Mysql快速找回root密碼妙招
目前B站正在直播Mysql、Oracle實戰,詳情關注公眾號:IT邦德 QQ群:955286955、168797397
一、Mysql root使用者密碼忘記 (8.0以下)
1.用命令編輯/etc/my.cnf配置檔案,即:vim /etc/my.cnf 或者 vi /etc/my.cnf
2.在[mysqld]下新增skip-grant-tables,然後儲存並退出
3.重啟mysql服務:service mysqld restart
4.更改root使用者名稱
重啟以後,執行mysql命令進入mysql命令列

5.修改root使用者密碼
update mysql.user set authentication_string=password('root') where user='root'; --5.7版本
flush privileges;
6.把/etc/my.cnf中的skip-grant-tables註釋掉,然後重啟mysql,即:service mysqld restart
好了,下面就可以用root新的密碼登入了!
二、Mysql root使用者密碼忘記 (8.0及以上)
在mysql8系統下,適用如下方法(全路徑)
G:\mysql-8.0.23-winx64\bin\mysqld --datadir=G:\mysql-8.0.23-winx64\data80323308 --console --skip-grant-tables --shared-memory
然後再開一個視窗,執行下面命令
cd G:\mysql-8.0.23-winx64\bin

mysql> select user,host,authentication_string from mysql.user;
mysql> delete from mysql.user where user='root' ;
mysql> flush privileges; --記得重新整理哈,如果提示無法建立
mysql> create user [email protected]'%' identified with mysql_native_password by 'root';
mysql> grant all on *.* to [email protected]'%' with grant option;
mysql> flush privileges;
mysql> drop user 'root'@'localhost';
mysql> flush privileges;
mysql> create user [email protected]'localhost' identified with mysql_native_password by 'root';
mysql> grant all on *.* to [email protected]'localhost' with grant option;
mysql> flush privileges;
QQ:2243967774,更多資料請關注公眾號:IT 邦德,專注於資料庫及程式開發,掃描加微信
「其他文章」
- 還用寬表?體驗一下DQL成就新一代的BI吧
- 大資料計算,如何優化SQL?
- MySQL高可用之MHA架構企業實戰
- 【牛客刷題-SQL大廠面試真題】NO5.某寶店鋪分析(電商模式)
- 內卷時代,35歲程式猿轉行DBA|2022 年中總結
- MySQL高可用之多源複製
- MySQL8.0新特性搶先看,效能又雙叒提升了
- Oracle表碎片對效能有多大影響?
- 趣味端午節,程式猿特殊的獻禮
- 【微信小程式開發】第1篇:開發工具安裝及程式配置
- CentOS7部署Mysql8.0.27
- MySQL中COLLATE是用來做什麼的?
- PostgreSQL大總結,小白最適合了
- Mysql快速找回root密碼妙招
- Python字典介紹
- Mysql日期型別剖析
- Python元組詳解
- Python列表詳解
- Python字串詳解
- Windows安裝Mysql(msi 圖形安裝)