How to reset the root password in mysql8.0.12

How to reset the root password in mysql8.0.12

After installing the database, if you accidentally close the installation window or have not used the root user to log in to the system for a long time, you may forget the root password. In this case, you need to reset the MySQL root password. Of course, the easiest way is to delete the database data directory and then reinstall the database. But most of the time we need to keep the data in the data directory, so we need to find out how to reset the root password.

We know that when we know the root password, we can use the "ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';" command to modify the root user's password, as shown below:

Only this one line of command is needed to reset the root password. No other operations are required. It is very simple.
But how do you reset your root password if you forget it? According to the official documentation, there are two ways to change the password under Windows. For the official documentation, please refer to the link

Solution 1: Execute the initialization file

Step 1: Log in to the system using an account with administrative privileges;

Step 2: Stop the MySQL service. No matter what method you use, you must stop it, as shown below:

Step 3: Create a file mysql-init.txt, which contains the password change instruction "ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';", and then save the file, as shown in the figure:

Step 4: In the terminal interface, enter the bin directory where MySQL is installed:

Step 5: In the bin directory, execute mysqld and specify the mysql-ini.txt just created as the initialization file. The command used is "mysqld –defaults-file="D:\Programs\MySQL\MySQL-8.0.12-winx64\my.ini" –init-file="D:\Programs\MySQL\mysql-ini.txt"", where –defaults-file specifies the configuration file and –init-file specifies the file to be executed for initialization, as shown in the following figure:

After pressing the Enter key, do not close the terminal. You need to open another terminal to confirm whether the password change is successful:

Obviously, the login was successful and the password modification method was correct!

Of course, if you really close the terminal, you can also use the "net start MySQL" command to start MySQL and then verify it:

Step 6: Delete the created mysql-ini.txt file. Of course, you can also keep it!

Solution 2: Reset the root password by skipping the verification during login

Step 1: First shut down the MySQL service, then use the "--skip-grant-tables" configuration item to skip the permission verification method and restart the MySQL service:

The command used here is "mysqld –shared-memory –skip-grant-tables". If it is just "mysqld –skip-grant-tables", mysqld startup will fail and prompt "TCP/IP, –shared-memory, or –named-pipe should be configured on NT OS" error. After testing, it is found that only by adding “--shared-memory” can the database be started and accessed.

Step 2: Open a terminal, log in to the database without a password, and run mysql directly:

/p>

Step 3: First, refresh the execution instruction "FLUSH PRIVILEGES;" to refresh the permissions:

Then execute the command "ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_psd_123';" to update the password. "new_psd_123" is the new password set:

After the settings are completed, start the MySQL service normally and use the username and password to verify whether the settings are successful!

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • What should I do if I forget my MySQL password? How to reset MySQL root password
  • Detailed method for forgetting the root password or resetting the password in Mysql 5.7
  • How to reset MySQL root password under Windows
  • Reset mysql root password in linux system
  • How to reset the root user password of MySQL database if you forget it [Graphic]
  • How to reset the root password of Mysql in Windows if you forget it
  • Complete steps to reset the root user password in mysql8
  • How to solve the problem "Unknown column 'password" when resetting MySQL root password
  • The easiest way to reset mysql root password
  • A practical record of MySql resetting the root password and failing

<<:  CentOS 8 officially released based on Red Hat Enterprise Linux 8

>>:  Vue implements Modal component based on Teleport

Recommend

Design theory: people-oriented design concept

<br />When thoughts were divided into East a...

How to change the MySQL database directory location under Linux (CentOS) system

How to change the MySQL database directory locati...

How to create users and manage permissions in MySQL

1. How to create a user and password 1. Enter the...

jQuery plugin to implement minesweeper game (3)

This article shares the third article on how to u...

Use of MySQL DATE_FORMAT function

Suppose Taobao encourages people to shop during D...

Docker image optimization (from 1.16GB to 22.4MB)

Table of contents The first step of optimization:...

How to view server hardware information in Linux

Hi, everyone; today is Double 12, have you done a...

Native js to achieve puzzle effect

This article shares the specific code of native j...

Border-radius IE8 compatible processing method

According to canisue (http://caniuse.com/#search=...

How to use the dig/nslookup command to view DNS resolution steps

dig - DNS lookup utility When a domain name acces...

onfocus="this.blur()" is hated by blind webmasters

When talking about the screen reading software op...

Summary of pitfalls of using nginx as a reverse proxy for grpc

background As we all know, nginx is a high-perfor...

CentOS 6 Compile and install ZLMediaKit analysis

Install ZLMediaKit on centos6 The author of ZLMed...

Bug of Chinese input garbled characters in flex program Firefox

Chinese characters cannot be input in lower versio...