A brief analysis of the best way to deal with forgotten MySQL 8 passwords

A brief analysis of the best way to deal with forgotten MySQL 8 passwords

Preface

Readers who are familiar with MySQL may find that MySQL is updated very quickly. In terms of installation, MySQL provides two classic installation methods: decompression and one-click. Although there are two installation methods, I prefer the decompression installation, which is not only fast but also clean. In terms of operating system, MySQL also supports multiple types of operating systems, such as Linux, Windows, etc. The following are several operating systems with major changes in MySQL.

Through research and analysis, it is not difficult to find that: as MySQL iterates from low versions to high versions, increasingly rigorous security is one of its major features. For example, before version 6, when you forget your password, it is very convenient to reset it. You only need to perform the following two steps:

Step 1: Skip the permissions table

mysqld --skip-grant-tables

Step 2: Leave the password blank

UPDATE user SET authentication_string='' WHERE user='root';

However, this solution is not applicable to MySQL 8.

This article will solve the problem of resetting the password if you forget the MySQL 8 password. It mainly includes three aspects

Content 1: Briefly describe the decompression installation of MySQL 8

Content 2: Forgot your password and reset it Solution 1

Content 3: Forgot your password and reset it Solution 2

One installation

1. Download the installation package from the official website (the official website provides two installation methods: visual installation and decompression). This example is based on the decompression method. Official website download address: https://dev.mysql.com/downloads/mysql/

2. Unzip the installation package and put it in the C:\MySQL directory

3. Configure environment variables

MySQL_HOME="C:\MySQL\mysql-8.0.15-winx64"

PATH="%MySQL_HOME%\bin"

4. Open DOS as an administrator

(1) Start the service

mysqld --install

(2) Initialize and generate an initialization password (MySQL 7+ does not have a data directory, so the data directory is installed initially)

mysqld --initialize --user=mysql --console

(3) Start the service

net start mysql

(4) Log in

Account root, password is the temporary password A*v)(Ivw7xjQ generated by the initial session, which needs to be changed after logging in

(5) Change the root password

Format: alter user 'user name'@'login host' identified by 'password (custom)';

(6) Log in with new password

(7) Extended commands

Remove service: mysql --remove

Stop the mysql service: mysql stop mysql

Exit mysql:exit

2. Solve the problem of forgetting password

(I) Plan 1

1. Enter DOS as an administrator

2. Stop the mysql service

net stop mysql

3. Start without password

mysqld --console --skip-grant-tables --shared-memory

4. Open another DOS window and log in without a password

5. Clear password

Note: authentication_string uses plugin encryption, so set it to empty and do not set it to other values.

6. Start the service

Close the two open DOS windows, then reopen a DOS window as an administrator and start the service

net start mysql

7. Password-less login

mysql -u root

8. Reset your password

After modification, you can log in with the new password.

9. Log in with new password

(II) Solution 2: Using the --init-file parameter

1. Stop the service

net stop mysql

2. Create the ResetPWD.txt file in the c:\MySQL directory. The content of the file is

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

3. Execute the ResetPWD.txt file

mysqld --init-file=c:\mysql\ResetPWD.txt --console, after execution, close the DOS window

4. Start mysql

net start mysql

5. Log in with your new password

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • How to reset password after forgetting password in MySQL8 (MySQL old method doesn't work)
  • The perfect solution for forgetting the password in mysql8.0.19
  • Solution for forgetting the root password of MySQL5.7 under Windows 8.1
  • Pitfalls encountered when installing MySQL 8.0.18 compressed package and resetting forgotten passwords
  • mysql8.0 forgotten password modification and net command service name invalid problem
  • Quick solution for forgetting MySQL8 password

<<:  Solve the cross-domain problem of Vue+SpringBoot+Shiro

>>:  How to implement Docker Registry to build a private image warehouse

Recommend

How to change $ to # in Linux

In this system, the # sign represents the root us...

How to get the current time using time(NULL) function and localtime() in Linux

time(); function Function prototype: time_t time(...

Several specific methods of Mysql space cleaning

Table of contents Preface 1. Check the file disk ...

Some problems you may encounter when installing MySQL

Question 1: When entering net start mysql during ...

Understand all aspects of HTTP Headers with pictures and text

What are HTTP Headers HTTP is an abbreviation of ...

Some common advanced SQL statements in MySQL

MySQL Advanced SQL Statements use kgc; create tab...

Steps to install RocketMQ instance on Linux

1. Install JDK 1.1 Check whether the current virt...

Mysql varchar type sum example operation

Some friends, when learning about databases, acci...

HTML marquee tag usage examples

This tag is not part of HTML3.2 and only supports ...

Implementing a distributed lock using MySQL

introduce In a distributed system, distributed lo...

React Routing Link Configuration Details

1. Link's to attribute (1) Place the routing ...

Introduction to Docker containers

Docker Overview Docker is an open source software...

CSS to implement sprites and font icons

Sprites: In the past, each image resource was an ...