数据库忘记密码
5.7版本的数据库忘记密码解决办法
管理员密码忘记的处理
登录的时候显示如下报错
[root@db01 ~]# mysql -uroot -pasdfasdfasdf
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
(1)停数据库
[root@db01 ~]# /etc/init.d/mysqld stop
(2)“单用户”模式启动数据库
service mysqld start --skip-grant-tables --skip-networking
或者:
mysqld_safe --skip-grant-tables --skip-networking &
( 3)登陆数据库改密码
mysql> alter user root@'localhost' identified by '123';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> flush privileges ;
Query OK, 0 rows affected (0.01 sec)
mysql> alter user root@'localhost' identified by '123';
Query OK, 0 rows affected (0.00 sec)
(4)重启数据库到正常模式
[root@db01 ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@db01 ~]# mysql -uroot -p123
8.0版本的数据库忘记密码解决办法
1 停数据库
systemctl stop mysqld
2 启动安全模式
mysqld_safe --skip-grant-tables --skip-networking &
mysql
3 改密码
flush privileges; 刷新授权表
alter user root@'localhost' indentified by '123456';
4 重启数据库到正常模式
/etc/init.d/mysqld restart