<title>What if MySQL forgets the root password under Linux?</title> What if MySQL forgets the root password under Linux? 1. Modify the MySQL configuration file
The default MySQL configuration file is /etc/my.cnf
, [mysqld]
add a line below
1.skip-grant-tables
2. Save the configuration file and restart the MySQL service
1.service mysqld restart
3. Go to MySQL again
1.[[Email protected] mysql]$ mysql-u root-p
2.Enter Password:#此处直接回车
3.Welcome to the MYSQL Monitor. Commands end with;or\g.
4.Your MySQL Connection ID is 2
5.Server version:5.7.11 MySQL Community server (Gpl)
6.
7.Copyright (C)+, Oracleand/orits affiliates. All rights reserved.
8.
9.Oracle is a registered trademark of Oracle Corporationand/orIts
.Affiliates. Other names trademarks of their respective
One by one .Owners.
.
.Type ' help; 'or' \h ' for help. Type ' \c ' to clear the current input statement.
.
A .Mysql>
.
So we can get into MySQL as usual.
4. Re-modify the root password
1.mysql> use MySQL
2.Reading table Information forCompletion ofTable andColumn names
3.You can turnoff ThisFeature toGet a quicker startup with-A
4.
5.Database changed
6.mysql> UPDATE user SET password = password (' 123456 ') WHERE user =' Root ';
7.ERROR1054( theS22): Unknown column' Password ' inch ' field List '
8.
This time there was a problem and no password was found in this field
The original MySQL database has no password This field, changed to a
1.authentication_string
So we're going to change the statement
1.set authentication_string=password(‘123456‘where user=‘root‘;
2.11 warning (0.03 sec)
3.1 1 1
4.
5.exit;
6.Bye
5. Edit the configuration file, delete the added line, and restart MySQL
1.[KANO@kelvin mysql]$ sudo vim /etc/my.cnf
2.[KANO@kelvin mysql]$ service mysqld restart
3.Redirecting to /bin/systemctl restart mysqld.service
4.
Then enter the password to log in to MySQL ~:-D
What to do if MySQL forgets the root password under Linux