mysql8.0三 實用技巧

重置密碼

說明:

忘記root的密碼情況下,如何重置密碼,此處以mysql8.0在Ubuntu系統下演示如何重置密碼,其他系統類似;

步驟:

 1. 找到mysql服務的配置文件,此處打開在/etc/mysql/mysql.conf.d目錄下的mysqld.cnf文件,mysqld下增加skip-grant-tables;

(windows下是mysql.ini文件,也可以直接mysqld --console --skip-grant-tables --shared-memory啓動mysql服務)

[mysqld]
skip-grant-tables 

 2. 重啓mysql;

service mysql restart

3. 進入mysql,並將root密碼置爲空;

// 進入mysql,提示輸入密碼直接回車
>> mysql -u root -p
// 將root密碼置空
mysql >> update user set authentication_string='' where user='root';
// 退出mysql
mysql >> exit;

(mysql8.0以前,通過update user set password=password('new_password') where user='root'來設置)

4. 將mysql配置文件中原來增加的skip-grant-tables去掉,即恢復原來配置;

5. 以root進入mysql設置新的密碼;

// 進入mysql,提示輸入密碼直接回車
> mysql -u root -p
// 設置新的密碼
mysql >> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

 6. 驗證,退出重新輸入新密碼進入mysql。

查看配置

mysqld --verbose --help

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章