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 incremental backup and breakpoint recovery script example

Introduction Incremental backup means that after ...

Install ethereum/Ethereum from scratch under CentOS7

Table of contents Preface Add sudo write permissi...

Vue implements simple calculator function

This article example shares the specific code of ...

Based on JavaScript ES new features let and const keywords

Table of contents 1. let keyword 1.1 Basic Usage ...

Talk about how to identify HTML escape characters through code

Occasionally you'll see characters such as &#...

HTML unordered list bullet points using images CSS writing

Create an HTML page with an unordered list of at l...

Detailed explanation of the relationship between Vue and VueComponent

The following case reviews the knowledge points o...

Detailed explanation of the solution to forget the password in MySQL 5.7

ENV: [root@centos7 ~]# uname -r 3.10.0-514.el7.x8...

Detailed tutorial on using the Prettier Code plugin in vscode

Why use prettier? In large companies, front-end d...

Several common CSS layouts (summary)

Summary This article will introduce the following...

Detailed installation and configuration tutorial of MySQL 5.7 under Win10

1. Unzip MySQL 5.7 2. Create a new configuration ...

CenterOS7 installation and configuration environment jdk1.8 tutorial

1. Uninstall the JDK that comes with centeros fir...