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. 退出
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM