共計 1825 個字符,預計需要花費 5 分鐘才能閱讀完成。
自動寫代碼機器人,免費開通
丸趣 TV 小編給大家分享一下 MySQL 5.7 及 8.0 版本數據庫的 root 密碼遺忘怎么辦,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
注:MySQL5.7 破解 root 密碼,跳過密碼認證登錄到數據庫,直接修改表中的密碼即可,但是 MySQL 8.0 則不可以這樣修改 root 密碼,需要跳過密碼認證登錄到數據庫后,先將 root 密碼設置為空,然后才可以登錄到數據庫,修改 root 密碼。
1、遺忘 MySQL 5.7 數據庫的 root 密碼解決辦法
[root@mysql01 ~]# mysql --version # 確定 MySQL 版本
mysql Ver 14.14 Distrib 5.7.28, for linux-glibc2.12 (x86_64) using EditLine wrapper
[root@mysql01 ~]# vim /etc/my.cnf # 編輯主配置文件
[mysqld] # 在 mysqld 這行下寫入下面內容
skip-grant-tables
.................# 省略部分內容
[root@mysql01 ~]# systemctl restart mysqld # 重啟 MySQL 服務,使配置文件生效
[root@mysql01 ~]# mysql -uroot # 跳過密碼驗證,直接登錄數據庫
#修改 root 密碼為 pwd@123,并刷新權限
mysql use mysql;
mysql update user set authentication_string = passwoord(pwd@123) where user = root
mysql flush privileges; # 刷新權限
mysql exit
#配置密碼驗證,使用新密碼登錄
[root@mysql01 ~]# vim /etc/my.cnf # 編輯主配置文件
[mysqld]
skip-grant-tables # 刪除此行
[root@mysql01 ~]# systemctl restart mysqld # 重啟使更改生效
#使用新密碼即可成功登錄
[root@mysql01 ~]# mysql -uroot -ppwd@123
2、遺忘 MySQL 8.0 數據庫的 root 密碼解決辦法
[root@mysql01 ~]# mysql --version # 查看 MySQL 版本
mysql Ver 8.0.18 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)
[root@mysql01 ~]# vim /etc/my.cnf # 編輯主配置文件
[mysqld] # 在 mysqld 這行下寫入下面內容
skip-grant-tables
.................# 省略部分內容
[root@mysql01 ~]# systemctl restart mysqld # 重啟 MySQL 服務,使配置文件生效
[root@mysql01 ~]# mysql -uroot # 跳過密碼驗證,直接登錄數據庫
#將 root 密碼設置為空
mysql use mysql
mysql update user set authentication_string= where user = root
mysql flush privileges;
mysql exit
#開啟密碼驗證并重新登錄數據庫
[root@mysql01 ~]# vim /etc/my.cnf # 編輯主配置文件
[mysqld]
skip-grant-tables # 刪除此行
[root@mysql01 ~]# systemctl restart mysqld # 重啟使更改生效
[root@mysql01 ~]# mysql -uroot # 直接登錄數據庫
mysql alter user root@localhost identified by pwd@111
mysql flush privileges;
mysql exit
#使用新密碼進行登錄測試
[root@mysql01 ~]# mysql -uroot -ppwd@111
看完了這篇文章,相信你對“MySQL 5.7 及 8.0 版本數據庫的 root 密碼遺忘怎么辦”有了一定的了解,如果想了解更多相關知識,歡迎關注丸趣 TV 行業資訊頻道,感謝各位的閱讀!
向 AI 問一下細節
正文完