java.sql.SQLException: null,  message from server: "Host '%' is not allowed to connect to

在阿里云 SUSE linux配置完mysql后,服务器端本身是可以访问数据库的如图:

java.sql.SQLException: null,  message from server: "Host '%' is not allowed to connect to
但是在客户端不可以,服务启动时报错:

java.sql.SQLException: null,  message from server: "Host '223.72.41.7' is not allowed to connect to this MySQL server"

 

客户端访问时报错:

java.sql.SQLException: null,  message from server: "Host '%' is not allowed to connect to

 

解决方法:

1,登陆服务器

java.sql.SQLException: null,  message from server: "Host '%' is not allowed to connect to

mysql> use mysql; //用mysql database

2,查询user表如下:

java.sql.SQLException: null,  message from server: "Host '%' is not allowed to connect to

3,mysql> update user set host='%' where user root; //%代表修改为任何ip地址都可以访问。若限制你本机访问,把你本机ip地址放进去

4,mysql> flush privileges;//使权限生效

再尝试就可以访问了。