溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

mysql5.6密碼忘記了該如何恢復(fù)

發(fā)布時間:2020-06-03 16:50:17 來源:網(wǎng)絡(luò) 閱讀:500 作者:三月 欄目:MySQL數(shù)據(jù)庫

本文主要給大家簡單講講mysql5.6密碼忘記了該如何恢復(fù),相關(guān)專業(yè)術(shù)語大家可以上網(wǎng)查查或者找一些相關(guān)書籍補(bǔ)充一下,這里就不涉獵了,我們就直奔主題吧,希望mysql5.6密碼忘記了該如何恢復(fù)這篇文章可以給大家?guī)硪恍嶋H幫助。

實驗環(huán)境:

    1、centos7.3

    2、mysql5.6.35

實驗描述:

    原mysql僅root賬號可以登錄且有密碼保護(hù),現(xiàn)在密碼已經(jīng)忘記無法找回。今天的目標(biāo)就是通過破解,重置mysql的root密碼。

實驗進(jìn)行時:

    1、開始之前確定mysql不用密碼已經(jīng)不能登錄了

[root@c73 mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@c73 mysql]#
[root@c73 ~]# mysql -u root -p654321 //用654321這個密碼也進(jìn)不了。
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    2、跳過授權(quán)進(jìn)入mysql

[root@c73 mysql]# systemctl stop mysql //停止mysql
//由于我本身使用的是root賬號,mysql運行需要mysql賬號所以,增加了--user=mysql,
//這里主要是使用--skip-grant-tables參數(shù)跳過授權(quán)表
[root@c73 mysql]# mysqld --user=mysql --skip-grant-tables &
[1] 6022
[root@c73 mysql]# 2017-04-11 09:36:41 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-04-11 09:36:41 0 [Note] mysqld (mysqld 5.6.35) starting as process 6022 ...
2017-04-11 09:36:41 6022 [Note] Plugin 'FEDERATED' is disabled.
2017-04-11 09:36:41 6022 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-04-11 09:36:41 6022 [Note] InnoDB: The InnoDB memory heap is disabled
2017-04-11 09:36:41 6022 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-04-11 09:36:41 6022 [Note] InnoDB: Memory barrier is not used
2017-04-11 09:36:41 6022 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-04-11 09:36:41 6022 [Note] InnoDB: Using Linux native AIO
2017-04-11 09:36:41 6022 [Note] InnoDB: Using CPU crc32 instructions
2017-04-11 09:36:41 6022 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-04-11 09:36:41 6022 [Note] InnoDB: Completed initialization of buffer pool
2017-04-11 09:36:41 6022 [Note] InnoDB: Highest supported file format is Barracuda.
2017-04-11 09:36:41 6022 [Note] InnoDB: 128 rollback segment(s) are active.
2017-04-11 09:36:41 6022 [Note] InnoDB: Waiting for purge to start
2017-04-11 09:36:42 6022 [Note] InnoDB: 5.6.35 started; log sequence number 1626007
2017-04-11 09:36:42 6022 [Note] Server hostname (bind-address): '*'; port: 3306
2017-04-11 09:36:42 6022 [Note] IPv6 is available.
2017-04-11 09:36:42 6022 [Note]   - '::' resolves to '::';
2017-04-11 09:36:42 6022 [Note] Server socket created on IP: '::'.
2017-04-11 09:36:42 6022 [Note] mysqld: ready for connections.
Version: '5.6.35'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)

[root@c73 mysql]# netstat -lnpt|grep 3306 //確定服務(wù)開啟成功
tcp6       0      0 :::3306                 :::*                    LISTEN      6022/mysqld         
[root@c73 mysql]# mysql  //無密碼進(jìn)入mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> //成功進(jìn)入^_^

    3、修改root密碼

mysql> set password for 'root'@'localhost' = password('654321');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
// 在--skip-grant-tables模式下,以上修改密碼的方法是行不通了。
// 所以我們直接修改用戶表來更新密碼。
mysql> update mysql.user set password=password("654321") where user='root';
Query OK, 4 rows affected (0.00 sec) #更新成功了4條root用戶的密碼
Rows matched: 4  Changed: 4  Warnings: 0
// 最后別忘了刷新
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit //退出
Bye

    4、這時候我們再來用新密碼測試看看能不能進(jìn)入吧

[root@c73 ~]# ps aux|grep mysql
mysql     6022  0.0 11.6 1038816 452312 pts/0  Sl   09:36   0:00 mysqld --user=mysql --skip-grant-tables
root      6113  0.0  0.0 112664   968 pts/1    R+   10:00   0:00 grep --color=auto mysql
[root@c73 ~]# kill -9 6022 //結(jié)束掉原來的mysql服務(wù)
[root@c73 ~]# systemctl start mysql 以正常模式開啟mysql服務(wù)
[root@c73 ~]# ps aux|grep mysql
mysql     6132  0.0  0.0 113252  1588 ?        Ss   10:00   0:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql     6310  1.8  2.8 698944 110984 ?       Sl   10:00   0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root      6337  0.0  0.0 112664   972 pts/1    R+   10:01   0:00 grep --color=auto mysql
[root@c73 ~]# mysql #測試不用密碼無法進(jìn)入
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@c73 ~]# mysql -u root -p654321 #測試使用新密碼進(jìn)入成功^_^
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>

實驗總結(jié):

    密碼盡可能的保存好吧,如果是線上24小時不間斷的業(yè)務(wù),出現(xiàn)這種情況必須重啟服務(wù)來處理,或多或少都會帶來一些不必要的麻煩。

mysql5.6密碼忘記了該如何恢復(fù)就先給大家講到這里,對于其它相關(guān)問題大家想要了解的可以持續(xù)關(guān)注我們的行業(yè)資訊。我們的板塊內(nèi)容每天都會捕捉一些行業(yè)新聞及專業(yè)知識分享給大家的。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI