Home > Database > Mysql Tutorial > body text

How to Recover a Forgotten MySQL Root Password?

Linda Hamilton
Release: 2024-11-05 18:51:02
Original
250 people have browsed it

How to Recover a Forgotten MySQL Root Password?

How to Retrieve the Forgotten MySQL Root Password

Problem:

Users may encounter situations where they've forgotten their MySQL root password. This can create a significant obstacle, especially for system administrators. Without the root password, accessing and managing MySQL becomes impossible.

Solution:

To recover the root password, a series of steps can be followed:

  1. Stop the MySQL Service:
<code class="shell">sudo service mysql stop</code>
Copy after login
  1. Launch MySQL in Safe Mode:
<code class="shell">sudo mysqld_safe --skip-grant-tables --skip-syslog --skip-networking</code>
Copy after login
  1. Connect to MySQL:

Open a new terminal and execute:

<code class="shell">mysql -u root</code>
Copy after login
  1. Update Password:

Enter the following queries to change the password:

<code class="sql">UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';
FLUSH PRIVILEGES;</code>
Copy after login

Note: For MySQL versions 5.7 and later, the field name in the query should be 'authentication_string' instead of 'password'.

  1. Exit Safe Mode and Restart MySQL:
<code class="shell">mysqladmin shutdown
sudo service mysql start</code>
Copy after login

With these steps, the root password will be reset, and users can regain access to their MySQL database. It's important to keep a record of the new password for future reference.

The above is the detailed content of How to Recover 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!