发布于 

MySQL找回密码

修改配置文件

[root@CentOS01 /]# vim /etc/my.cnf
#配置文件中[mysql]新增如下行
skip-grant-tables

重启数据库

[root@CentOS01 /]# systemctl restart mysqld

登录MySQL修改密码

[root@CentOS01 /]# mysql -uroot
mysql> use mysql;
mysql> update user set authentication_string=password("新密码") where user="root";
##mariaDB使用如下命令
update user set password=password("123456") where user="root";
mysql> flush privileges;

注销配置文件中之前新增的行,并重启MySQL

[root@CentOS01 /]# vim /etc/my.cnf
#skip-grant-tables
[root@CentOS01 /]# systemctl restart mysqld