Home  >  Article  >  Database  >  How to Reset a Forgotten MySQL Root Password?

How to Reset a Forgotten MySQL Root Password?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-02 14:17:02831browse

How to Reset a Forgotten MySQL Root Password?

How to Reset Forgotten MySQL Root Password

If you've forgotten your MySQL root password, you'll face login issues and error #1045 when attempting to connect via PHPMyAdmin. Here's how to reset your root password:

1. Locate MySQL Configuration File:

Use the following command to find the location of the MySQL configuration file:

mysql --help | grep -A 1 "Default options"

On Ubuntu 16, the file is usually located at /etc/mysql/mysql.conf.d/mysqld.cnf.

2. Edit Configuration File:

Edit the configuration file using the command:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Add skip-grant-tables under the [mysqld] block and save the changes.

3. Restart MySQL Service:

Restart the MySQL service using the following command:

sudo service mysql restart

4. Check MySQL Service Status:

Verify that the MySQL service is running properly:

sudo service mysql status

5. Login to MySQL with Root:

Log into MySQL without a password using the command:

mysql -u root

6. Change Root Password:

Reset the root password within the MySQL console:

mysql> FLUSH PRIVILEGES;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'MyNewPass';

7. Revert Configuration File Changes:

Remove or comment out the skip-grant-tables line from the MySQL configuration file.

8. Restart MySQL Service Again:

Finally, restart the MySQL service to apply the changes and restore normal functionality.

The above is the detailed content of How to Reset a Forgotten MySQL Root 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