1. Close the database
Script: [[email protected] etc]# service MySQL stop
2. Use script: Mysqld_safe--skip-grant-tables start Database
Starting a database with/usr/bin/mysqld_safe--skip-grant-tables&
3. Use a blank password to enter the database (MySQL command directly after the return)
[[email protected] ~]# MySQL
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 3
Server version:5.6.20-enterprise-commercial-advanced MySQL Enterprise server-advanced Edition (commercial)
Copyright (c), the Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql>
4. Use the UPDATE statement to change the root password
mysql> UPDATE Mysql.user SET
-Password=password (' root ')
, where
-user= ' root ' and host= ' localhost ';
5. Close the database and start the database again in the normal way
[[Email protected] ~]# service MySQL restart;
Shutting down MySQL. success!
Starting MySQL. success!
[[email protected] ~]# MySQL
ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)
[Email protected] ~]# mysql-p
Enter Password:
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 2
Server version:5.6.20-enterprise-commercial-advanced MySQL Enterprise server-advanced Edition (commercial)
Copyright (c), the Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql>
MySQL Change password and forget root password