MySQL 5.7 reset root password, tried N methods and finally found it

The operating system is windows, the MySQL version is 5.7, and my.ini is in another path.

It has been used for a while, and several users have been set up. Because I want to change the root password recently, I use the online:

mysqladmin -uroot -pmy_old_pwd password my_new_pwd

to change the password. After restarting the service, I found that the change was not successful. I tried several times, including updating mysql.user directly, but it was unsuccessful. As a result, when I tried again, the following error message appeared:

mysqladmin: connect to server at 'localhost' failed.

So I found the official documentation of MySQL 5.7: http:/ /dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

Follow the steps below:

1. Modify my.ini and add a line under [mysqld]:

skip-grant-tables

2. Restart mysql

3. In the mysql/bin directory, execute mysql -uroot to connect to mysql

4. Refer to the official first time above,
  
   use the following command for versions after 5.7.6:
   ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
   after running, the output is as follows Information, indicating unsuccessful
   Query OK, 0 rows affected (0.00 sec)


   So use the command before version 5.7.5:
   SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
   After running, the following information is displayed, indicating that it was not successful
   . Query OK, 0 rows affected (0.00 sec)

5 . Test again with the following command:
    UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPass') password_expired = 'N'
    WHERE User = 'root' AND Host = 'localhost';
    also after running: Query OK, 0 rows affected
    so the following 6. Then use the following command to relax the where condition update
    mysql.user    set authentication_string=PASSWORD('newpassword') where User='root';    After execution, it will prompt: Query OK, 1 row affected. .. Explain that there is a play 7. Modify my.ini back, restart mysql, and do a test: the new password of the root user is available, and the old password is no longer available. Other users were not affected.












Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326523601&siteId=291194637