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.