欢迎光临散文网 会员登陆 & 注册

Mysql8 重置密码(平台 CentOS7)

2021-03-22 23:56 作者:祝三枝  | 我要投稿

1  在配置文件关闭密码登陆

      找到mysql配置文件: my.cnf

      进入修改: vim /etc/my.cnf

      末尾添加:skip-grant-tables 保存退出

      重启mysql服务: systemctl restart mysqld


2  mysql 原密码置空

      登陆mysql:   mysql -u root; 

      选择数据库:  use mysql; 

      密码置空:  update user set authentication_string = ''  where user = 'root';  

      退出:quit;


3 配置文件重新开启密码登陆

      找到mysql配置文件: my.cnf

      删除步骤1添加的 skip-grant-tables 保存退出

      重启服务: systemctl restart mysqld


4 进入mysql修改密码

      登陆mysql:  mysql -u root; # 密码为空 直接回车

      修改密码:ALTER USER 'root'@'localhost' IDENTIFIED BY  'yourpassword' ;


5 密码登陆:mysql -u root -p;



Mysql8 重置密码(平台 CentOS7)的评论 (共 条)

分享到微博请遵守国家法律