登入数据库时,用root账号,但是忘记密码,可以采用强制跳过密码的方式,然后再重新设置密码:
1、输入以下命令,该命令必须在Linux的root账号下进入
vim /etc/my.cnf
添加下面语句
skip-grant-tables
2、重启数据库
systemctl restart mysqld
3、root账号登入数据库,此时回车就可以跳过密码
mysql -uroot -p
4、进入数据库,然后就可以修改密码
update user set authentication_string=password('') where user='root' and host='localhost';
5、将原先添加的 skip-grant-tables 删掉或者注释掉
6、重启数据库,即可按新的root密码登入数据库