当前位置: 移动技术网 > IT编程>数据库>Mysql > 完美解决mysql客户端授权后连接失败的问题

完美解决mysql客户端授权后连接失败的问题

2017年12月12日  | 移动技术网IT编程  | 我要评论

世界城市gdp排名,李尚花,2014136

在本地(192.168.1.152)部署好mysql环境,授权远程客户机192.168.1.%连接本机的mysql,在iptables防火墙也已开通3306端口。

如下:

mysql> select host,user,password from mysql.user;
+--------------+-----------------+---------------------------------------------------------+
| host | user | password |
+--------------+-----------------+----------------------------------------------------------+
| localhost | root | |
| fdm1 | root | |
| 127.0.0.1 | root | |
| localhost | | |
| fdm1 | | |
| 192.168.1.% | db_hqsb | *dfc9dc16b13651a95ecec3a26e07d244431b55c9 |
| 192.168.1.% | db_ro_hqsb | *2c0b0dd50595bb40879110437beef026d019dfb7 |
| 192.168.1.% | db_jkhwuser | *2c0b0dd50595bb40879110437beef026d019dfb7 |
| 192.168.1.25| slave | *ee52b8eacb3ccd13624273ad6b5cda52b9b53eb7 |
| 192.168.1.% | tech_db_user | *6053e57c7b61043dc2c6b4e3291d5f61ccc23f5c |
| 192.168.1.% | game_db_user| *05ea4d71c9a1273ecf3e24e6323f7175ae45c366 |
| localhost | zabbix | *6bb4837eb74329105ee4568dda7dc67ed2ca2ad9 |
+---------------+---------------+------------------------------------------------------------+

问题:

在客户机(比如192.168.1.20)上远程连接上面192.168.1.152机器的mysql,连接失败!

[root@huanqiu ~]# mysql -udb_ro_hqsb -h 192.168.1.152 -pmhxzkhl0802xqsjdb
error 1130 (hy000): host '192.168.1.20' is not allowed to connect to this mysql server

解决:

是由于192.168.1.152的mysql里“host为localhost,user和password为空”这条语句导致的,删除这条即可解决问题!

mysql> delete from mysql.user where host="localhost" and user="";
query ok, 1 row affected (0.00 sec)
mysql> flush privileges;
query ok, 0 rows affected (0.00 sec)

这样,授权连接的客户机就能成功连接了!

[root@huanqiu ~]# mysql -uxqsj_db_ro_user -h 192.168.1.152 -pmhxzkhl0802xqsjdb
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 28
server version: 5.1.73 source distribution

copyright (c) 2000, 2013, oracle and/or its affiliates. all rights reserved.

oracle is a registered trademark of oracle corporation and/or its
affiliates. other names may be trademarks of their respective
owners.

type 'help;' or '\h' for help. type '\c' to clear the current input statement.

mysql>

以上这篇完美解决mysql客户端授权后连接失败的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网