Mysql> Update mysql. User SET Password = PASSWORD ('new password') where user = 'root ';
Mysql> flush privileges;
Mysql> quit
A:
MySQL needs flush privileges to refresh the MySQL system permission table after setting a user or changing the password. Otherwise, access is denied. Another method is to restart the MySQL server, to make the new settings take effect.
Example:
1. After the root user enters MySQL and opens the MySQL database (use MySQL ),
Create user XH identified by 'xh'; // create a user XH and add the password as XH
Exit; // exit the test.
2. Return to the C directory and use a new user to access MySQL again.
Mysql-uxh-pxh // success
3. Use the root user again to access MySQL and open the MySQL database.
Update user SET Password = PASSWORD ('monkey') where user = 'xh'; // change the xh user password to monkey
Exit; // exit the test again
4. Log in directly as the XH user and use the new password to check whether the access is successful.
Mysql-uxh-pmonkey; // The password is incorrect.
5. log on to the MySQL database again as the root user and change the user password.
Update user SET Password = PASSWORD ('monkey') where user = 'xh'; // change the xh user password to monkey
Flush privileges; // refresh the MySQL system permission table.
Exit;
6. Exit again and enter the XH user monkey password. The test is successful!