问题:

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

原因:

Mysql Server不允许该Java项目的服务器进行远程连接。这里需要修一下改权限即可,以下两种方式均可,亲测。


法1:

GRANT ALL PRIVILEGES ON ChoiceManagerSys.* TO 'root'@'192.168.x.x' IDENTIFIED BY '0';
GRANT ALL PRIVILEGES ON ChoiceManagerSys.* TO 'root'@'%' IDENTIFIED BY '0';
flush privileges;执行刷新权限
ChoiceManagerSys为DB名,ChoiceManagerSys.*表示授权该DB下的所有表。如果要授权所有DB的所有表,则改成“*.*”;

'root'@'192.168.x.x' 表示允许root用户在192.168.x.x对Mysql进行远程登陆。如果要允许任何主机访问,则改成'root'@'%';
'0'为用户密码
可能会报Can't find any matching row in the user table,执行flush privileges即可;
发生这一错误的原因是在变更了mysql.user表之后,没有使用FLUSH PRIVILEGES命令来更新权限表(grant tables)'
http://dev.son1c.com/show/2609.html

法2:

mysql -u root -p
use mysql;
select Host,User from user;
发现root用户只允许本机访问
修改user表允许任何主机访问:
update user set Host='%' where User='root';
flush privileges;
在执行update user set Host='%' where User='root';时可能会报
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
意思是User='root'的数据有多条,执行flush privileges即可;




参考网址:

http://www.jb51.net/article/31902.htm