Inventory of 4 ways to modify the root password of MYSQL

 

 

 

 

This article takes windows as an example to introduce in detail the 4 methods of modifying the root password of MySQL. You can choose freely according to your own situation. I hope it will be helpful to you.

Method 1: Use the SET PASSWORD command
to log in to MySQL first.
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
First log in to 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
use windows For example:
1. Shut down 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 permission table authentication when starting the MySQL service.
4.
5. Enter mysql and press Enter. If successful, the MySQL prompt > will appear.
6. Connect to the authority database: use mysql; .
6. Change the password: update user set password=password("123") where user="root"; (don't forget to add a semicolon at the end).
7. Refresh privileges (required step): flush privileges; .
8. Quit quit.
9. Log out of the system, log in again, and log in with the user name root and the new password 123 you just set.

Source: Weidian Reading    https://www.weidianyuedu.com

Guess you like

Origin blog.csdn.net/weixin_45707610/article/details/131865773