且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法创建PoolableConnectionFactory(对用户``@'localhost'的访问被拒绝

更新时间:2023-12-01 21:23:40

您的设置看起来不错.看来这纯粹是一个权限问题.

Your setup looks fine. This looks to purly be a permissions problem.

您需要在mysql中授予该用户访问权限. Java将连接到localhost时,它将使用tcp/ip进行连接-但是在mysql localhost和127.0.0.1中具有不同的含义.发出此SQL应该可以解决问题.

You need to grant that user access in mysql. While Java will connect to localhost, it will do so using tcp/ip - however in mysql localhost and 127.0.0.1 have different meaning. Issuing this SQL should do the trick.

grant all on twitter.* to 'root'@'127.0.0.1' identified by 'mypwd';

假设Java将"localhost"解析为127.0.0.1,如果仍然无法解决问题,则可以尝试将连接字符串更改为"jdbc:mysql://127.0.0.1:3306/twitter"

That assumes Java resolves 'localhost' to 127.0.0.1, if things still doesn't work, you could try changing your connection string to "jdbc:mysql://127.0.0.1:3306/twitter"

我的context.xml中应该有这个吗? 还是普通密码?

Should I have this in my context.xml or just the normal password?

您现在拥有的是纯文本密码.

As you have it now, the plaintext password.