CentOS system MySQL forgot root user's password

Source: Internet
Author: User

First step: (Stop running MySQL)
[Root@maomao ~]# service mysqld Stop
Stopping MySQL: [ OK ]

Step two: Restart MySQL with the "--skip-grant-tables" parameter
[Email protected] ~]# Mysqld_safe--skip-grant-tables

[email protected] ~]# starting mysqld daemon with databases From/var/lib/mysql

Note: If you stop at this point, please open the SSH login and proceed to the next step.

Step three: Log in to MySQL with your account
[Email protected] ~]# mysql-u root
Welcome to the MySQL Monitor. Commands End with; or \g.
Your MySQL Connection ID is 1
Server version:5.0.77 Source Distribution

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the buffer.

Fourth step: Change the user database
mysql> use MySQL
Reading table information for completion of table and column names
Can turn off this feature to get a quicker startup with-a

Database changed

Fifth Step: Change the password, below () The root123 is Xinmi Code
mysql> Update user Set Password=password (' root123 ') where user= ' root ';

Query OK, 3 Rows Affected (0.00 sec)

Rows Matched:3 Changed:3 warnings:0

Sixth step: Refresh the Permissions table
mysql> Flush Previleges;
Error 1064 (42000): You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near ' previleges ' on line 1

Seventh Step: Exit MySQL
Mysql> quit
Bye

Eighth Step: Restart MySQL
[[Email protected] ~]# service mysqld restart;

Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]

Nineth Step: Re-login with a changed password.
[Email protected] ~]# mysql-u root-p
Enter password:admin123
Welcome to the MySQL Monitor. Commands End with; or \g.
Your MySQL Connection ID is 2
Server version:5.0.77 Source Distribution

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the buffer.

Mysql> quit
Bye

[Email protected] ~]#

Add the following auto-start command/etc/rc.d/init.d/mysqld start

CentOS system MySQL forgot root user's password

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.