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

MySQL8.0 雙密碼機制:解決應(yīng)用程序用戶不停機修改密碼問題

數(shù)據(jù)庫 MySQL
MySQL 8.0 的雙密碼機制為數(shù)據(jù)庫管理員提供了一個無縫過渡的方式,使得密碼更新過程可以分階段進(jìn)行,避免了傳統(tǒng)方式中可能造成的停機和連接中斷問題。

在數(shù)據(jù)庫管理中,定期更新密碼是確保系統(tǒng)安全的重要手段。然而,如何在不影響現(xiàn)有連接的情況下平滑地切換密碼,避免系統(tǒng)停機,始終是一個挑戰(zhàn)。MySQL 8.0 引入的“雙密碼”機制為這種需求提供了有效的解決方案,使得密碼更新過程能夠無縫進(jìn)行。

1. MySQL8.0雙密碼特性

自 MySQL 8.0.14 版本起,MySQL 支持為每個用戶賬戶設(shè)置兩個密碼:主密碼(新密碼)和輔助密碼(舊密碼)。這種雙密碼機制能夠在一些復(fù)雜的系統(tǒng)中,特別是當(dāng)涉及大量 MySQL 實例、復(fù)制、多個應(yīng)用程序連接以及頻繁的密碼更新時,保持服務(wù)不中斷,從而實現(xiàn)更流暢的密碼更改流程。

常見使用場景:

  • 系統(tǒng)有多個 MySQL 服務(wù)器,其中一些可能是主從復(fù)制。
  • 不同的應(yīng)用程序連接到不同的 MySQL 服務(wù)器。
  • 系統(tǒng)需要定期更新連接憑據(jù),且不希望中斷現(xiàn)有服務(wù)。

如果不使用雙密碼機制,密碼更改可能需要仔細(xì)協(xié)調(diào)更新過程,以避免在某些服務(wù)器或應(yīng)用程序上造成停機或連接中斷。而通過雙密碼機制,可以在不影響現(xiàn)有連接的情況下分階段完成憑據(jù)更新,從而避免停機。

2. 雙密碼機制的工作流程

(1)為賬戶添加新密碼并保留舊密碼

在更改密碼時,首先通過 RETAIN CURRENT PASSWORD 子句設(shè)置新的主密碼,并保留當(dāng)前密碼作為輔助密碼。此時,客戶端可以繼續(xù)使用舊密碼(輔助密碼)連接數(shù)據(jù)庫,同時新密碼(主密碼)也已經(jīng)生效,主要語法如下:

ALTER USER 'user'@'host'
IDENTIFIED BY 'new_password'
RETAIN CURRENT PASSWORD;

該命令會將 new_password 設(shè)置為主密碼,并將舊密碼保留為輔助密碼。此時,

無論是使用新密碼還是舊密碼的客戶端,都能正常連接到數(shù)據(jù)庫。

案例如下:

# 創(chuàng)建一個用戶并設(shè)定密碼
mysql> create  user  'app_user'@'localhost' identified by  '123456';
Query OK, 0 rows affected (0.03 sec)

mysql> grant select on *.*  to  'app_user'@'localhost';
Query OK, 0 rows affected, 1 warning (0.01 sec)
# 登錄測試密碼
[root@alidb ~]# /usr/local/mysql8.0/bin/mysql  -uapp_user -p'123456'  --socket=/data//mysql/mysql3308/tmp/mysql.sock
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 24090
Server version: 8.0.39 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

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> select user();
+--------------------+
| user()             |
+--------------------+
| app_user@localhost |
+--------------------+
1 row in set (0.00 sec)

原密碼可以正常登錄。

再創(chuàng)建新密碼進(jìn)行驗證。

#創(chuàng)建新密碼
mysql> ALTER USER 'app_user'@'localhost' IDENTIFIED BY 'Test@123456' RETAIN CURRENT PASSWORD;
Query OK, 0 rows affected (0.01 sec)

# 使用新密碼登錄
[root@alidb ~]# /usr/local/mysql8.0/bin/mysql  -uapp_user -p'Test@123456'  --socket=/data//mysql/mysql3308/tmp/mysql.sock
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 24093
Server version: 8.0.39 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

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> select user();
+--------------------+
| user()             |
+--------------------+
| app_user@localhost |
+--------------------+
1 row in set (0.00 sec)

mysql> 
mysql> exit
Bye

