MySQL破解root用戶密碼
1.先停掉mysql服務
# service mysqld stop
2.跳過授權表啟動mysql服務
# mysqld_safe --skip-grant-tables &
3.更新root密碼
mysql> update mysql.user set password=password('sunxianjiu123') where user='root' and host='localhost';
mysql> flush privileges;
4.退出數據庫,殺死mysql跳過授權登陸方式服務
# ps -ef |grep mysql
- 環境:CentOS 7
- MySQL版本:MySQL 5.7.29
一、停止MySQL進程的運行
service mysqld stop
二、修改配置文件
vim /etc/my.cnf
在[mysqld]下添加兩行:
user=mysql
skip-grant-tables
第一行user=mysql的意思是指定啟動MySQL進程的用戶。第二行是關鍵,skip-grant-tables的意思是跳過密碼驗證。
wq保存退出。
三、啟動MySQL進程
service mysqld start
四、直接登錄MySQL,不接密碼

五、修改密碼
要注意的是,此時直接修改密碼會報錯,如下所示。
錯誤語句:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
看不懂英文就扔谷歌翻譯:

解決辦法是刷新權限,加載原來沒有加載的權限表。
msyql> flush privileges;
skip-grant-tables語句就是繞過了grant授權表,實現免密登錄,而執行flush privileges之后就相當于加載了grant授權表。
另外修改密碼不能直接使用set password='Charramma';命令修改。

報錯說沒有在用戶表中找到匹配的行。
正確的語法應該是下面這樣:
msyql> set password for 'root'@'localhost' = 'Charramma123#';
如下,修改成功。

六、修改MySQL配置文件
就是把之前添加的兩行內容注釋掉或刪除掉。
七、重啟MySQL服務
service mysqld restart
八、使用新密碼登錄

參考:http://www.rzrgm.cn/CharrammaBlog/p/12993735.html?ivk_sa=1024320u
https://blog.csdn.net/qq_17805763/article/details/89518656
1.內容有錯還請在評論區指出哦!謝謝!

浙公網安備 33010602011771號