How to recover deleted MySQL 8.0.17 root account and password under Windows

How to recover deleted MySQL 8.0.17 root account and password under Windows

I finished learning SQL by myself not long ago, and downloaded MySQL 8.0.17. After installing and configuring it, I explored it and wondered if I could delete the root account by logging in with the root account. Then I wanted to slap myself...

How to quickly restore root:

1. Close the MySQL service: press win+R, type services.msc, find the MySQL service, and click stop;

2. Delete the data folder and its files: Enter the mysql folder, find the data folder and delete it;

3. Initialize mysql: Enter services.msc again and run the mysql service; enter the mysql\bin file path in the cmd window and run mysqld --initialize --console. The result is similar to the following:

2019-08-07T02:08:11.300849Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is
deprecated. Please use --explicit_defaults_for_timestamp server option (see doc
umentation for more details).
2019-08-07T02:08:11.724874Z 0 [Warning] InnoDB: New log files created, LSN=45790

2019-08-07T02:08:12.024891Z 0 [Warning] InnoDB: Creating foreign key constraint
system tables.
2019-08-07T02:08:12.056893Z 0 [Warning] No existing UUID has been found, so we a
ssume that this is the first time that this server has been started. Generating
a new UUID: 35611a71-b8b8-11e9-8e24-28d24409926b.
2019-08-07T02:08:12.064893Z 0 [Warning] Gtid table is not ready to be used. Tabl
e 'mysql.gtid_executed' cannot be opened.
2019-08-07T02:08:12.076894Z 1 [Note] A temporary password is generated for root@
localhost: QTpg4Y!sh:dk

Note that the bold statement contains the temporarily generated root account password;

4. Run mysql in cmd: type mysql -u root -p+root password; Note: p is the abbreviation of password. According to the above example, you should type: mysql -u root -pQTpg4Y!sh:dk -p and password must be connected together to be effective, without space in between;

5. Modify the temporary root password: Run the SQL statement: alter alter user root@localhost identified by ' root密碼' ; Note: The password must be contained in English single quotes '', otherwise it will be invalid and an error will be reported. The semicolon at the end must also be written.

6. Check whether the query is successful: Run the SQL statement: select user from mysql.user; 成功顯示root賬戶;

Note: Although this method is quick and effective, it will delete all database files, that is, the databases in the data folder. I have tried adding skip-grant-tables to bypass login authentication, but it is not effective for version 8.0.17.

Summarize

The above is what I introduced to you on how to recover the deleted Mysql8.0.17 Root account and password under Windows. I hope it will be helpful to you!

You may also be interested in:
  • Implementation of MySQL5.7 mysqldump backup and recovery
  • Two methods of restoring MySQL data
  • Steps for restoring a single MySQL table
  • MySQL database backup and recovery implementation code
  • MySQL uses mysqldump+binlog to completely restore the deleted database principle analysis
  • Analysis of MySQL data backup and recovery implementation methods
  • Shell script to implement mysql scheduled backup, deletion and recovery functions
  • Sharing of the fast recovery solution for Mysql large SQL files
  • MySQL Binlog Data Recovery: Detailed Explanation of Accidentally Deleting a Database
  • How to restore a database and a table from a MySQL full database backup
  • MySQL quick recovery solution based on time point

<<:  JavaScript to achieve calendar effect

>>:  Detailed steps for installing, configuring and uninstalling QT5 in Ubuntu 14.04

Recommend

MySQL performance optimization: how to use indexes efficiently and correctly

Practice is the only way to test the truth. This ...

MySQL character set garbled characters and solutions

Preface A character set is a set of symbols and e...

MySQL Packet for query is too large problem and solution

Problem description: Error message: Caused by: co...

What to do if you forget your mysql password

Solution to forgetting MySQL password: [root@loca...

Three methods of inheritance in JavaScript

inherit 1. What is inheritance Inheritance: First...

MySQL statement execution order and writing order example analysis

The complete syntax of the select statement is: S...

Mysql join table and id auto-increment example analysis

How to write join If you use left join, is the ta...

How are Vue components parsed and rendered?

Preface This article will explain how Vue compone...

Steps for docker container exit error code

Sometimes some docker containers exit after a per...

Sample code for nginx to achieve dynamic and static separation

1. Simple configuration of nginx's dynamic an...

Solve the problem of inconsistency between mysql time and system time in docker

Recently, when I installed MySQL in Docker, I fou...

Comparison of two implementation methods of Vue drop-down list

Two implementations of Vue drop-down list The fir...

Mysql specifies the date range extraction method

In the process of database operation, it is inevi...