您好,登錄后才能下訂單哦!
本文主要給大家簡單講講mysql5.6密碼忘記了該如何恢復,相關專業術語大家可以上網查查或者找一些相關書籍補充一下,這里就不涉獵了,我們就直奔主題吧,希望mysql5.6密碼忘記了該如何恢復這篇文章可以給大家帶來一些實際幫助。
實驗環境:
1、centos7.3
2、mysql5.6.35
實驗描述:
原mysql僅root賬號可以登錄且有密碼保護,現在密碼已經忘記無法找回。今天的目標就是通過破解,重置mysql的root密碼。
實驗進行時:
1、開始之前確定mysql不用密碼已經不能登錄了
[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這個密碼也進不了。 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、跳過授權進入mysql
[root@c73 mysql]# systemctl stop mysql //停止mysql //由于我本身使用的是root賬號,mysql運行需要mysql賬號所以,增加了--user=mysql, //這里主要是使用--skip-grant-tables參數跳過授權表 [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 //確定服務開啟成功 tcp6 0 0 :::3306 :::* LISTEN 6022/mysqld [root@c73 mysql]# mysql //無密碼進入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> //成功進入^_^
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、這時候我們再來用新密碼測試看看能不能進入吧
[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 //結束掉原來的mysql服務 [root@c73 ~]# systemctl start mysql 以正常模式開啟mysql服務 [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 #測試不用密碼無法進入 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) [root@c73 ~]# mysql -u root -p654321 #測試使用新密碼進入成功^_^ 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>
實驗總結:
密碼盡可能的保存好吧,如果是線上24小時不間斷的業務,出現這種情況必須重啟服務來處理,或多或少都會帶來一些不必要的麻煩。
mysql5.6密碼忘記了該如何恢復就先給大家講到這里,對于其它相關問題大家想要了解的可以持續關注我們的行業資訊。我們的板塊內容每天都會捕捉一些行業新聞及專業知識分享給大家的。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。