Mysql root user does not allow remote connections
异常:java.sql.SQLException: Access denied for user 'root'@'RJB-Z' (using passwrod)。
String url ="jdbc:mysql://192.168.1.169:3306/test“;
The password is correct, and you can log in from the command line window. I checked the Internet and found that it is because the root user does not allow remote connections.
I found a solution on this website (http://xucons.javaeye.com/blog/278581): change the table or empower. http://xucons.javaeye.com/blog/278581
If this error occurs when you connect to mysql:
Sql code
ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL server
[sql] view plaincopy
Here is the quote:
ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL server
Solution:
1. Change the table method.
It may be that your account is not allowed to log in from the remote, only on localhost. At this time, as long as you are on the localhost computer, after logging in to mysql, change the "host" item in the "user" table in the "mysql" database, from "localhost" to "%"
Java code
mysql -u root -p
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
[java] view plaincopy
mysql -u root -p
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
[java] view plaincopy
[java] view plaincopy
2. Authorization Act.
For example, if you want myuser to connect to the mysql server from any host using mypassword.
Sql code
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
[sql] view plaincopy
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
If you want to allow user myuser to connect to mysql server from host with ip 192.168.1.3 and use mypassword as password
Sql code
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
I use the second method.