且构网

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

JDBC Hibernate - Mysql连接错误

更新时间:2023-11-22 11:32:04

您的框架很可能以 127.0.0.1 。如果您尚未定义适当的域范围凭据,那么将在MySQL中创建登录问题。试试这个来验证:

More than likely your framework is logging into your local database as 127.0.0.1. Which will create a login problem in MySQL if you have not defined an appropriate domain scoped credential. Try this to verify:

mysql -uroot -proot
SELECT * from mysql.user WHERE user = 'root';

如果没有'root'@'127.0.0.1'那么找到问题并补救它,执行以下两项操作之一:

If there is no 'root'@'127.0.0.1' then have found the problem and to remedy it, do one of two things:


  1. 为'root'定义域范围的凭证,位于'127.0.0.1'。

  2. 为'root'定义通配符域范围的凭据,因此您可以使用来自多个位置的凭据登录到您的MySQL。

以下是第二个例子:

mysql -uroot -proot

CREATE USER 'root'@'%' IDENTIFIED BY 'root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

在旁注中,我肯定会建议您使用更具创意的用户ID和密码。特别是如果你的服务器启用了TCP套接字。

On a side note, I would definitely recommend using something more creative for your user id and password. Especially if you have TCP sockets enabled for your server.