HOST is not allowed to connect to this mysql server
HOST is not allowed to connect to this mysql server
host主机不能访问本机的mysql服务,原因需要连接非本机的mysql的时候,默认host是localhost,我们需要将这个mysql连接权限设置成%,更改方法直接通过软件更改和命令行更改:
在mysql的数据库选择mysql这个数据库,里面有一个user表,进入表中有一个host字段将localhost值更改为%这个保存后,刷新或者重启MySQL服务都行。
登录服务器mysql查看
mysql> use mysql; Database changed mysql> mysql> select host,user from user; +-----------+------------------+ | host | user | +-----------+------------------+ | localhost | mysql.infoschema | | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +-----------+------------------+ 4 rows in set (0.00 sec) mysql>
授权访问,因为是本地连接,所以,给予了所有权限
mysql> grant all privileges on *.* to 'root'@'%' with grant option; ERROR 1410 (42000): You are not allowed to create a user with GRANT
报错,产生用户不能授权的原因是mysql 数据库中user 表中的特定用户(root) 的host 的属性值为localhost.
mysql> mysql> update user set host='%' where user='root'; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> mysql> mysql> grant all privileges on *.* to 'root'@'%'; Query OK, 0 rows affected (0.01 sec) mysql> mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql>
然后测试连接又报错了,提示说:“客户端不支持服务器请求的身份验证协议”
更改加密方式
mysql> alter user 'root'@'%' identified by '111111' password expire never;
Query OK, 0 rows affected (0.01 sec)
mysql>
更改密码
mysql> alter user 'root'@'%' identified with mysql_native_password by '111111'; Query OK, 0 rows affected (0.00 sec) mysql>
刷新权限
mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql>
连接成功