MySQL8 0 忘記密碼 修改密碼

2022-07-02 02:21:12 字數 1382 閱讀 1403

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

alter user 'root'@'localhost' identified by 'newpassword';
1.登入mysql

關閉正在執行的 mysql 服務。開啟 cmd 進入 mysql 的 bin 目錄,可直接找到bin目錄,在位址列輸入cmd

輸入 mysqld --

console --skip-grant-tables --shared-memory 

命令。–skip-grant-tables 會讓 mysql 伺服器跳過驗證步驟,允許所有使用者以匿名的方式,無需做密碼驗證就可以直接登入 mysql 伺服器,並且擁有所有的操作許可權。

上乙個 dos 視窗不要關閉,開啟乙個新的 dos 視窗,此時僅輸入 mysql 命令,不需要使用者名稱和密碼,即可連線到 mysql。

2.修改密碼

因為mysql 5.7.9以後廢棄了password欄位和password()函式;authentication_string:字段表示使用者密碼,而authentication_string欄位下只能是mysql加密後的41位字串密碼。所以需要用一下方式來修改root密碼:

alter

user

'root

'@'localhost

' identified by

'newpassword

';

mysql 從8.0開始修改密碼有了變化,在user表加了字段authentication_string,修改密碼前先檢查authentication_string是否為空,user表在mysql庫中,檢視表之前先換庫,再查表

select host, user, authentication_string from user where user='root';
若authentication_string欄位不為空,則修改該字段為空字串

update user set authentication_string='' where user='root';
然後,

flush privileges; --重新整理許可權

alter user 'root'@'localhost' identified by 'root';--修改密碼為root
若authentication_string欄位為空,則直接重新整理許可權+修改密碼

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使...

MYSQL 8 0 忘記密碼或修改密碼的方法

很早前安裝了mysql,現在由於需要使用mysql但忘記密碼,我在網上搜到凌晨一點,網上大部分的方法都是通過在my.ini或是my default.ini中新增 skip grant tables的方法來實現跳過mysql密碼來連線資料庫,並更改密碼。這些方法對我來說都不適用。最後綜合兩篇部落格,我...