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
Usually in project development, we have to deal wi...
When using jquery-multiselect (a control that tra...
Does performance really matter? Performance is im...
Table of contents Install Pagoda Configure Python...
Preface The sleep system function in MySQL has fe...
Table of contents Preface Asynchronous loading Pa...
1. Alibaba Cloud selects the appropriate cloud se...
A word in advance: Suddenly I received a task to ...
What is the input type="file"? I don'...
Method 1: Use CSS overflow omission to solve The ...
Usually the goal of building a website is to have...
Note 1: The entire background in the above pictur...
Table of contents Introduction Install 1. Create ...
I use Navicat as my database tool. Others are sim...
Table of contents Preface 1. Get the length of a ...