3人閱讀java
若是你想鏈接你的mysql的時候發生這個錯誤:mysql
ERROR 1130: Host '192.168.16.145' is not allowed to connect to this MySQL serversql
改表法。數據庫
多是你的賬號不容許從遠程登錄,只能在localhost。這個時候只要在localhost的那臺電腦,登入mysql後,更改 "mysql" 數據庫裏的 "user" 表裏的 "host" 項,從"localhost"改稱"%"vim
mysql -u root -pvmwaremysql>use mysql;mysql>update user set host = '%' where user = 'root';mysql>select host, user from user;
2. 受權法。bash
(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做爲密碼ide
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.16.145' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
(3)最後這句必定必定要加上!!!this
mysql>flush privileges;
出現以下錯誤:.net
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