相关推荐recommended
Mysql 报 java.sql.SQLException:null,message from server:“Host ‘‘ is not allowed to connect.解决方案
作者:mmseoamin日期:2024-04-30

这个错误i是因为mysql数据库没有放开远程访问权限引起的,以mysql8为例

首先进入Mysql 安装目录,然后输入命令:mysql -uroot -p ;具体参见下图:

Mysql 报 java.sql.SQLException:null,message from server:“Host ‘‘ is not allowed to connect.解决方案,在这里插入图片描述,第1张

再输入use mysql; 回车执行,

Mysql 报 java.sql.SQLException:null,message from server:“Host ‘‘ is not allowed to connect.解决方案,在这里插入图片描述,第2张

接着输入,show tables; 回车执行

Mysql 报 java.sql.SQLException:null,message from server:“Host ‘‘ is not allowed to connect.解决方案,在这里插入图片描述,第3张

输入,select host from user; 回车执行,这里特别说明一下,我这个是已经放开了远程访问权限,正常报错的情况,host下应全部都为localhost,说明mysql只允许本机连接

Mysql 报 java.sql.SQLException:null,message from server:“Host ‘‘ is not allowed to connect.解决方案,在这里插入图片描述,第4张

输入,update user set host =‘%’ where user =‘root’; 回车执行

6,最后,再输入 flush privileges; 进行权限刷新,然后再回去重新启动就没有问题了