After MySQL forgets the root password _ MySQL

Source: Internet
Author: User
When the root user logs on to MySQL, the system finds that the password is incorrect.

[Root @ gk ~] # Mysql-u root-p
Enter password:
ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: NO)

Solution

1. stop the mysqld service

[Root @ gk ~] # Service mysqld stop
Stop mysqld: [OK]


2. Execute mysqld_safe -- skip-grant-tables

[Root @ gk ~] # Mysqld_safe -- skip-grant-tables
140607 22:21:50 mysqld_safe Logging to '/var/log/mysqld. log '.
140607 22:21:50 mysqld_safe Starting mysqld daemon with databases from/var/lib/mysql

3. log on to mysql

[Root @ gk ~] # Mysql
Welcome to the MySQL monitor. Commands end with; or/g.
Your MySQL connection id is 1
Server version: 5.1.71 Source distribution

Copyright (c) 2000,201 3, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.

Type 'help; 'or'/h' for help. type'/C' to clear the current input statement.

4. switch to the mysql database

Mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-

Database changed


5.Update password

Mysql> update user set password = password ('redhat') where user = 'root ';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 3 Changed: 2 Warnings: 0

Mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

Mysql> exit
Bye

6. restart the mysqld service.


[Root @ gk ~] # Service mysqld restart
Stop mysqld: [OK]
Starting mysqld: [OK]

7. log on with the new password

[Root @ gk ~] # Mysql-u root-p
Enter password:
Welcome to the MySQL monitor. Commands end with; or/g.
Your MySQL connection id is 2
Server version: 5.1.71 Source distribution

Copyright (c) 2000,201 3, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.

Type 'help; 'or'/h' for help. type'/C' to clear the current input statement.

Mysql>

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.