可以做網(wǎng)站的域名后綴優(yōu)化疫情防控

在數(shù)據(jù)庫(kù)管理的世界里,隨著技術(shù)的不斷進(jìn)步和業(yè)務(wù)的不斷發(fā)展,數(shù)據(jù)庫(kù)的版本升級(jí)成為了一個(gè)不可避免的過程。
MySQL 作為業(yè)界領(lǐng)先的開源關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng),其版本迭代與功能優(yōu)化同樣不容忽視。
而在這個(gè)過程中,升級(jí)工具就顯得尤為重要,比如 mysql_upgrade
。
但是,mysql_upgrade
已經(jīng)成為過去式,且來往下看。
mysql_upgrade 介紹
mysql_upgrade 是 MySQL 提供的一個(gè)用于升級(jí) MySQL 服務(wù)器的實(shí)用程序。
它檢查服務(wù)器上的所有數(shù)據(jù)庫(kù),查看是否需要任何更改以利用新版本的 MySQL 服務(wù)器提供的特性。
mysql_upgrade 還會(huì)升級(jí)系統(tǒng)表,以使用當(dāng)前 MySQL 版本提供的任何新特性。
簡(jiǎn)而言之,mysql_upgrade 就是一個(gè)幫助用戶平滑過渡到新版本 MySQL 的橋梁。
使用 mysql_upgrade 的過程相對(duì)簡(jiǎn)單。
首先,停止舊版本的 MySQL 服務(wù),建議用戶備份整個(gè)數(shù)據(jù)庫(kù),以防萬一升級(jí)過程中出現(xiàn)問題。
然后,安裝新版本的 MySQL 服務(wù)器軟件,并啟動(dòng)新版本的 MySQL 服務(wù)。
最后,運(yùn)行 mysql_upgrade 命令,它會(huì)檢查數(shù)據(jù)庫(kù)中的表,并根據(jù)需要進(jìn)行升級(jí)。
通常只需向幾個(gè)表添加新字段,或者修改字段長(zhǎng)度,或者補(bǔ)充修訂數(shù)據(jù)。
也可能會(huì)出現(xiàn)罕見的情況,比如系統(tǒng)表的存儲(chǔ)引擎發(fā)生變更,比如由 MyISAM 變更為 InnoDB。
mysql_upgrade 使用示例
舉個(gè)栗子,
從 MySQL 5.7.18 升級(jí)到 MySQL 5.7.19,會(huì)增加一個(gè) 'mysql.session'@'localhost'
保留賬戶。
該帳戶由插件在內(nèi)部使用來訪問服務(wù)器。 它被鎖定,因此不能用于客戶端連接。
具體案例如下:
現(xiàn)在,我們有一個(gè) MySQL 5.7.18 服務(wù)器正在運(yùn)行。
mysql>?select?version();
+-----------+
|?version()?|
+-----------+
|?5.7.18????|
+-----------+
1?row?in?set?(0.00?sec)
查看用戶列表。
mysql>?select?user?from?mysql.user;
+-----------+
|?user??????|
+-----------+
|?mysql.sys?|
|?root??????|
+-----------+
2?rows?in?set?(0.00?sec)
我們來停止舊版本的 MySQL 服務(wù)。
systemctl?stop?mysqld
接下來,準(zhǔn)備升級(jí)到 MySQL 5.7.19,RPM 包已經(jīng)準(zhǔn)備好。
$?ls?m*rpm
mysql-community-client-5.7.19-1.el7.x86_64.rpm
mysql-community-common-5.7.19-1.el7.x86_64.rpm
mysql-community-devel-5.7.19-1.el7.x86_64.rpm
mysql-community-embedded-5.7.19-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.19-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.19-1.el7.x86_64.rpm
mysql-community-libs-5.7.19-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.19-1.el7.x86_64.rpm
mysql-community-server-5.7.19-1.el7.x86_64.rpm
使用 yum 命令進(jìn)行升級(jí)。
yum?update?mysql-community-*
Updated:
??mysql-community-client.x86_64?0:5.7.19-1.el7?????????????????????????????
??mysql-community-common.x86_64?0:5.7.19-1.el7?????????????????????????????
??mysql-community-devel.x86_64?0:5.7.19-1.el7??????????????????????????????
??mysql-community-embedded.x86_64?0:5.7.19-1.el7???????????????????????????
??mysql-community-embedded-compat.x86_64?0:5.7.19-1.el7????????????????????
??mysql-community-embedded-devel.x86_64?0:5.7.19-1.el7?????????????????????
??mysql-community-libs.x86_64?0:5.7.19-1.el7???????????????????????????????
??mysql-community-libs-compat.x86_64?0:5.7.19-1.el7????????????????????????
??mysql-community-server.x86_64?0:5.7.19-1.el7?????????????????????????????
Complete!
安裝完成,啟動(dòng)新版本的 MySQL 服務(wù)。
systemctl?start?mysqld
登陸數(shù)據(jù)庫(kù),查看用戶列表。
mysql>?select?user?from?mysql.user;
+-----------+
|?user??????|
+-----------+
|?mysql.sys?|
|?root??????|
+-----------+
2?rows?in?set?(0.00?sec)
可以看到,mysql.session
用戶尚未被添加到數(shù)據(jù)庫(kù)中。
這里我們開啟 general 日志,來觀察升級(jí)命令都執(zhí)行了哪些 SQL。
mysql>?show?variables?like?'%gen%';
+------------------+-----------------------------+
|?Variable_name????|?Value???????????????????????|
+------------------+-----------------------------+
|?general_log??????|?ON??????????????????????????|
|?general_log_file?|?/var/lib/mysql/shawnyan.log?|
+------------------+-----------------------------+
2?rows?in?set?(0.00?sec)
下一步,運(yùn)行 mysql_upgrade 命令。
mysql_upgrade
[root@shawnyan?~?07:42:50]$?mysql_upgrade?-uroot?-p
Checking?if?update?is?needed.
Checking?server?version.
Running?queries?to?upgrade?MySQL?server.
Checking?system?database.
mysql.columns_priv?????????????????????????????????OK
mysql.db???????????????????????????????????????????OK
mysql.engine_cost??????????????????????????????????OK
mysql.event????????????????????????????????????????OK
mysql.func?????????????????????????????????????????OK
mysql.general_log??????????????????????????????????OK
mysql.gtid_executed????????????????????????????????OK
mysql.help_category????????????????????????????????OK
mysql.help_keyword?????????????????????????????????OK
mysql.help_relation????????????????????????????????OK
mysql.help_topic???????????????????????????????????OK
mysql.innodb_index_stats???????????????????????????OK
mysql.innodb_table_stats???????????????????????????OK
mysql.ndb_binlog_index?????????????????????????????OK
mysql.plugin???????????????????????????????????????OK
mysql.proc?????????????????????????????????????????OK
mysql.procs_priv???????????????????????????????????OK
mysql.proxies_priv?????????????????????????????????OK
mysql.server_cost??????????????????????????????????OK
mysql.servers??????????????????????????????????????OK
mysql.slave_master_info????????????????????????????OK
mysql.slave_relay_log_info?????????????????????????OK
mysql.slave_worker_info????????????????????????????OK
mysql.slow_log?????????????????????????????????????OK
mysql.tables_priv??????????????????????????????????OK
mysql.time_zone????????????????????????????????????OK
mysql.time_zone_leap_second????????????????????????OK
mysql.time_zone_name???????????????????????????????OK
mysql.time_zone_transition?????????????????????????OK
mysql.time_zone_transition_type????????????????????OK
mysql.user?????????????????????????????????????????OK
The?sys?schema?is?already?up?to?date?(version?1.5.1).
Checking?databases.
sys.sys_config?????????????????????????????????????OK
Upgrade?process?completed?successfully.
Checking?if?update?is?needed.
通過 general 日志,可以看到 mysql.session
用戶被寫入用戶表。
[root@shawnyan?~?07:43:42]$?grep?'mysql.session'?/var/lib/mysql/shawnyan.log
2024-03-15T23:43:09.277088Z?????6?Query?SELECT?COUNT(*)?FROM?mysql.user?WHERE?user?=?'mysql.session'
2024-03-15T23:43:10.888664Z?????6?Query?INSERT?IGNORE?INTO?mysql.user?VALUES?('localhost','mysql.session','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0,'mysql_native_password','*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE','N',CURRENT_TIMESTAMP,NULL,'Y')
2024-03-15T23:43:10.889540Z?????6?Query?INSERT?IGNORE?INTO?mysql.tables_priv?VALUES?('localhost',?'mysql',?'mysql.session',?'user',?'root\@localhost',?CURRENT_TIMESTAMP,?'Select',?'')
2024-03-15T23:43:10.890429Z?????6?Query?INSERT?IGNORE?INTO?mysql.db?VALUES?('localhost',?'performance_schema',?'mysql.session','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N')
[root@shawnyan?~?07:44:02]$?
再次登陸數(shù)據(jù)庫(kù),查看用戶列表,確認(rèn)新用戶已經(jīng)添加成功。
mysql>?select?version();
+-----------+
|?version()?|
+-----------+
|?5.7.19????|
+-----------+
1?row?in?set?(0.00?sec)
mysql>?select?user?from?mysql.user;
+---------------+
|?user??????????|
+---------------+
|?mysql.session?|
|?mysql.sys?????|
|?root??????????|
+---------------+
3?rows?in?set?(0.00?sec)
mysql_upgrade 廢棄
不過,從 MySQL 8.0.16 開始, mysql_upgrade 被廢棄,并將從未來的版本中移除。
DBA 不再需要額外地手動(dòng)調(diào)用 mysql_upgrade 來進(jìn)行升級(jí)操作。
取而代之的是,服務(wù)器新增了 --upgrade
選項(xiàng),默認(rèn)值為 AUTO
,
服務(wù)器會(huì)自行判斷是否需要升級(jí),如需要會(huì)在啟動(dòng)時(shí)自動(dòng)執(zhí)行升級(jí)操作。
如果執(zhí)行 mysql_upgrade 命令,會(huì)輸出下面一段信息:
★The mysql_upgrade client is now deprecated. The actions executed by the upgrade client are now done by the server. To upgrade, please start the new MySQL binary with the older data directory. Repairing user tables is done automatically. Restart is not required after upgrade. The upgrade process automatically starts on running a new MySQL binary with an older data directory. To avoid accidental upgrades, please use the --upgrade=NONE option with the MySQL binary. The option --upgrade=FORCE is also provided to run the server upgrade sequence on demand. It may be possible that the server upgrade fails due to a number of reasons. In that case, the upgrade sequence will run again during the next MySQL server start. If the server upgrade fails repeatedly, the server can be started with the --upgrade=MINIMAL option to start the server without executing the upgrade sequence, thus allowing users to manually rectify the problem.
總結(jié)
總的來說,在 MySQL 8.0.16 之前,mysql_upgrade 是一個(gè)功能強(qiáng)大且實(shí)用的工具,它能夠幫助用戶平滑地過渡到新版本的 MySQL。
隨著 MySQL 版本的不斷更新和升級(jí),mysql_upgrade 的功能已經(jīng)內(nèi)嵌到 MySQL 服務(wù)器,其也將伴隨 MySQL 5.7 逐步退出歷史舞臺(tái)。
-- END --

如果這篇文章為你帶來了靈感或啟發(fā),就幫忙點(diǎn)『贊』or『在看』or『轉(zhuǎn)發(fā)』吧,這對(duì)我非常重要,感謝!(??????)
本文由 mdnice 多平臺(tái)發(fā)布