MySQL root password forgotten how to do?

1, modify the mysql configuration file, implement password-free login

在mysql配置文件中添加以下参数:
[mysqld]
skip-grant-tables

2, restart the MySQL service

service mysqld restart

3, free secret landing

mysql -uroot -p (直接点击回车,密码为空)

4, change the root password

1.切换数据库
use mysql;
2.执行命令修改密码
update user set password=password('root') where user='root';
//5.7 以后版本执行上面命令报错可以尝试以下语句:
update user set authentication_string=password('123456') where user='root';
3.刷新权限
flush privileges;
//可能会出现的异常
ERROR 1820 (HY000): You must reset your password using ALTER USER statement;
//解决办法(执行以下命令):
alter user user() identified by "root";

5, restore the configuration file, restart the Mysql service

[mysqld]
#skip-grant-tables
//重启服务
service mysqld restart

6, using the new password

mysql -uroot -p (回车输入密码)
Released four original articles · won praise 6 · views 1760

Guess you like

Origin blog.csdn.net/m0_46422300/article/details/104685630