mysql 8.0+忘记root密码-linux

1.vim /etc/my.cnf 在[mysqld]最后加上如下语句并保存退出

2.重启mysql服务 : service mysqld restart

3.免密码登陆: mysql -u root -p
password校验直接回车

  1. select host, user, authentication_string, plugin from user;
    use mysql;选择数据库
    update user set authentication_string='' where user='root'; 设置登陆密码为空

  2. exit;退出登录,删除第一步中/etc/my.cnf文件最后的 skip-grant-tables,再次重启mysql服务.

  3. root用户空密码直接登陆
    mysql -u root -p
    passwrod:直接回车;

  4. 修改密码,需要设置复杂的密码(字母,数字,特殊符号组合)后重新登陆,如下:
    ALTER user 'root'@'localhost' IDENTIFIED BY 'Sql@#123';

posted @ 2020-06-16 21:52  mintsd  阅读(2475)  评论(0编辑  收藏  举报