Home > Database > Mysql Tutorial > body text

Mysql 5.6 What to do if you forget your password

PHPz
Release: 2023-04-20 10:51:26
Original
1313 people have browsed it

When using the MySQL database, the password is a very important part. But sometimes we may forget the MySQL password, what should we do at this time?

The following article will introduce the solution when forgetting the password in mysql5.6 version.

  1. Check MySQL version

Before performing any operation, we need to first check the MySQL version. We can check the MySQL version through the following command:

mysql -V
Copy after login

Running this command will display the MySQL version information, for example:

mysql  Ver 14.14 Distrib 5.6.51, for Linux (x86_64) using  EditLine wrapper
Copy after login
  1. Stop the MySQL service

Before resetting the password, we need to stop the MySQL service first. You can stop the MySQL service through the following command:

sudo service mysql stop
Copy after login
Copy after login
  1. Start the MySQL service to skip authentication

Next we need to start the MySQL service and skip authentication. We need to use the following command to start the MySQL service:

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

After executing this command, we can see that the MySQL service has been started. At the same time, we also set a "skip authentication" option, which will allow us to log in to MySQL without a password.

  1. Reset the password of the root account

Now we have successfully started the MySQL service and there is no authentication that requires a password. The next step is to reset the password of the root account.

First you need to log in to MySQL, enter the following command in the terminal, log in to the MySQL console:

mysql -u root
Copy after login

After logging in, we need to select the MySQL database:

use mysql;
Copy after login

Then we You can use the following command to change the password of the root user:

UPDATE user SET Password=PASSWORD('new_password') WHERE user='root';
Copy after login

In the command, replace new_password with your new password.

Finally, we need to refresh the permissions using the following command:

FLUSH PRIVILEGES;
Copy after login
  1. Restart the MySQL service

Now we have reset the password of the root account , and the permissions have been refreshed. We can shut down the MySQL service and restart it. You can use the following command to shut down the MySQL service:

sudo service mysql stop
Copy after login
Copy after login

Next, we can use the following command to start the MySQL service:

sudo service mysql start
Copy after login

Now you can use your new password to log in to MySQL.

Summary

Forgetting MySQL password is a very common mistake, but we can use the above 5 simple steps to reset the password. If you are unable to reset your password for any reason, you can try checking the MySQL documentation or contacting the MySQL support team to resolve the issue.

The above is the detailed content of Mysql 5.6 What to do if you forget your 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template