mysql 5 7 忘記密碼

2021-08-15 18:51:25 字數 785 閱讀 2463

作業系統為centos7 64

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 5.7 在初始安裝後(centos7 作業系統)會生成隨機初始密碼,並在 /var/log/mysqld.log 中有記錄,可以通過 cat 命令檢視,找 password 關鍵字

找到密碼後,在本機以初始密碼登入,並且(也只能)通過 alter user 'root'@'localhost' identified by 'root' 命令,修改 root 使用者的密碼為 root,然後退出,重新以root使用者和剛設定的密碼進行登入即可。

MySQL5 7忘記root密碼

ubuntu下是 etc mysql mysql.conf.d mysqld.cnf window下是mysql目錄下的 my.ini skip grant tables啟動 mysql 服務後,直接使用 root 登陸,不用密碼 alter user root localhost identifi...

Mysql 5 7 忘記密碼或重置密碼

mysql 5.7 mysql庫的user表中已經不再有password欄位,取而代之的為authentication string 修改語法相同,步驟也相同。注意 etc my.cnf這個配置檔案中,basedir datadir這兩個引數的指向,如果指向錯誤,mysqld safe skip g...

mysql5 7忘記密碼時,修改root密碼

1 由於mysql5.7在安裝完後,第一次啟動時,會在root目錄下生產乙個隨機的密碼,檔名為 mysql secret 所以,登入時需要用隨機密碼登入,然後通過以下命令修改密碼 set password password new password 2 在忘記root密碼的時候,以windows為例...