Official tutorial on password reset for MySQL8 on Linux system

Step 1: Create a file mysql-passwd with the following contents

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

Step 2: Start through mysqld

mysqld --user=mysql --init-file=/tmp/mysql-passwd

An error was encountered during startup as follows

The reason is that --user=mysql is not added

Step 3: Re-open a window and log in using the password in mysql-passwd

After logging in, change the password to be used (it is not recommended to use a simple one such as 12345678)

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

quit;

Step 4: End the MySQL process and delete the mysql-passwd file.

Step 5: Start normally and log in with the modified password

Start systemctl start mysql.service

Login mysql -uroot -p

おすすめ

転載: blog.csdn.net/weirdo_world/article/details/124860888