1. Root user login to MySQL database
code example:
/usr/local/mysql/bin/mysql-u root-p (enter the password into MySQL)
2. Go to MySQL and enter:
code example:
Use MySQL;
3. View the user table
code example:
SELECT Host,user from User;
Indicates the host name, and "%" indicates that all strings are matched
4.
code example:
UPDATE user SET Host = '% ' WHERE user= ' root ' LIMIT 1;
5. Enter the following command to make the command you just set in effect
code example:
mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)
Note that you must enter ";" in the form of the MySQL command line.
After completing the previous five steps, enter from the console:
code example:
[Email protected] ~]# mysql-h localhost-u root-p
Enter Password:
ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:yes)
Don't let this connect to the database
Cause: Because the user field of the host is empty, we need to change it to root
code example:
Mysql> select Host,user from user;
+-----------+------+
| Host | user |
+-----------+------+
| % | Root |
| 127.0.0.1 | Root |
| Linux | |
| Linux | Root |
| localhost | |
+-----------+------+
5 rows in Set (0.00 sec)
Solution One:
code example:
mysql> Update user set user= ' root ' where host= ' localhost ';
Query OK, 1 row Affected (0.00 sec)
Rows matched:1 changed:1 warnings:0
mysql> flush Privileges;
Modify MySQL account password under Linux