JDBC Hibernate - Mysql Connection Error

不想你离开。 提交于 2019-12-04 16:19:49

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';

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

  1. Define a domain scoped credential for 'root', at '127.0.0.1'.
  2. Define a wildcard domain scoped credential for 'root', so you can login to your MySQL with those credentials from multiple locations.

Here's an example of the second:

mysql -uroot -proot

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

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.

You might have to GRANT permissions to access the database.

Look at the MySQL docs for something that looks like this:

create database pmt;
create user pmt identified by 'pmt';
grant all on pmt.* to 'pmt'@'%';

"pmt" is just an example above. I happened to make the name of the database, username, and password all the same. I don't recommend that as a best practice. It's just something I did for some local development.

I personally don't like GRANTing root access to any application. I would not use root username and password in even a toy application. It doesn't take much effort to create a new user and GRANT appropriate permissions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!