# 再次使用原密碼登錄
[root@alidb ~]# /usr/local/mysql8.0/bin/mysql  -uapp_user -p'123456'  --socket=/data//mysql/mysql3308/tmp/mysql.sock
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 24094
Server version: 8.0.39 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

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> select user();
+--------------------+
| user()             |
+--------------------+
| app_user@localhost |
+--------------------+
1 row in set (0.00 sec)

可見,新密碼及原密碼均可以登錄。

(2)廢棄舊密碼

當(dāng)新密碼已經(jīng)在所有服務(wù)器上同步,且所有應(yīng)用程序也更新為使用新密碼時,可以使用 DISCARD OLD PASSWORD 子句來丟棄輔助密碼(原密碼),使得數(shù)據(jù)庫僅接受主密碼(新密碼)。例如:

ALTER USER  'app_user'@'localhost'  DISCARD OLD PASSWORD;

此時,客戶端只能使用主密碼進(jìn)行連接,舊密碼(輔助密碼)將不再有效。

# 新密碼登錄
root@alidb ~]# /usr/local/mysql8.0/bin/mysql  -uapp_user -p'Test@123456'  --socket=/data//mysql/mysql3308/tmp/mysql.sock
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 24099
Server version: 8.0.39 MySQL Community Server - GPL
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
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> select user();
+--------------------+
| user()             |
+--------------------+
| app_user@localhost |
+--------------------+
1 row in set (0.00 sec)
mysql> exit
Bye
#原密碼無法登錄了
[root@alidb ~]# /usr/local/mysql8.0/bin/mysql  -uapp_user -p'123456'  --socket=/data//mysql/mysql3308/tmp/mysql.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'app_user'@'localhost' (using password: YES)

3.小結(jié)

MySQL 8.0 的雙密碼機制為數(shù)據(jù)庫管理員提供了一個無縫過渡的方式,使得密碼更新過程可以分階段進(jìn)行,避免了傳統(tǒng)方式中可能造成的停機和連接中斷問題。通過這種機制,DBA可以在不影響系統(tǒng)可用性的前提下,安全地執(zhí)行密碼更新操作。

責(zé)任編輯:姜華 來源: 數(shù)據(jù)庫干貨鋪
相關(guān)推薦

2010-05-17 13:00:56

MySQL修改用戶密碼

2010-04-07 11:04:52

Oracle用戶密碼

2010-04-08 18:21:56

Oracle用戶密碼

2010-10-29 09:13:33

Oracle用戶密碼

2009-10-23 17:51:51

Oracle用戶密碼

2010-10-22 14:29:53

sqlserver s

2010-05-27 18:06:12

MySQL 修改roo

2010-05-20 11:36:25

MySQL 修改密碼

2022-09-01 09:52:18

應(yīng)用解決方案

2010-07-30 10:24:18

2010-07-27 10:57:27

2021-06-26 08:09:21

MySQL不停機不鎖表

2022-03-03 23:34:19

Windows 11微軟應(yīng)用程序

2010-11-16 16:00:40

Oracle默認(rèn)用戶

2011-07-27 13:48:30

iPhone 安全

2010-05-31 09:10:20

Myeclipse S

2019-08-01 11:31:32

2010-05-18 16:41:25

MySQL 修改

2010-10-14 11:48:20

MySQL賬戶密碼

2010-06-09 17:26:54

點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 亚洲伊人久久综合 | 中文字幕第一页在线 | 色综合久久久久 | 黄色毛片在线播放 | 天堂久久av | 亚洲情综合五月天 | 国产免费国产 | 91在线视频播放 | 日韩一区二区三区视频在线观看 | 日韩精品视频一区二区三区 | 国产99精品| 免费福利视频一区二区三区 | 91亚洲精品久久久电影 | 在线亚州| 日韩羞羞 | 一级大黄色片 | 亚洲www啪成人一区二区麻豆 | 国产在线视频一区二区董小宛性色 | 久久精品久久精品久久精品 | 操网站 | 亚洲精品一区二区三区蜜桃久 | 天天射影院 | 欧美一区二区在线 | 久久一区二区三区免费 | 一区二区久久精品 | 欧美精品网站 | 中文日韩在线视频 | 久久精品视频在线观看 | 精品国产色| 一级毛片在线视频 | 久久久久久久一区二区三区 | 国产精品高潮呻吟久久 | 成人免费一区二区三区视频网站 | 男人天堂网址 | 欧美久久久久久 | 欧美一区2区三区4区公司二百 | 3级毛片 | 天天操天天天干 | 久久专区 | 女同久久另类99精品国产 | 欧美日韩专区 |