Home > Common Problem > How to reset mysql password if I forget it

How to reset mysql password if I forget it

zbt
Release: 2023-07-19 10:31:19
Original
15477 people have browsed it

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.

How to reset mysql password if I forget it

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
Copy after login

(replace X.X with your MySQL version number)

3. Stop the MySQL service. Use the following command to stop the MySQL service:

netstopMySQL
Copy after login

4. Run MySQL to skip authorization verification. Run MySQL using the following command:

mysqld--skip-grant-tables
Copy after login

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
Copy after login
Copy after login

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';
Copy after login
Copy after login

Replace "new_password" with the new password you want to set.

8. Refresh permissions. Use the following command to refresh permissions:

FLUSHPRIVILEGES;
Copy after login
Copy after login

9. Exit MySQL. Enter the following command to exit MySQL:

quit;
Copy after login

10. Start the MySQL service. Use the following command to start the MySQL service:

netstartMySQL
Copy after login

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
Copy after login

3. Start MySQL to skip authorization authentication. Start MySQL using the following command:

mysqld_safe--skip-grant-tables&
Copy after login

4. Connect to the MySQL database. Use the following command to connect to the MySQL database:

mysql-uroot
Copy after login
Copy after login

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';
Copy after login
Copy after login

Replace "new_password" with the new password you want to set.

6. Refresh permissions. Refresh permissions using the following command:

FLUSHPRIVILEGES;
Copy after login
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template