本地django远程链接服务器的mysql,报(1130, "Host '*.*.*.*' is not allowed to connect to this MySQL server")

一、问题描述

本地django远程链接服务器的mysql,报(1130, "Host '*.*.*.*' is not allowed to connect to this MySQL server")
使用授权语句显示语法错误。

二、解决方案

1.在安装Mysql数据库的主机上登录root用户:

mysql -u root -p

2.依次执行如下命令:

use mysql;
select host from user where user='root';

可以看到当前主机配置信息为localhost。
本地django远程链接服务器的mysql,报(1130, "Host '*.*.*.*' is not allowed to connect to this MySQL server")

3.执行
update user set host = '%' where user ='root';
将Host设置为通配符%。

本地django远程链接服务器的mysql,报(1130, "Host '*.*.*.*' is not allowed to connect to this MySQL server")

4.权限刷新。

flush privileges;

本地django远程链接服务器的mysql,报(1130, "Host '*.*.*.*' is not allowed to connect to this MySQL server")

大功告成,重新执行python manage.py runserver
本地django远程链接服务器的mysql,报(1130, "Host '*.*.*.*' is not allowed to connect to this MySQL server")