感谢分享:http://blog.csdn.net/zwx19921215/article/details/41867963
今天在linux上远程访问windows下的mysql时出现如下异常:
ERROR manager.SqlManager: Error executing statement: java.sql.SQLException: null, message from server: "Host '172.103.54.12' is not allowed to connect to this MySQL server" java.sql.SQLException: null, message from server: "Host '172.103.54.12' is not allowed to connect to this MySQL server
解决方法:
mysql -u root -p
mysql>use mysql;
mysql>select 'host' from user where user='root';
mysql>update user set host = '%' where user ='root';
(注:如果在执行update user set host = '%' where user ='root';出现错误提示
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 则只需执行 flush privileges 即可)
mysql>flush privileges;
mysql>select 'host' from user where user='root';
第一句是以权限用户root登录
第二句:选择mysql库
第三句:查看mysql库中的user表的host值(即可进行连接访问的主机/IP名称)
第四句:修改host值(以通配符%的内容增加主机/IP地址),当然也可以直接增加IP地址
第五句:刷新MySQL的系统权限相关表
第六句:再重新查看user表时,有修改。。
重起mysql服务即可完成。