A workaround for forgetting the root password of MySQL

Source: Internet
Author: User

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

Related Article

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.