CentOS to forget the MySQL root password solution Summary

Source: Internet
Author: User

One: (Stop running MySQL)

The code is as follows Copy Code
[Root@netdakvps ~]# service mysqld Stop

Two: Restart MySQL using the "--skip-grant-tables" parameter

The code is as follows Copy Code
[Root@netdakvps ~]# mysqld_safe--skip-grant-tables &
[1] 23810
Starting mysqld daemon with databases From/var/lib/mysql

Third: Login to MySQL with root account

The code is as follows Copy Code

[Root@netdakvps ~]# 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

The code is as follows Copy Code
mysql> use MySQL
Reading table information for completion of table and column names
You can turn off this feature a quicker startup With-adatabase changed

Five: Change password, remember password to use password () function to encrypt

The code is as follows Copy Code
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 permission table

The code is as follows Copy Code
mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)

Seven: Exit MySQL

The code is as follows Copy Code

Mysql> quit

Bye
Eight: Restart MySQL

The code is as follows Copy Code
[Root@netdakvps ~]# service mysqld restart;
Stopping server from PID File/var/run/mysqld/mysqld.pid
100421 13:44:03 mysqld endedstopping MySQL: [OK]
Starting MySQL: [OK]
[1]+ done Mysqld_safe--skip-grant-tables

Nine: Log in again with a changed password.

The code is as follows Copy Code

[Root@netdakvps ~]# 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
Bye


Attach Other methods

1. Kill off the MySQL process in the system;

The code is as follows Copy Code
Killall-term mysqld

2. Use the following command to start MySQL, to do not check the permissions of the way to start;

The code is as follows Copy Code
Safe_mysqld--skip-grant-tables &

3. Then use the null password method to log in to MySQL with root user;

The code is as follows Copy Code
Mysql-u Root

4. Change the password of root user;

The code is as follows Copy Code
mysql> Update Mysql.user Set Password=password (' New password ') where user= ' root ';
mysql> flush Privileges;
Mysql> quit

Restart MySQL and you can log on with the new password.

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.