解决java.sql.SQLException: null, message from server: "Host 'XXX' is not allowed to connect异常

我是迁移项目后,项目访问数据库时报的这个异常。这个异常是数据库只允许localhost或127.0.0.1访问,不允许远程访问。我用的本机IP都不行。

解决办法:修改访问权限即可。

打开cmd,进入mysql

解决java.sql.SQLException: null, message from server: "Host 'XXX' is not allowed to connect异常

flush privileges是为了将权限更新操作刷新到内存中,而不用下次启动时生效。

当然也可以直接选择重启mysql的方式:

解决java.sql.SQLException: null, message from server: "Host 'XXX' is not allowed to connect异常

解决java.sql.SQLException: null, message from server: "Host 'XXX' is not allowed to connect异常

参考:https://blog.csdn.net/xionglangs/article/details/50385057