0
点赞
收藏
分享

微信扫一扫

Linux下Mysql忘记密码,如何进行修改

木匠0819 2022-02-18 阅读 177

假如Mysql忘记密码,或者在初次安装Mysql时忘记密码,如何修改密码呢,这时就需要用到mysql的参数配置 skip-grant-tables。

  1. 修改my.cnf
    加上参数 skip-grant-tables
    在这里插入图片描述
  2. 重启mysql服务
  3. 输入命令行登录
mysql -uroot -p

不用输入密码,直接回车即可登录

  1. 进行密码修改
sql>alter user 'root'@'localhost' identified by 'root123';
sql>grant all privileges on *.* to'root'@'%' identified by 'root123';

sql>flush privileges;

sql>exit
  1. 重新回到第一步把skip-grant-tables去除,重启mysql服务,用新密码登录即可
  2. 常见问题
  • 执行修改密码出错
    执行语句:alter user ‘root’@‘localhost’ identified by ‘root123’
    错误信息:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
    解决方案:
sql>flush privileges;

再重新往下执行即可

举报

相关推荐

0 条评论