When using the MySQL database, if you have not logged into MySQL for a long time due to some reasons, or if the work handover is not completed well, you may forget the database root login password. How can you solve this problem? 1. Change the my.cnf configuration file 1. Edit the /etc/my.cnf configuration file using the command: vim /etc/my.cnf or vi /etc/my.cnf or nano /etc/my.cnf 2. Add skip-grant-tables under [mysqld], then save and exit 3. Restart the mysql service: service mysqld restart 2. Change the root username 1. After restarting, execute the mysql command to enter the mysql command line 2. Change the root user password
Note: The above is for versions before 5.7. Versions after 5.7 do not have the Password field, and the password field is changed to authentication_string
At this point, either set the password to be more complex or modify the configuration: This is actually related to the value of validate_password_policy. validate_password_policy has the following values: The default value is 1, which means MEDIUM, so the password you set at the beginning must meet the length and must contain numbers, lowercase or uppercase letters, and special characters. Sometimes, just for my own testing, I don’t want to set a complicated password. For example, I just want to set the root password to 123456. Two global parameters must be modified: First, modify the value of the validate_password_policy parameter mysql> set global validate_password_policy=0; Query OK, 0 rows affected (0.00 sec) 1 2 The validate_password_length parameter defaults to 8, which we change to 1 mysql> set global validate_password_length=1; Query OK, 0 rows affected (0.00 sec) 1 2 4. After completion, execute the password change statement again to succeed mysql> alter user 'root'@'localhost' identified by '123456'; Query OK, 0 rows affected (0.00 sec) 3. Finally, comment out skip-grant-tables in /etc/my.cnf, and then restart mysql, that is: service mysqld restart OK, now we can use the new root password to log in to MySQL. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Teach you how to implement Vue3 Reactivity
>>: Example analysis of the use of GROUP_CONCAT in MySQL
effect: The GROUP_CONCAT function can concatenate...
Preface Recently, due to work reasons, I was work...
Article mind map Why use master-slave replication...
What Beautiful HTML Code Looks Like How to write ...
Table of contents Preliminary work Backend constr...
This article uses examples to illustrate the prin...
1. Under 800*600, if the width of the web page is...
Effect: The title has its own serial number, the ...
This article shares the specific code for impleme...
Analyze the execution process. Move the mouse int...
Ubuntu 20.04 has been officially released in Apri...
Problem Description Install nginx on Tencent Clou...
Table of contents 1. Encapsulation API 2. Registe...
1. Overview MySQL version: 5.6.21 Download addres...
The drag function is mainly used to allow users t...