Set the root permission for mysql remote connection bitsCN.com
You may have encountered this problem when remotely connecting to mysql. the root user cannot connect to mysql remotely, but can only connect locally and reject the connection.
You must create a database account that allows remote logon to perform database operations.
The method is as follows:
By default, the user permissions in the MYSQL system table user of the mysql database only provide localhost local login;
You must change the permissions to remotely connect to the MYSQL database.
You can confirm the problem by using the following methods:
Root # mysql-h localhost-uroot-p
Enter password :******
Welcome to the MySQL monitor. Commands end with; or/g.
Your MySQL connection id is 4 to server version: 4.0.20a-debug
Type 'help; 'or'/h' for help. type'/C' to clear the buffer.
Mysql> use mysql; (this DB stores various MySQL configuration information)
Database changed
Mysql> select host, user from user; (view user permissions)
Mysql> select host, user, password from user;
+ ----------- + ------ + --------------------------------------------- +
| Host | user | password |
+ ----------- + ------ + --------------------------------------------- +
| Localhost | root | * 4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| 127.0.0.1 | root | * 4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| Localhost |
+ ----------- + ------ + --------------------------------------------- +
4 rows in set (0.01 sec)
From this we can see that it can only be accessed as a localhost.
Solution:
Mysql> Grant all privileges on *. * to 'root' @ '%' identified by 'dm001' with grant option;
(% Indicates all external Machines. if a specific machine is specified, Change % to the corresponding machine name; 'root' indicates the user name to be used ,)
Mysql> flush privileges; (run this statement to take effect, or restart MySQL)
Query OK, 0 rows affected (0.03 sec)
View again ..
Mysql> select host, user, password from user;
+ ----------- + ------ + --------------------------------------------- +
| Host | user | password |
+ ----------- + ------ + --------------------------------------------- +
| Localhost | root | * 4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| 127.0.0.1 | root | * 4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| Localhost |
| % | Root | * 4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
+ ----------- + ------ + --------------------------------------------- +
4 rows in set (0.01 sec)
We can see that a new user has been added.
Check whether the mysqld listening mode is set to only listen to localhost,
Use netstat to check if yes. Find the mysql configuration file my. cnf and change the bind address to the real IP address of the machine.
You can also comment out bind address directly. Restart is required to take effect.
Exit and try the effect ....
Now you can successfully log on ..
This article is from the "jie blog"
BitsCN.com