Ubuntu下mysql 修改root密碼

mysql 修改root密碼

  1. 跳過(guò)驗(yàn)證

     sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
    
    [mysqld]
    #
    # * Basic Settings
    #
    user            = mysql
    pid-file        = /var/run/mysqld/mysqld.pid
    socket          = /var/run/mysqld/mysqld.sock
    port            = 3306
    basedir         = /usr
    datadir         = /var/lib/mysql
    tmpdir          = /tmp
    lc-messages-dir = /usr/share/mysql
    skip-external-locking
    
    skip-grant-tables
    
    

    在 skip-external-locking 添加skip-grant-tables

  2. 重啟mysql服務(wù)

    sudo systemctl restart mysql
    
  1. 設(shè)置root密碼

    # Mysql連接數(shù)據(jù)庫(kù)
    mysql
    # 使用Mysql庫(kù)
    use mysql
    # 查看root用戶是否存在
    select * from user where User='root'\G
    

    設(shè)置密碼

    update  user set  authentication_string=password('admin') , plugin='mysql_native_password'  where user='root';
    flush privileges;
    

    這里認(rèn)證要是用 plugin='mysql_native_password',要不會(huì)使用auth_socket認(rèn)證。(密碼登錄失敗)

  2. 講 /etc/mysql/mysql.conf.d/mysqld.cnf配置的skip-grant-tables注釋掉并重啟mysql服務(wù)

  3. 使用密碼登錄

參考: 解決MySql ERROR 1698 (28000) 錯(cuò)誤:Access denied for user ‘root‘@‘localhost‘

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容