Often have friends or colleagues ask, MySQL root password forgot, do not know how to do.
In fact, the solution is very simple, the following is a detailed procedure.
(1) Modify the configuration file my.cnf, add it under Configuration file [Mysqld]
skip-grant-tables,重启MySQL服务即可免密码登录
Where the--skip-grant-tables option was previously introduced, meaning that the MySQL service was started by skipping the permission table authentication. After booting, the root of the connection to MySQL will not require a password.
---------------------------------------------------------------------- this # file.#[mysqld ]Skip-grant-tables
(2) Connect to MySQL with the root user of the blank password and change the root password:
[email protected] mysql]# MySQL- urootWelcome to the MySQL Monitor. Commands End With; or \g.your MySQL connection ID is -Server Version:5.0. A-community-log MySQL Community Edition (GPL) Type'Help ;'Or'\h' forHelp. Type'\c'To clear the buffer. MySQL >mysql> ALTER USER ' root ' @ ' localhost ' identified with Mysql_native_password by ' 123 ';
1290 is running with the--skip-grant- This statement
mysql> Update user Set authentication_string = NULL where user = ' root ';
1 Row affected (0.00 sec)
The root password was first modified with Grant, but the change password using the ALTER USER command failed due to the use of the Skip-grant-tables option configured, straight
The password change succeeds after updating the authentication_string field of the user table.
(3) To my.cnf remove the skip-grant-tables option, and then directly with the mysql-uroot password-free login, after executing the following statement reset password
' Root '@'localhost'123'
(4) When you re-login with root, you must enter a new password.in MySQL, passwords cannot be retrieved after they are lost, and passwords can only be modified in the above way.
A workaround for forgetting the root password of MySQL