标签:连接mysql出错
3人阅读如果你想连接你的mysql的时候发生这个错误:
ERROR 1130: Host '192.168.16.145' is not allowed to connect to this MySQL server
改表法。
可能是你的帐号不允许从远程登陆,只能在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出错
原文地址:http://blog.51cto.com/12348890/2092472