今天在用pycharm使用pymysql模块连接Mysql服务器的数据库,发现连接不到,错误代码是1130,pymysql.err.InternalError: (1130,'xxxxx' is not allowed to connect to this MariaDB server")
之后发现是权限问题。如下操作mysql库,即可解决。登录mysql后,更改 “mysql” 数据库里的 “user” 表里的 “host” 项,从”localhost”改称'%'。。
mysql -u root -p
mysql>use mysql; #选择mysql库
mysql>update user set host = '%' where user ='root' and host='localhost'; #修改host值(以通配符%的内容增加主机/IP地址)
mysql>flush privileges; #刷新MySQL的系统权限相关表
退出mysql后再次登录需要使用mysql -h xxx.xxx.xxx.xxx -uroot -p才能登录 (xxx.xxx.xxx.xxx为远程mysql服务器的ip地址)