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

访问Tomcat内的项目时出现:“404访问tomcat下的项目源服务器未能找到目标资源的表示或者是不愿公开一个已经存在的资源表示”。

解决办法:

  1. 查看tomcat的logs目录下的localhost.time.log日志文件
  2. 找到有缩进的at开头的row的前面一句错误信息
  3. 报错为“java.sql.SQLException: null,  message from server: "Host '192.xxx.xxx.xxx' is not allowed to connect to this MySQL server"”
  4. 原因是:远程服务器不允许你的java程序访问它的数据库。所以,我们要对远程服务器进行设置,使它允许你进行连接。
  5. 在mysql的bin目录下打开命令行,登录数据库mysql -u root -p
  6. 输入user mysql;
  7. 再输入select host,user from user;
  8. 再输入update user set host ='%' where user ='root';
  9. 最后重新启动MySQL服务

猜你喜欢

转载自www.cnblogs.com/mlh2019616/p/12335700.html