Share four methods to change mysql password

Four ways to quickly change mysql password

Method 1: Use the SET PASSWORD command 

First log in to MySQL. 
Format: mysql> set password for username@localhost = password('new password'); 
Example: mysql> set password for root@localhost = password('123'); 

Method 2: use mysqladmin 

Format: mysqladmin -u username -p old password password New password 
example: mysqladmin -uroot -p123456 password 123 

Method 3: Use UPDATE to directly edit the user table 

首先登录MySQL。 
mysql> use mysql; 
mysql> update user set password=password('123') where user='root' and host='localhost'; 
mysql> flush privileges; 

Method 4: When you forget the root password, you can do this 

Taking windows as an example: 
1. Close the running MySQL service. 
2. Open a DOS window and go to the mysql\bin directory. 
3. Enter mysqld --skip-grant-tables and press Enter. --skip-grant-tables means to skip the authorization table authentication when starting the MySQL service. 
4. Open another DOS window (because the DOS window just now cannot be moved) and go to the mysql\bin directory. 
5. Enter mysql and press Enter. If successful, the MySQL prompt > will appear. 
6. Connect to the permission database: use mysql;. 
6. Change password: update user set password=password("123") where user="root"; (don't forget to add the semicolon at the end) 
7. Refresh permissions (required step): flush privileges; 
8. Exit quit. 
9. Log out of the system, re-enter, and log in using the username root and the new password 123 you just set.

Reprinted from: Weidian Reading    https://www.weidianyuedu.com

Guess you like

Origin blog.csdn.net/weixin_45707610/article/details/131206474#comments_28398273