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
来源: http://www.bubuko.com/infodetail-2542860.html