mysql 8 0 忘記root密碼 linux

2022-07-17 03:42:11 字數 631 閱讀 2036

1.vim /etc/my.cnf 在[mysqld]最後加上如下語句並儲存退出

2.重啟mysql服務 : service mysqld restart

3.免密碼登陸: mysql -u root -p

password校驗直接回車

select host, user, authentication_string, plugin from user;

use mysql;選擇資料庫

update user set authentication_string='' where user='root'; 設定登陸密碼為空

exit;退出登入,刪除第一步中/etc/my.cnf檔案最後的 skip-grant-tables,再次重啟mysql服務.

root使用者空密碼直接登陸

mysql -u root -p

passwrod:直接回車;

修改密碼,需要設定複雜的密碼(字母,數字,特殊符號組合)後重新登陸,如下:

alter user 'root'@'localhost' identified by 'sql@#123';

mysql 8 0忘記密碼

開啟終端,停止mysql服務。mysql.server stop進入mysql所在目錄 我的是 usr local bin 如果不確定在哪,可以用which mysql命令查詢一下,然後輸入如下命令 cd usr local bin sudo mysqld safe skip grant table...

Mysql8 0忘記密碼

問題背景 在ubuntu18上裝完mysql8後,初始化時沒有給隨機密碼,也無法設定密碼 第一步 修改 etc my.cnf配置檔案,在 mysqld ui後加上如下語句 skip grant tables 第二步免密登入到mysql上,第三步 給root使用者重置秘密 3.1首先檢視當前root使...

MySQL8 0 忘記密碼 修改密碼

mysql 5.7.9以後廢棄了password欄位和password 函式 authentication string 字段表示使用者密碼,而authentication string欄位下只能是mysql加密後的41位字串密碼。所以需要用一下方式來修改root密碼 alter user root...