如何在 Ubuntu 20.04 將 MariaDB 10.3 升級到 MariaDB 10.5

如何在 Ubuntu 20.04 將 MariaDB 10.3 升級到 MariaDB 10.5

由於想把 Zabbix 5.0 LTS 升級到 6.0 LTS,但是 Zabbix 6.0 LTS 要求 MariaDB版本最好為 10.5,所以我們先來進行資料庫升級。

數據備份

最好在升級之前執行備份,如果在升級過程中遇到問題,您可以使用備份將 MariaDB Server 數據庫恢復到舊版本。確認升級完成沒有問題,再將備份刪除。

administrator@zabbix:~$ sudo apt-get install mariadb-backup
administrator@zabbix:~$ sudo mariadb-backup --backup \
--user=mariabackup_user \
--password=mariabackup_passwd \
--target-dir=/data/backup/preupgrade_backup
administrator@zabbix:~$ ll /data//backup/preupgrade_backup/
total 81528
drwxr-xr-x 5 root root 4096 Aug 10 13:57 ./
drwxr-xr-x 3 root root 4096 Aug 10 13:48 ../
-rw-r----- 1 root root 729088 Aug 10 13:57 aria_log.00000001
-rw-r----- 1 root root 52 Aug 10 13:57 aria_log_control
-rw-r----- 1 root root 324 Aug 10 13:57 backup-my.cnf
-rw-r----- 1 root root 16857 Aug 10 13:57 ib_buffer_pool
-rw-r----- 1 root root 79691776 Aug 10 13:50 ibdata1
-rw-r----- 1 root root 2976768 Aug 10 13:57 ib_logfile0
drwx------ 2 root root 4096 Aug 10 13:57 mysql/
drwx------ 2 root root 4096 Aug 10 13:57 performance_schema/
-rw-r----- 1 root root 87 Aug 10 13:57 xtrabackup_checkpoints
-rw-r----- 1 root root 470 Aug 10 13:57 xtrabackup_info
drwx------ 2 root root 28672 Aug 10 13:57 zabbix/

卸載舊版本

升級到 MariaDB Server 的新主要版本時,必須先刪除現有的安裝,然後再安裝新的版本。否則,套件管理器將拒絕安裝新版本的 MariaDB Server。

在卸載舊版本之前,我們首先需要停止當前的 MariaDB Server

  • 將 innodb_fast_shutdown 系統變量設置 1 為:
  • 使用 XA RECOVER 確認沒有處於準備狀態的外部 XA 事務
administrator@zabbix:~$ sudo mysql
MariaDB [(none)]> SET GLOBAL innodb_fast_shutdown = 1;
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> XA RECOVER;
Empty set (0.000 sec)
MariaDB [(none)]> quit
Bye
administrator@zabbix:~$ sudo systemctl stop mariadb

卸載 MariaDB Server 與相依套件

administrator@zabbix:~$ sudo apt remove "mariadb-*"
...
Setting up zabbix-server-mysql (1:5.0.26-1+focal) ...
Configuration file '/etc/zabbix/zabbix_server.conf'
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** zabbix_server.conf (Y/I/N/O/D/Z) [default=N] ? N
Installing new version of config file /etc/zabbix/zabbix_server.conf ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for systemd (245.4-4ubuntu3.15) ...
administrator@zabbix:~$

卸載 Galera 套件

administrator@zabbix:~$ sudo apt remove galera-3

在繼續之前,請確認所有 MariaDB Server 套件都已卸載。以下命令不應返回任何結果:

administrator@zabbix:~$ apt list --installed | grep -i -E "mariadb|galera"

安裝新版本

安裝 MariaDB Server 與相依套件

administrator@zabbix:~$ sudo apt install software-properties-common
administrator@zabbix:~$ sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
administrator@zabbix:~$ sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.5/ubuntu focal main'
administrator@zabbix:~$ sudo apt update
administrator@zabbix:~$ sudo apt install mariadb-server-10.5
...
Configuration file '/etc/mysql/mariadb.conf.d/50-server.cnf'
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** 50-server.cnf (Y/I/N/O/D/Z) [default=N] ? N
Processing triggers for systemd (245.4-4ubuntu3.15) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.7) ...
administrator@zabbix:~$

升級數據目錄

MariaDB Server 10.5 附帶 mariadb-upgrade 實用程序,可用於識別和糾正新版本中的兼容性問題。升級服務器並啟動服務器進程後,運行此實用程序來升級數據目錄:

administrator@zabbix:~$ sudo mariadb-upgrade
This installation of MariaDB is already upgraded to 10.5.16-MariaDB.
There is no need to run mysql_upgrade again for 10.5.16-MariaDB.
You can use --force if you still want to run mysql_upgrade
administrator@zabbix:~$

驗證升級

通過調用 VERSION() 函數來驗證服務器版本

administrator@zabbix:~$ sudo mysql
MariaDB [(none)]> SELECT VERSION();
+---------------------------------------+
| VERSION() |
+---------------------------------------+
| 10.5.16-MariaDB-1:10.5.16+maria~focal |
+---------------------------------------+
1 row in set (0.000 sec)
MariaDB [(none)]>

评论

此博客中的热门博文

使用 OpenWrt 23.05.5 官网源码编译固件 创建日期:2023/04/05 修改日期:2024/10/27

OpenWrt作为旁路由配置Wireguard 实现内网穿透

yt-dlp详细使用教程参考,其中下载播放列表有效