What to do if MySQL forgets the root password under Linux

Source: Internet
Author: User

<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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.