数据库的登录密码忘记时,我们应该怎么办??

如果我们忘记数据库的登录密码,在登录过程中,认证失败,该怎么办呢???

[root@shareserver ~]# mysql  -uroot -plee  
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

首先,关闭数据库mariadb服务,进入安全模式,跳过授权这一步,输入mysql命令进入到数据库中

[root@shareserver ~]# systemctl stop mariadb
[root@shareserver ~]# mysqld_safe --skip-grant-tables &   ##进入安全模式,跳过授权



 其次,修改数据库的密码

MariaDB [(none)]> UPDATE mysql.user SET PASSWORD=password('lee') WHERE USER='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 3  Changed: 1  Warnings: 0
 



最后,退出数据库,查看并删除和mysql相关的所有进程,并重新开启数据库服务
 

[root@shareserver ~]# ps aux |grep mysql      ##删除和mysql相关的所有进程
[root@shareserver ~]# systemctl start mariadb      ##开启服务



重新登录检测

[root@shareserver ~]# mysql -uroot -plee           ##登陆


此时登陆成功!!!!
 
 
 
 
 
 
 

猜你喜欢

转载自blog.csdn.net/sinceNow/article/details/84589214