ByteBeat

描述:忘记了mysql的登录密码,无法登录的情况下该怎么办?

环境:CentOS 7,数据库:mysql 5.7

1、停止数据库(先查看mysql服务是否运行)

# ps -ef | -i grep mysql    //查看mysql运行状态
# service mysql stop

2、编辑mysql配置文件,配置文件目录:/etc/my.cnf

[mysqld]
skip-grant-tables    //跳过密码登录

3、启动mysql服务,使用无密码登录到mysql

# service mysql start
# mysql -uroot -p

4、修改数据库登录密码

mysql>  use mysql;    //使用mysql数据库
mysql>  update mysql.user set authentication_string=password(\'新密码\') where user=\'root\';        //修改root用户的密码
mysql>  flush privileges;        //刷新权限
mysql> exit

5、删除配置文件中添加的配置参数

skip-grant-tables    //删除参数
:wq      //保存退出

6、重启数据库

systemctl start  mysqld.service

7、使用新的密码重新登录到数据库OK

分类:

技术点:

相关文章:

  • 2021-06-07
  • 2021-09-21
  • 2021-12-08
  • 2021-09-21
  • 2021-07-25
  • 2021-12-11
  • 2021-09-28
猜你喜欢
  • 2022-12-23
  • 2021-11-14
  • 2022-01-15
  • 2021-10-14
  • 2022-01-15
  • 2021-05-27
  • 2021-11-28
相关资源
相似解决方案