Bạn có thể khôi phục lại MySQL mật khẩu máy chủ cơ sở dữ liệu dễ dàng qua một vài bước sau:

Bước 1 : Stop mysql service

[root@server ~]# service mysqld stop
Shutting down MySQL. SUCCESS!

Bước 2 : Start to MySQL server w/o password:

[root@server ~]# mysqld_safe --skip-grant-tables &
[1] 5470
[root@server ~]# 160617 17:14:53 mysqld_safe Logging to '/var/lib/mysql/server.vps157.vn.err'.
160617 17:14:53 mysqld_safe A mysqld process already exists

Bước 3: Kết nối tới máy chủ database mysql client:

[root@server ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.31 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, 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>

Bước 4: Setup mật khẩu mới MySQL cho user root:

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 -A

Database changed
mysql> update user set password=PASSWORD("Admin@123") where User='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

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

mysql> quit
Bye

Bước 5: Stop MySQL Server:

[root@server ~]# service mysqld stop
Shutting down MySQL. SUCCESS!

Bước 6: Start MySQL server và kiểm tra nó:

[root@server ~]# service mysqld start
Starting MySQL SUCCESS!

 

[root@server ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.31 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, 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>
 

Chúc bạn thực hiện thành công !