Forgot to reset mysql password: 1. Open the command prompt. Search for "CMD" in the start menu and click to open; 2. Enter the MySQL installation directory; 3. Stop the MySQL service; 4. Run MySQL to skip authorization authentication; 5. Open a new command prompt window and enter the MySQL installation directory. bin folder; 6. Connect to the MySQL database; 7. Update the root user password; 8. Refresh permissions; 9. Exit MySQL; 10. Start the MySQL service.
MySQL is an open source relational database management system that is widely used in Internet and enterprise-level applications. When using MySQL, we usually set a password to protect the security of the database. However, sometimes we may forget the MySQL password, which will bring us some trouble. This article will introduce how to reset MySQL password.
The method of resetting your MySQL password depends on your operating system and MySQL version. The following will introduce the reset methods on Windows and Linux operating systems respectively.
Reset MySQL password on Windows operating system:
1. First, open the command prompt. Search for "CMD" in the Start menu and click Open.
2. Enter the MySQL installation directory. By default, the MySQL installation directory is C:\Program Files\MySQL\MySQL Server X.X. Use the following command to enter the directory:
cdC:\ProgramFiles\MySQL\MySQLServerX.X\bin
(replace X.X with your MySQL version number)
3. Stop the MySQL service. Use the following command to stop the MySQL service:
netstopMySQL
4. Run MySQL to skip authorization verification. Run MySQL using the following command:
mysqld--skip-grant-tables
5. Open a new command prompt window and enter the bin folder of the MySQL installation directory.
6. Connect to MySQL database. Use the following command to connect to the MySQL database:
mysql-uroot
If there is no password, just press Enter.
7. Update the root user password. Enter the following command to update the root user password:
UPDATEmysql.userSETauthentication_string=PASSWORD('new_password')WHERE User='root';
Replace "new_password" with the new password you want to set.
8. Refresh permissions. Use the following command to refresh permissions:
FLUSHPRIVILEGES;
9. Exit MySQL. Enter the following command to exit MySQL:
quit;
10. Start the MySQL service. Use the following command to start the MySQL service:
netstartMySQL
Reset the MySQL password on the Linux operating system:
1. First, log in to the Linux system as the root user.
2. Stop the MySQL service. Use the following command to stop the MySQL service:
servicemysqlstop
3. Start MySQL to skip authorization authentication. Start MySQL using the following command:
mysqld_safe--skip-grant-tables&
4. Connect to the MySQL database. Use the following command to connect to the MySQL database:
mysql-uroot
If there is no password, just press Enter.
5. Update the root user password. Enter the following command to update the root user password:
UPDATEmysql.userSETauthentication_string=PASSWORD('new_password')WHERE User='root';
Replace "new_password" with the new password you want to set.
6. Refresh permissions. Refresh permissions using the following command:
FLUSHPRIVILEGES;
7. Exit MySQL. Enter the following command to exit MySQL:
quit;
8. Start the MySQL service. Start the MySQL service using the following command:
servicemysqlstart
These are the steps to reset the MySQL password on Windows and Linux operating systems. Please note that after resetting your password, be sure to remember the new password and keep it secret to protect the security of your database.
The above is the detailed content of How to reset mysql password if I forget it. For more information, please follow other related articles on the PHP Chinese website!