標籤:
與其說是mysql密碼破解倒不如說是mysql密碼重設更準確,因為大多數情況下我們只是忘了登入的密碼,如果是普通使用者還可以讓管理員重新設定一下密碼或者重新分配一個使用者,但是這裡我們不考慮普通使用者,如果是管理員密碼忘了怎麼辦?找回是不可能了,雖然mysql中user表中記錄了每個使用者的資訊,但是普通使用者一般也沒有許可權操作,而且其中密碼是通過單向加密產生。所以對於管理員密碼遺忘,最簡單的方法就是重設了。
這裡分兩種情況分析linux下和windows下
linux作業系統下:
mysql版本5.5
1.修改MySQL設定檔
vim /etc/my.cnf
找到和mysql伺服器配置相關部分[mysqld],在最後加上skip-grant-tables,如下所示
socket = /tmp/mysql.sock
myisam_sort_buffer_size = 8M
skip-grant-tables //設定mysql伺服器啟動跳過許可權表
儲存並退出
2.重新啟動mysql伺服器
./usr/local/mysql/bin/mysqld_safe
注意這個時候mysql中的許可權表已經失去作用了,為防止來自外部的攻擊,最好斷網操作。
3.登入並修改管理員root使用者的密碼
重新開啟一個終端,如果上一個步驟是放到後台執行,也可以在同一個終端下執行
./usr/local/mysql/bin/mysql 如下所示
[[email protected] bin]# ./mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.23-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
這個時候就可以不需要輸入管理員root的密碼
選擇mysql庫
mysql> use mysql;
修改root密碼
mysql> update user set password=password(‘123456‘) where user=‘root‘ and host=‘127.0.0.1‘;
Query OK, 1 row affected (0.11 sec)
Rows matched: 1 Changed: 1 Warnings: 0
重新整理許可權列表,讓伺服器下次啟動能夠生效
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
4.修改mysql設定檔
vim /etc/my.cnf
將步驟一中在[mysqld]的段中加上的skip-grant-tables刪除 ,
儲存並且退出vi。
5.重新啟動mysql伺服器即可
./usr/local/mysql/bin/mysqld_safe
這時候使用剛才重設的密碼即可登入mysql
windows環境下
1.開啟DOS切換到mysql安裝目錄的bin檔案夾下
2.輸入mysqld --skip-grant-table 斷行符號
注意不要退出
3.再開啟一個DOS視窗切換到mysql安裝的目錄的bin檔案夾下
4.輸入mysql 斷行符號
5.選擇mysql庫,use mysql
6.重新設定root密碼
update user set password=password(‘newpassword‘) where user=‘root‘
7.重新整理許可權表
flush privileges
8.退出兩個終端,重新登入即可
MySQL密碼破解。