mysql 8+ forget the root password solution

After installing the database, since they do not care directly off of the installation screens, or no longer logged in as root system, leading to forget the root password, then you need to reset the MySQL root password. Of course, the easiest way nature is delete the data directory database, and then re-install the database. But a lot of time we need to retain data in the data directory, so we need to find out how to reset the root password.

We know that at the time know the root password, you can use the "ALTER USER 'root' @ ' localhost' IDENTIFIED BY ' new password';" command to change the root user's password, as shown below:

only this line instructions to complete to root the new password is set, no further action is very simple.
However, if you forget the root password, how to reset it? According to the official description of the document, under the Windows system There are two ways to change the password, official documents refer to: https: //dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
Option One: perform the initialization files
step 1: account login system using administrative privileges;
step 2: stop the MySQL service, regardless of the method used, it must stop, as shown below:

step 3: create a file mysql-init.txt, which read, modify command "ALTER USER 'root' @ ' localhost' IDENTIFIED BY ' new password';" password, then save the file, as shown in FIG:

step 4: in the terminal interface, to the next bin directory MySQL installation:

step 5: in the bin directory, execute mysqld, and specify the mysql-ini.txt just created as the initialization file, use the command is "mysqld -defaults-file =" D : \ Programs \ MySQL \ MySQL-8.0.12-winx64 \ my.ini "-init-file =" D : \ Programs \ MySQL \ mysql-ini.txt "", wherein, -defaults-file specifies a configuration file, -init-file initialization execution file is specified, as follows Figure:

After pressing the Enter key, do not close the terminal, need to open a terminal to confirm the password change was successful:

It is clear that the landing is successful, the correct password to modify the way!

Guess you like

Origin www.cnblogs.com/wrhbk/p/10991823.html