MySQL8.0. Forgot password solution reported ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

foreword

I seem to have encountered a hacker recently, and the database is always deleted. Then I added permissions to the database and prohibited the use of the drop command. As a result, I also restricted myself. I created a new table, but I couldn’t delete it. The following method can use the drop command across user permissions, and it can also solve the problem of password forgetting.

Note: The database I am using is MySQL8.0

The first step: close the service net stop mysql This needs administrator privileges, how to use the administrator to open cmd to skip

 Step 2: Go to the installed bin directory and execute: mysqld --console --skip-grant-tables --shared-memory

 

The output of this step is required. If there is an error in this step, you need to deal with it yourself. Do not close this window after execution, and start a new cmd window.

Step 3: Start a new cmd window and execute mysql -uroot -p to enter without password

The fourth part changes the password:

   1.  use mysql 

   2. update user set authentication_string='' where user='root' If this field has a value, set it to empty first

   3. flush privileges to refresh the privilege table (you can do anything after this step, change the password, delete the table, modify the table name, etc.)

   4. ALTER user 'root'@'localhost' IDENTIFIED BY '123456' to modify the root password

 

 

Guess you like

Origin blog.csdn.net/gaoqingliang521/article/details/122935759