After some searching, I realized that I should log in with a username and password:
mysql -u root -p
If you forget your password, there are steps to solve it in the later section.
Server version: 8.0.19 MySQL
and 8.0.13 MySQL
have been verified.
msyql> use msyql;
msyql> alter user 'root'@'localhost' identified by '123';
msyql> flush privileges;
verification:try to login with mysql -u root -p
to see if it is successful.
If there is no accident, you can see that the password change is successful.
Step 1: Shut down the mysql service
the mysql service can be closed by net stop mysql
as administrator or in the task manager.
Step 2: Skip Mysql password verification
Enter the command prompt (as administrator) operation, enter the \bin
folder in the \mysql
directory, the difference between mysql8.0
and other versions is that mysqld --skip-grant-tables
cannot be used directly to skip password login. Here we use mysqld -console --skip-grant-tables --shared-memory
to skip permission verification.
C:\Windows\system32> d:
D:\> cd D:\mysql-8.0.19-winx64\bin
D:\mysql-8.0.19-winx64\bin> mysqld -console --skip-grant-tables --shared-memory
D:\mysql-8.0.19-winx64\bin>
There is no feedback after the input is executed.
next, open a new administrator window to execute again.After entering the directory, make sure that you have closed the Mysql service:
net stop mysql
After closing the Mysql service, continue to operate in the D:\mysql-8.0.19-winx64\bin
directory:
execute:
mysql --console --skip-grant-tables --shared-memory
After entering this line of code, as shown below, we have successfully skipped Mysql password login:
Step 3: Enter Mysql without password
After the above steps, open another cmd.exe
running in administrator mode (this is the third window)
After entering the bin
directory under mysql, log in directly to mysql
No need to open mysql service via net start mysql
Enter the following code in the command line
> d:
> cd D:\mysql-8.0.19-winx64\bin #This should be changed to your own path
> mysql -u root -p
At this point, it will show you to enter the password, press Enter directly, and you can successfully connect to Mysql.
Step 4: Set the login password to empty
Enter the code and set the password to be empty (the password cannot be directly modified at this time, it must be set to be empty first, otherwise an error will be reported)
input:
> use mysql;
# leave the password blank
> update user set authentication_string='' where user='root';
# then quit Mysql
> quit;
Step 5: Change your login password
It is divided into two parts
cmd
windows (must be closed!);# close the mysql service, although it will show that the service is not started, but just in case
net stop mysql
# open the mysql service again
net start mysql
we must do this, if the last mysql service is not closed, we still log in without a password.
Then enter:
# Enter the installation directory on your computer here
cd D:\mysql-8.0.19-winx64\bin
# The input password will be displayed here, just press Enter, we have left it empty in the fourth step
mysql -u root -p
# (change the password)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
last step: verify that the password has been changed successfully
enter:
# exit mysql
quit
# Enter new password and log in again
mysql -u root -p
done!