1. 程式人生 > >客戶端連接mysql出錯

客戶端連接mysql出錯

連接mysql出錯

3人閱讀

如果你想連接你的mysql的時候發生這個錯誤:

ERROR 1130: Host '192.168.16.145' is not allowed to connect to this MySQL server

  1. 改表法。

可能是你的帳號不允許從遠程登陸,只能在localhost。這個時候只要在localhost的那臺電腦,登入mysql後,更改 "mysql" 數據庫裏的 "user" 表裏的 "host" 項,從"localhost"改稱"%"

mysql -u root -pvmwaremysql>use mysql;mysql>update user set host = '%' where user = 'root';mysql>select host, user from user;


2. 授權法。


(1)例如:你想myuser使用mypassword從任何主機連接到mysql服務器的話

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

(2)如果你想允許用戶myuser從ip為192.168.16.145的主機連接到mysql服務器,並使用mypassword作為密碼

GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.16.145' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

(3)最後這句一定一定要加上!!!

mysql>flush privileges;


出現如下錯誤:

Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. java.net.ConnectException: Connection refused: connect

這時候,你需要登錄到服務器裏面按照如下方法設置你的mysql並重啟mysql

vim /etc/mysql/my.cnf

將配置裏面的bind-address = 127.0.0.1
這一項改成bind-address = 0.0.0.0
取消MySQL Server 綁定本地地址!
之後保存退出(wq)

sudo /etc/init.d/mysql restart (重啟mysql服務)
或者sudo service mysql restart


客戶端連接mysql出錯