Home > Database > Mysql Tutorial > body text

How to Reset a Forgotten MySQL Root Password?

Patricia Arquette
Release: 2024-11-02 14:17:02
Original
764 people have browsed it

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

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

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

4. Check MySQL Service Status:

Verify that the MySQL service is running properly:

sudo service mysql status
Copy after login

5. Login to MySQL with Root:

Log into MySQL without a password using the command:

mysql -u root
Copy after login

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

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!