Mac system (Linux system) When you do not know the root password of MySql, reset the root password | How to deal with the forgotten MySQL root password

1. First open the terminal and enter the bin folder under the MySQL installation directory, such as: /usr/local/mysql/bin/

2. Execute the following command to log in to MySQL without a password:

./mysql -u root

3. After entering MySQL, select the mysql database:


use mysql;

4. Enter the following command to change the password of the root user:


UPDATE user SET authentication_string=PASSWORD('new_password') WHERE User='root';

Among them, new_password is the new password you want to set, which can be modified according to your needs.

5. After changing the password, you need to refresh the MySQL permissions:

flush privileges;

6. Finally, log back into MySQL with the new password:

quit;
./mysql -u root -p

Among them, the -p parameter indicates that a password is required.

7. If there is an error in step 4, you can try the following command:


ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql';

Among them, mysql is the new password you want to set, which can be modified according to your needs.

8. After changing the password, you also need to refresh the MySQL permissions:


flush privileges;

9. Finally, log back into MySQL with the new password:

quit;
./mysql -u root -p

Guess you like

Origin blog.csdn.net/yueyeguzhuo/article/details/129341245