Recently, due to the development in windows and deployment in linux, the project suffered a lot of cross-platform losses, for example, we found that the names of mysql tables in linux are case-sensitive. This is another pitfall, when tomcat connects to mysql, the error Accessdeniedforuserxxx@localhost.localdomain (using
Recently, due to the development in windows and deployment in linux, the project suffered a lot of cross-platform losses, for example, we found that the names of mysql tables in linux are case-sensitive. This is another pitfall. When tomcat connects to mysql, the error "Access denied for user 'xxx' @ 'localhost. localdomain '(using
Recently, due to the development in windows and deployment in linux, the project suffered a lot of cross-platform losses, for example, we found that mysql table names in linux are case sensitive. This is another pitfall. When tomcat connects to mysql, the error "Access denied for user 'xxx' @ 'localhost. localdomain '(using password: YES)" is reported )).
I have encountered a similar problem before, but in windows, the error message is a little different, that is, Access denied for user 'xxx' @ 'localhost' (using password: YES )), the result is that the cache is not clear. the user name and password used to connect to the database are inconsistent with those in the configuration file, for this reason, you only need to print the user name and password used to connect to the database once. However, this is not due to this reason. the user name and password are correct.
Troubleshooting process:
Log on to mysql with the root user, run the following statement to query all mysql users, and observe the results. This helps you understand the subsequent content:
SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
You will see that even the same user name has a different @ host suffix. Here, it refers to the login of the same user on different hosts, and @ host refers to the host.
The error message "Access denied for user 'xxx' @ 'localhost" is returned. localdomain '(using password: YES) instead of Access denied for user 'xxx' @ 'localhost' (using password: YES), there is still a lot of difference between localdomain. This involves the difference between localhost and 127.0.0.1 (localhost. localdomain.
When we log on to mysql data directly in the command line in the form of "mysql-u username-p password", we do not use TCP/IP connection. mysql will think that the connection is from localhost, therefore, the actual logon is xxx @ localhost. However, in linux, when tomcat is used to connect to the database (I won't do this in windows, but I don't know why), the host is determined to be from 127.0.0.1, so the actual login is the xxx@localhost.localdomain, then you use xxx @ localhost password to verify the xxx@localhost.localdomain of course can only be determined as a denial of connection.
Solution:
1. Create a new user and authorize it to access the specified database. Here, I specified the host as localhost. localdomain indicates that users with the username snow are allowed to use the password 123 on localhost. connect to the database on the localdomain host. Pay attention to the specified host localhost. localdomain is critical.
GRANT USAGE ON *.* TO 'snow'@'localhost.localdomain' IDENTIFIED BY '123' WITH GRANT OPTION;
2. The New User grants all permissions to Operate Database exampleDB.
grant all privileges on exampleDB.* to snow@localhost.localdomain identified by '123';
3. Update the permission table
flush privileges;
Then, change the username used for connection in the code to snow and the password to 123 ., Solve the problem and connect to mysql successfully.
Of course, you can also replace the username and password in the Code with your username and password.