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.
Before performing any operation, we need to first check the MySQL version. We can check the MySQL version through the following command:
mysql -V
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
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
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 &
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.
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
After logging in, we need to select the MySQL database:
use mysql;
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';
In the command, replace new_password with your new password.
Finally, we need to refresh the permissions using the following command:
FLUSH PRIVILEGES;
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
Next, we can use the following command to start the MySQL service:
sudo service mysql start
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!