一:登錄報錯
ERROR 1045 (28000): Access denied for user 'mysql'@'localhost' (using password: NO) mysql日志文件總結此問題的整體步驟如下: 第一步:修改pid路徑 查看日志文件中錯誤信息: cat /var/log/mysqld.log 2013-10-26 16:39:34 3712 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory) 2013-10-26 16:39:34 3712 [ERROR] Can't start server: can't create PID file: No such file or directory 原因: mysql 用戶沒有操作/var/run目錄的權限,所以pid文件無法創建,導致登陸時無法建立 進程信息文件,登陸進程就無法開啟,自然無法登陸。 解決: 修改 /etc/my.conf 原來為: #pid-file=/var/run/mysqld/mysqld.pid 修改為 pid-file=/var/lib/mysql/mysqlid.pid 檢查發現,mysql用戶根本無法cd到/var/run/。修改為mysql可以有權限的目錄後再執行mysql就進入數據庫了。 第二步:修改數據庫默認密碼 /etc/init.d/mysql stop (service mysqld stop) /usr/bin/mysqld_safe --skip-grant-tables 另外開個SSH連接 [root@localhost ~]# mysql mysql>use mysql mysql>update user set password=password("123456") where user="root"; mysql>flush privileges; mysql>exit 然後 [mysql@localhost etc]$ ps -A | grep mysql 4532 pts/0 00:00:00 mysqld_safe 5542 pts/0 00:00:00 mysqld [mysql@localhost etc]$ kill -9 4532 5542 正常啟動 MySQL:/etc/init.d/mysql start (service mysqld start) 第三步: 登陸ok。 mysql -uroot -p 二:遠程登錄mysql數據庫報錯 ERROR 1130 (HY000): Host '192.168.76.50' is not allowed to connect to this MySQL server 1.改表法。 可能是你的帳號不允許從遠程登陸,只能在localhost。這個時候只要在localhost的那台電腦,登入mysql後,更改 "mysql" 數據庫裡的 "user" 表裡的 "host" 項,從"localhost"改稱"%" mysql -u root -pTalent123 mysql>use mysql; mysql>update user set host = '%' where user = 'root'; mysql>select host, user from user; mysql> flush privileges; 2.授權法。 例如,你想myuser使用mypassword從任何主機連接到mysql服務器的話。 GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; 如果你想允許用戶myuser從ip為192.168.1.3的主機連接到mysql服務器,並使用mypassword作為密碼 GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; 三:創建普通用戶後無法在本地登錄 [root@jcfx-4 ~]#mysql -h192.168.76.73 -usalt -psalt ERROR 1045 (28000): Access denied for user 'salt'@'jcfx-4' (using password: YES) 通過查看user表發現localhost對應的是空密碼,所以這是導致不能再本地登錄的根本原因: mysql> select host,user,password from mysql.user; 解決方法: mysql> grant select,insert,update,delete on salt.* to salt@"localhost" identified by "salt"; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) 四:mysql登錄報錯: [root@patronus2 bin]# mysql -bash: mysql: command not found 解決方法: ln -s /usr/local/mysql/bin/mysql /usr/bin 五:設置字符集 Server version: 5.6.21 MySQL character_set_server=utf8 注:遇到異常情況,通過上面列舉的辦法應該是可以解決;