MySQL忘記root密碼的找回方法

2021-09-07 02:58:47 字數 2494 閱讀 3932

(1)登入到資料庫所在伺服器,手工kill掉mysql程序:  

kill ' cat /mysql-data-directory/hostname.pid'

其中,/mysql-data-directory/hostname.pid指的是mysql資料目錄下的.pid檔案,它記錄了mysql服務的程序號。

(2)使用--skip-grant-tables選項重啟mysql服務:

[root@iz28dr6w0qvz mysql]# ./bin/mysqld_safe --skip-grant-tables --user=root &[1] 17299[root@iz28dr6w0qvz mysql]# 151006 13:14:41 mysqld_safe logging to '/alidata/log/mysql/error.log'.

151006 13:14:41 mysqld_safe starting mysqld daemon with databases from /alidata/server/mysql/data

其中--skip-grant-tables選項的意思是啟動mysql服務的時候跳過許可權表認證。啟動後,連線到mysql的root將不需要命令。

(3)用空密碼的root使用者連線到mysq,並且更新root口令:

[root@iz28dr6w0qvz ~]# mysql -uroot

welcome to the mysql monitor. commands end with ; or \g.

your mysql connection id is 4server version: 5.5.37-log mysql community server (gpl)

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> set password = password('ysj123');

error 1290 (hy000): the mysql server is running with the --skip-grant-tables option so it cannot execute this

statement

mysql> update mysql.user set password=password('123456') where user='root' and host='localhost';

query ok, 1 row affected (0.00sec)

rows matched: 1 changed: 1 warnings: 0

此時,由於使用了--skip-grant-tables選項啟動,使用「set password」命令更改密碼失敗,直接更新user表的password欄位後更改密碼成功。

(4)重新整理許可權表,使得許可權認證重新生效:

mysql>flush privileges;

query ok, 0 rows affected (0.00 sec)

(5)重新用root登入時,必須輸入新口令:

[root@iz28dr6w0qvz ~]# mysql -uroot

error 1045 (28000): access denied for user 'root'@'localhost'(using password: no)

[root@iz28dr6w0qvz ~]# mysql -uroot -p

enter password:

welcome to the mysql monitor. commands end with ; or \g.

your mysql connection id is 8server version: 5.5.37-log mysql community server (gpl)

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中,密碼丟失後無法找回,只能通過上述方式修改密碼。

**:

mysql忘記root密碼

1.以系統管理員身份登陸系統。2.開啟cmd net start 檢視mysql是否啟動。啟動的話就停止net stop mysql.3.我的mysql安裝在d usr local mysql4 bin下。4.跳過許可權檢查啟動mysql.d usr local mysql4 bin mysqld ...

mysql忘記root密碼

1.開啟dos視窗,關閉正在執行的mysql net stop mysql。2.開啟dos視窗,轉到mysql bin目錄 cd c program files x86 mysql mysql server 5.1 bin。3.輸入mysqld skip grant tables回車。4.再開乙個新...

mysql忘記root密碼

第一步 執行如下命令,停止mysql服務 net stop mysql 第二步 啟動mysql 進入到mysql的安裝目錄bin,找到mysqld.exe 或mysqld nt.exe 執行 mysqld.exe skip grant tables 或mysqld nt skip grant tab...