Home  >  Article  >  Database  >  How to Reset MySQL Root Password Without the Old Password?

How to Reset MySQL Root Password Without the Old Password?

DDD
DDDOriginal
2024-11-06 16:37:02916browse

How to Reset MySQL Root Password Without the Old Password?

Resetting MySQL Root Password Without Old Password

If you find yourself unable to recall your MySQL root password, regaining access is possible through a series of steps.

To begin, stop the MySQL service using the command:

sudo service mysql stop

Next, start MySQL in safe mode with the following command:

sudo mysqld_safe --skip-grant-tables --skip-syslog --skip-networking

In a new terminal, connect to MySQL as root:

mysql -u root

Execute the following queries to change the root password:

UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';
FLUSH PRIVILEGES;

Note: In MySQL 5.7, the password field was replaced by the authentication_string field.

Finally, quit MySQL safe mode and restart the MySQL service:

mysqladmin shutdown
sudo service mysql start

With these steps, you should have reset your MySQL root password successfully.

The above is the detailed content of How to Reset MySQL Root Password Without the Old Password?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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