Method 1: Use the Set password command
First log in to MySQL.
Format:mysql> set password for user name @localhost = password (' new password ');
Example:mysql> set password for [email protected] = password (' 123 ');
Method 2: Use Mysqladmin
Format: Mysqladmin-u username-P Old password password new password
Example: mysqladmin-uroot-p123456 password 123
Method 3: Edit the user table directly with update
First log in to MySQL.
mysql> use MySQL;
mysql> Update user set Password=password (' 123 ') where user= ' root ' and host= ' localhost ';
mysql> flush Privileges;
(Very strange phenomenon, flush privileges do not execute, quit MySQL, the old password can still be logged in, after the update after the login, the new password to take effect. )
Method 4: When you forget the root password, you can do this
take windows as an example:
1. Close the running MySQL service.
2. Open the DOS window and go to the Mysql\bin directory.
3. Enter Mysqld--skip-grant-tables carriage return. --skip-grant-tables means skipping permission table authentication when starting the MySQL service.
4. Open a DOS window again (because the DOS window is no longer moving), go to the Mysql\bin directory.
5. Enter MySQL return and, if successful, the MySQL prompt > will appear.
6. Connection rights database: use MySQL;.
6. Change Password: Update user set Password=password ("123") where user= "root"; (don't forget the last semicolon).
7. Refresh permissions (required steps): flush privileges;.
8. Quit quit.
9. Log out of the system and then enter, using the username root and the new password you just set 123 to log in.
4 ways to change the root password in Windows mysql--