The solution to the root password of the forgotten MySQL under CentOS

Source: Internet
Author: User

One: ( stop running MySQL)
[[email protected] ~]# service mysql stop
Second: Restart MySQL with the "--skip-grant-tables" parameter
[email protected] ~]# mysqld_safe--skip-grant-tables &

[1] 23810
starting mysqld daemon with databases From/var/lib/mysql
Three: Use rootAccount Login MySQL
[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 distributiontype ' help, ' or ' \h ' for help. Type ' \c ' to clear the buffer.
Four: Change 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-adatabase changed
Five: Change Password, rememberPasswordto use password ()function for encryption
mysql> Update user set Password=password (' Netdak ') where user= ' root ';
Query OK, 1 row affected (0.04 sec)
Rows matched:1 changed:1 warnings:0
Six: Refresh the permissions table
mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)
Seven: Quit MySQL
Mysql> quit
eight: to MySQLto restart
[[Email protected] ~]# service MySQL restart;
stopping server from PID file/var/run/mysqld/
100421 13:44:03 mysqld endedstopping MySQL: [OK]
starting MySQL: [OK]
[1]+ done Mysqld_safe--skip-grant-tables
Nine: Use a changed passwordyou can log in again.
[email protected] ~]# mysql-u root-p
Enter Password:netdak
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 2
Server version:5.0.77 Source distributiontype ' help, ' or ' \h ' for help. Type ' \c ' to clear the buffer.mysql> quit

10. Re-execute Password change


Note: The tenth step is not required, but MySql5.6 operation may be error: You must SET PASSWORD before executing this statement.

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: 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.