成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

MySQL數據庫密碼忘記了,怎么辦?

數據庫 MySQL
MySQL數據庫密碼忘記了且沒有其他可以修改賬號密碼的賬戶時怎么辦呢?

MySQL數據庫密碼忘記了且沒有其他可以修改賬號密碼的賬戶時怎么辦呢?

登錄MySQL,密碼輸入錯誤

/* 密碼錯誤,報如下錯誤 */
[root@TESTDB ~]# mysql -uroot -p -P3306
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

如果忘記密碼,對于MySQL而言處理起來也相對比較簡單。但需要修改配置,重啟數據庫。可以按照如下步驟處理。

1. 修改數據庫配置文件

vim  /etc/my.cnf
-- 添加如下參數
skip_grant_tables

2. 重啟數據庫

如果部署了服務 可以重啟數據庫服務重啟,如果沒有部署,需要殺掉數據庫進程,在重新啟動數據庫。

/*  重啟數據庫服務 */
/etc/init.d/mysqld restart

ps -ef|grep mysql /* 查出MySQL 的進程號,下一步中使用 */


kill 30516 29246 /* 不建議使用 kill -9 */

3. 登錄數據庫修改密碼

/*  此時可以直接登錄數據庫 無需輸入密碼 */
[root@TESTDB ~]# mysql -uroot -P3306
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.23-24-log Percona Server (GPL), Release 24, Revision 57a9574


Copyright (c) 2009-2018 Percona LLC and/or its affiliates
Copyright (c) 2000, 2018, 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>
再修改密碼
/* MySQL5.7 中修改密碼 */
mysql> update mysql.user set authentication_string=password('123456') where user='root' and host='localhost';
Query OK, 0 rows affected, 1 warning (0.02 sec)
Rows matched: 1 Changed: 0 Warnings: 1


mysql> flush privileges;
Query OK, 0 rows affected (0.06 sec)

注:

a) 不可以使用set password命令修改密碼,只能通過更新數據庫表的方式

mysql> set password=password('123456');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

b) 使用update表mysql.user的方式需要flush privileges生效

c) 不同的版本mysql.user的字段以及密碼加密方式不同,例如MySQL5.6中密碼存儲在password中,MySQL8.0中加密方式有變更等,處理時需要根據版本來相應修改腳本處理。

4 . 將配置文件還原

去掉第1步中my.cnf配置文件中添加的skip_grant_tables參數

vim  /etc/my.cnf
#skip_grant_tables /* 注釋掉該參數*/

5. 重啟數據庫

Mysql5.7中可以直接在MySQL命令行中使用shutdown命令關閉數據庫,之后再啟動數據庫即可。

mysql> shutdown;
Query OK, 0 rows affected (0.00 sec)

啟動后,即可使用重置后的密碼登錄

[root@TESTDB ~]# mysql -uroot    -P3306   -p'123456'
mysql: [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.7.23-24-log Percona Server (GPL), Release 24, Revision 57a9574


Copyright (c) 2009-2018 Percona LLC and/or its affiliates
Copyright (c) 2000, 2018, 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>

至此,密碼重置完畢。

TIPS: 生產環境的數據庫密碼一定要妥善保管,雖然可以找回,但需要重啟,影響數據庫可用性。

責任編輯:華軒 來源: 今日頭條
相關推薦

2010-04-20 08:56:53

2011-07-27 11:19:48

2021-01-30 09:50:54

MySQL密碼服務器

2009-11-30 13:27:21

2025-01-14 00:00:10

Mysql登陸數據庫

2021-01-04 09:40:48

Linux運維Linux系統

2020-10-20 08:01:30

MySQL密碼Windows

2010-06-09 08:39:34

2010-06-07 17:45:06

MySQL數據庫密碼

2009-02-24 09:36:00

路由器密碼恢復CISCO 2600

2013-01-21 09:32:10

2010-05-27 18:24:09

MySQL數據庫密碼

2010-08-18 15:24:14

路由器密碼

2013-07-15 09:51:04

2024-04-22 08:17:23

MySQL誤刪數據

2020-04-28 10:24:55

Wi-FiWindows密碼

2015-03-19 09:15:20

2016-12-15 12:24:03

Oracle數據庫密碼

2021-01-15 13:31:25

加密貨幣密碼比特幣

2020-11-17 06:42:21

MySQL數據庫開源
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产精品a一区二区三区网址 | 亚洲视频在线一区 | 你懂的免费在线 | 国产精品高潮呻吟久久 | 午夜精品久久久 | 我要看免费一级毛片 | 久久国产精品久久国产精品 | 91免费福利视频 | 国产专区在线 | 中文字幕二区 | 麻豆精品国产91久久久久久 | 亚洲情侣视频 | 日韩国产欧美视频 | 91高清视频 | 日韩亚洲视频在线 | 中文字幕色站 | 亚洲国产精品久久久久秋霞不卡 | 欧美黄a| 欧美一区免费 | 女女百合av大片一区二区三区九县 | 亚洲精品国产第一综合99久久 | 亚洲精品久久久蜜桃 | 日韩成人国产 | 国产成人亚洲精品自产在线 | 欧美精品一区二区三区四区五区 | 久久久www成人免费无遮挡大片 | 国产一区二区精品在线 | 国产视频福利在线观看 | 永久免费av | 一区二区三区在线 | 亚洲国产成人在线观看 | 国内自拍视频在线观看 | www.一区二区三区.com | 欧美激情在线一区二区三区 | 久久影院一区 | 91在线免费视频 | 日韩在线视频免费观看 | 香蕉av免费| 国产精品一区一区三区 | 国产日产久久高清欧美一区 | 九九热在线观看 |