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-penter password: ***** welcome to the MySQL monitor. commands end with; or \ G. your MySQL connection ID is 4 to server version: 4.0.20a-debugtype 'help; 'or' \ H' for help. type '\ C' to clear the buffer. mysql> use MySQL; (this dB stores various MySQL configurations) database changedmysql> select host, user from user; (view User Permissions) mysql> select host, user, password from user; + ----------- + ------ + Principal + | host | user | password | + ----------- + ------ + Principal + | localhost | root | * Principal | 127.0.0.1 | root | * Principal | + ----------- + ------ + ------------------------------------------- +
From this we can see that it can only be accessed as a localhost.
Solution:
Mysql> grant all privileges on *. * To 'root' @ '%' identified by 'pwd' with grant option; (% indicates all external machines. If you specify a certain machine, change "%" to the corresponding machine name; "root" to 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 || % | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |+-----------+------+-------------------------------------------+
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 whether the listening mode is set to only listen to localhost. 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 ..