ubuntu mysql8 密码忘记

  1. 编辑mysqld.cnf文件
    1. sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
 
  1. 在文件中的skip-external-locking一行的下面添加一行
    1.  skip-grant-tables
 
  1. 重启MySQL服务
    1. sudo service mysql restart
 
 
  1. 终端输入mysql进入MySQL,输入USE mysql切换至mysql数据库
    1.  mysql
    2. USE mysql
 
  1. 把root用户的密码修改为空(8版本以上必须先改成空,好像是因为没有password函数)
    1.  update user set authentication_string=‘’ where user=‘root’;
 
  1. 退出重启mysql
    1.  flush privileges;
    2. exit
    3. 注释掉/etc/mysql/mysql.conf.d/mysqld.cnf文件中添加的一行
    4. sudo service mysql restart
  1. 登陆
    1. mysql -u root
  2. 修改密码
    1. alter user 'root'@'localhost' identified by 'new_password';
  3. 退出
 
posted @ 2019-07-22 12:02  MaxZheng2018  阅读(2303)  评论(0编辑  收藏  举报