一臺測試服務(wù)器,很久沒有登錄使用,忘記了MySQL得root密碼,經(jīng)過搜索引擎一番查找,發(fā)現(xiàn)需要進行如下步驟做root密碼重置
1、修改 /etc/my.cnf,在 [mysqld] 小節(jié)下添加一行:skip-grant-tables=1這一行配置讓 mysqld 啟動時不對密碼進行驗證2、重啟 mysqld 服務(wù):systemctl restart mysql.server3、新開一個終端,使用 root 用戶登錄到 mysql:mysql -u root4、切換到mysql數(shù)據(jù)庫,更新 user 表:use mysql;update user set authentication_string = password(‘newrootpassword’), password_expired = ‘N’, password_last_changed = now where user = ‘root’;
在之前的版本中,密碼字段的字段名是 password,5.7版本改為了 authentication_string
5、退出 mysql,編輯 /etc/my.cnf 文件,刪除前面添加得 skip-grant-tables=1 這一行內(nèi)容6、重啟 mysqld 服務(wù),systemctl restart mysql.server7. 再用新密碼登錄即可






