天天看点

Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)

以前一直是用本地的 MySQL 进行学习、开发,后来买了服务器,服务器上也搭好了环境,就准备开始用服务器上的 MySQL 进行学习和开发,也遇到了一些坑,在此记录一下。

现在我本地是可以正常远程连接服务器 MySQL 的,下面两个图用红色涂鸦的是我服务器的公网IP。

Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)
Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)

如果你不是这样子的,请继续往下看。要想服务器的 MySQL 可以被本地远程连接,先要进入服务器 MySQL 中执行下面几条语句。

进入 MySQL 输入 ​

​use mysql;​

​​ 、​

​update user set host='%' where user='username';​

​(% 也可以是固定的 IP,默认是 localhost,即只允许本地连接)。

我的 ​

​username​

​​ 是 ​

​root2​

​​,大家填自己的 ​

​username​

​。

Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)

再对这个用户进行授权(不知道是不是必须的,为了保险起见,​

​password​

​ 是用户的密码)

GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;      

再看一下对用户授权是否成功。

show grants for 'username'@'%'      
Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)

如果还不能进行远程连接,看服务器防火墙的 3306 端口设置好了没。

Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)

即使可以正常远程连接服务器 MySQL,运行程序还是会报错。

报错信息如下图:

Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)

解决方法是: 数据库用户密码用​

​""​

​​括起来。如​

​"012345"​

​。

这个解决方法是在一个论坛中看到的(找了两天的资料发现的神奇操作,估计是因为数据库密码有前缀0的原因吧,我的数据库密码就有前缀0)。

这样后,我的项目就可以正常运行了,如下图。

Unable to create initial connections of pool.Access denied for user ' '@' '(using password: YES)