1. 程式人生 > >重置mysql密碼

重置mysql密碼

() chan 數據庫 expire 重置 ble 用戶登錄 rest etc

其實想要重置 5.7 的密碼很簡單,就一層窗戶紙:

1、修改 /etc/my.cnf,在 [mysqld] 小節下添加一行:skip-grant-tables=1

這一行配置讓 mysqld 啟動時不對密碼進行驗證

2、重啟 mysqld 服務:systemctl restart mysqld

3、使用 root 用戶登錄到 mysql:mysql -u root

4、切換到mysql數據庫,更新 user 表:

update user set authentication_string = password(‘root‘), password_expired = ‘N‘, password_last_changed = now() where user = ‘root‘;

在之前的版本中,密碼字段的字段名是 password,5.7版本改為了 authentication_string

5、退出 mysql,編輯 /etc/my.cnf 文件,刪除 skip-grant-tables=1 的內容

6、重啟 mysqld 服務,再用新密碼登錄即可

重置mysql密碼