update user set authentication_string=PASSWORD('your_new_password') where User='root';
刷新权限。输入以下命令:
flush privileges;
退出MySQL。输入以下命令:
quit;
停止MySQL服务。在命令行中输入以下命令:
systemctl stop mysqld
重新启动MySQL服务。在命令行中输入以下命令:
systemctl start mysqld
现在已经成功重置了MySQL 5.7的root密码,能正常登录mysql了。
[root@test mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.38-log MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.