Mysql 5.7重置root密码
- 如果您忘记了MySQL 5.7的root密码,可以通过以下步骤重置:
停止MySQL服务。在命令行中输入以下命令:
systemctl stop mysqld
- 启动MySQL服务并跳过授权表。在命令行中输入以下命令:
mysqld_safe --skip-grant-tables &
- 以root用户登录MySQL。在命令行中输入以下命令:
mysql
use mysql;
- 重置root密码。将your_new_password替换为您想要设置的新密码,然后输入以下命令:
update user set authentication_string=PASSWORD('your_new_password') where User='root';
flush privileges;
quit;
systemctl stop mysqld
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.
评论区