Linux下MySQL8 0版本忘記密碼

2021-09-23 22:27:24 字數 1274 閱讀 4366

具體步驟如下:

1、修改mysql的配置檔案(預設為/etc/my.cnf),在[mysqld]下新增一行

skip-grant-tables
2、儲存配置檔案後,重啟mysql服務

service mysqld restart
3、再次進入mysql命令列

mysql -uroot -p
4.1、輸入密碼時直接回車,就會進入mysql資料庫了,這個時候按照常規流程修改root密碼即可。

mysql5.7和之前的使用者修改密碼方式:

mysql -uroot -e "set password=password(『123』);"
mysql -uroot -p123.com -e "use mysql;update user set authentication_string=password('456') where user='root';"
update mysql.user set authentication_string=password("123") where user='root';
以上三種方法在mysql8.0以後版本中將不能使用,如果使用了將會導致在正確修改密碼是報如下錯誤:

mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123';

error 1396 (hy000): operation alter user failed for 'root'@'localhost'

4.2、如遇上以上問題請使用update語句先清空authentication_string欄位

update user set authentication_string='' where user='root';
再輸入exit退出mysql命令列,再按照步驟1中的流程,刪掉配置檔案中的那行,並且重啟mysql服務,然後再次進入mysql命令列。

alter user 'root'@'localhost' identified with mysql_native_password by '你的密碼';
flush privileges;
然後重啟下mysql伺服器。

試下你的新密碼吧。

Linux下解除安裝MySQL8 0版本

一 關閉mysql root localhost service mysqld stop redirecting to bin systemctl stop mysqld.service 二 檢視當前安裝mysql情況,查詢以前是否裝有mysql root localhost rpm qa grep...

搭建mysql8 0版本

本次採用yum構建mysql8.0資料庫,具體操作步驟如下 wget c 安裝mysql8.0 yum源 rpm ivh mysql80 community release el7 3.noarch.rpm 安裝mysql8.0資料庫 yum install y mysql community se...

Windows下安裝Mysql8 0版本

mysql官網位址 3 在d盤的mysql 8.0.19 winx64資料夾下面新建乙個my.ini檔案和乙個data檔案 4 編輯my.ini檔案的內容 mysqld 設定3306埠 port 3306 設定mysql的安裝目錄 basedir d mysql 8.0.19 winx64 設定my...