码迷,mamicode.com
首页 > 数据库 > 详细

客户端连接mysql出错

时间:2018-03-29 15:57:59      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:连接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出错

标签:连接mysql出错

原文地址:http://blog.51cto.com/12348890/2092472

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!