如何升級 MariaDB 在 Linux (阿爾瑪Linux)

MariaDB 是一個著名的開源 關係型數據庫。 參與的相同開發人員 MySQL 已創建 MariaDB 並承諾保持開源。 它包含在大多數 雲服務 並且是大多數中的默認值 Linux 變體。 它建立在性能、穩定性和開放性原則的基礎上。 此外, MariaDB 基礎 保證根據技術優點接受貢獻。 您的持續升級 MariaDB 保持最新版本將確保您使用數據庫平台中的最佳功能。

獲取 VPS 託管

很多的 每一個都做出了新的功能和改進 MariaDB 發布。 要接收重要的安全更新並避免與其他應用程序的兼容性問題,您必須升級 MariaDB 到更新的受支持版本。 如果你保留 MariaDB 到目前為止,您將獲得多種好處,例如改進的性能、增強的安全性、新功能等等。

先決條件 之前 MariaDB 升級

  • 操作系統及版本: 操作系統必須是 AlmaLinux操作系統8 對於本教程。
  • 數據庫及版本: A MariaDB 版本 這不是最新的。
  • Linux 管理權限: 要登錄AlmaLinux 8系統,請使用 sudo 以 root 身份執行命令 或作為 具有管理權限的用戶

升級 MariaDB 是AlmaLinux

步驟#1:檢查 MariaDB 和 AlmaLinux 版本

您可以檢查當前版本 MariaDB 和 AlmaLinux,執行以下命令:

  • ~]# mysql -V
  • ~]# cat /etc/redhat-release

這是輸出:

[root@nouf ~]# mysql -V
mysql  Ver 15.1 Distrib 10.5.21-MariaDB, for Linux (x86_64) using readline 5.1
[root@nouf ~]# cat /etc/redhat-release 
AlmaLinux release 8.8 (Sapphire Caracal)

步驟#2:備份數據庫

在執行之前 MariaDB 升級時,創建現有數據庫和數據庫配置文件的備份或轉儲至關重要。

要轉儲數據庫,請使用以下命令:

  • ~]# mysqldump –all-databases > /tmp/all-database-backup.sql

要將數據庫目錄複製到其他文件夾中,請使用以下命令:

  • ~]# cp -a /var/lib/mysql /var/lib/mysql_oldbackup

要備份配置文件,請使用以下命令:

  • ~]# cp -a /etc/my.cnf /etc/my.cnf_oldbackup

請注意,內容 /etc/my.cnf.d/ 如果文件存在也需要備份。 Liquid Web 核心託管 AlmaLinux 8 服務器 包含此文件。

步驟#3:卸載當前的 MariaDB 存儲庫

安裝最新版本之前,請先卸載舊版本 MariaDB 存儲庫。 您可以使用以下命令來停止 MariaDB 服務:

  • ~]# systemctl 停止 mariadb

確認 MariaDB的當前狀態,使用以下命令:

  • ~]# systemctl 狀態 mariadb

要重命名或移動當前存儲庫文件,請使用以下命令:

  • ~]# mv /etc/yum.repos.d/mariadb.repo /etc/yum.repos.d/mariadb.repo_oldbackup

步驟#4:添加新的 MariaDB 存儲庫(“回購”)

在創建新的之前 MariaDB 存儲庫,您必須更新所有包。 您可以使用以下命令來更新所有軟件包:

  • ~]# sudo dnf更新-y

您現在可以為最新版本創建一個新的存儲庫文件 MariaDB 版本:

  • ~]# vi /etc/yum.repos.d/mariadb.repo

然後,將以下詳細信息添加到 /etc/yum.repos.d/mariadb.repo 文件並保存文件:

[mariadb]
name = MariaDB
baseurl = https://yum.mariadb.org/10.5/rhel8-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

步驟#5:卸載舊的 MariaDB 版本

您可以卸載舊版本 MariaDB 使用以下命令:

  • ~]# sudo dnf 刪除 MariaDB-服務器-y

要清理服務器上的存儲庫緩存,請使用以下命令:

  • ~]# sudo dnf 清理全部

步驟#6:安裝最新版本 MariaDB 版本

現在,您已準備好升級 MariaDB。 要安裝最新的 MariaDB 版本,使用以下命令:

  • ~]# sudo dnf安裝 MariaDB-服務器-y

這是輸出:

[root@nouf ~]# sudo dnf install MariaDB-server -y
AlmaLinux 8 - BaseOS                                                                                                                     6.0 MB/s | 4.0 MB     00:00    
AlmaLinux 8 - AppStream                                                                                                                   16 MB/s |  11 MB     00:00    
AlmaLinux 8 - Extras                                                                                                                      32 kB/s |  18 kB     00:00    
MariaDB                                                                                                                                  1.0 MB/s | 620 kB     00:00    
Dependencies resolved.
=========================================================================================================================================================================
 Package                                          Architecture                      Version                                   Repository                            Size
=========================================================================================================================================================================
Installing:
 MariaDB-server                                   x86_64                            10.10.5-1.el8                             mariadb                               27 M

—-
—-

Installed:
  MariaDB-server-10.10.5-1.el8.x86_64  boost-program-options-1.66.0-13.el8.x86_64  galera-4-26.4.14-1.el8.x86_64  libpmem-1.6.1-1.el8.x86_64  lsof-4.93.2-1.el8.x86_64 
  socat-1.7.4.1-1.el8.x86_64          

Complete!

安裝最常用的 MariaDB 包,作為整體的一部分 MariaDB 升級,使用以下命令:

  • ~]# sudo dnf 安裝galley-4 MariaDB-客戶 MariaDB-共享 MariaDB-備份 MariaDB-常見-y

步驟#7:開始 MariaDB

要開始 MariaDB 服務,使用以下命令:

  • ~]# sudo systemctl 啟動 mariadb

步驟#8:設置 MariaDB 在引導時啟動

設置 MariaDB 要在引導時啟動,請使用以下命令:

  • ~]# sudo systemctl 啟用 mariadb

這是輸出:

[root@nouf ~]# sudo systemctl enable mariadb 
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.

步驟#9:升級 MariaDB

升級 MariaDB,使用以下命令:

  • ~]# mysql_upgrade

這是輸出:

[root@nouf ~]# mysql_upgrade 
Major version upgrade detected from 10.5.21-MariaDB to 10.10.5-MariaDB. Check required!
Phase 1/7: Checking and upgrading mysql database
Processing databases
mysql
mysql.column_stats                                 OK
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.event                                        OK
mysql.func                                         OK
mysql.gtid_slave_pos                               OK
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.host                                         OK
mysql.index_stats                                  OK
mysql.innodb_index_stats                           OK
mysql.innodb_table_stats                           OK
mysql.plugin                                       OK
mysql.proc                                         OK
mysql.procs_priv                                   OK
mysql.proxies_priv                                 OK
mysql.roles_mapping                                OK
mysql.servers                                      OK
mysql.table_stats                                  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.transaction_registry                         OK
mysql.user                                         OK
Phase 2/7: Installing used storage engines... Skipped
Phase 3/7: Fixing views
Phase 4/7: Running 'mysql_fix_privilege_tables'
Phase 5/7: Fixing table and database names
Phase 6/7: Checking and upgrading tables
Processing databases
information_schema
performance_schema
Phase 7/7: Running 'FLUSH PRIVILEGES'
OK

步驟#10:檢查電流 MariaDB 版本

使用以下命令檢查並驗證當前安裝的 MariaDB 版本:

  • ~]# mysql -V

這是輸出:

[root@nouf ~]# mysql -V
mysql  Ver 15.1 Distrib 10.10.5-MariaDB, for Linux (x86_64) using readline 5.1
[root@nouf ~]# 

恭喜您成功完成 MariaDB 升級!

確保 MariaDB 數據庫

最新版本 MariaDB 已在 AlmaLinux 8 上設置。您現在可以 確保 MariaDB 數據庫 使用以下命令:

  • ~]# sudo mysql_安全_安裝

這是輸出:

[root@nouf ~]# sudo mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

如果您想從 MySQL 到 MariaDB,了解更多關於 之間的主要區別 MySQL 和 MariaDB 在我們的 知識庫博客在線資源。 一旦你跑步 MariaDB,你需要執行 MariaDB 不時升級,以便從新功能中受益。

結論

您現在應該了解如何升級 MariaDB 在AlmaLinux上。 如何進行備份、卸載以前的版本並確保安全 MariaDB 升級後也被覆蓋了。 MariaDB 是一個很好的替代品 MySQL 用於數據庫託管。

查看所有產品

液體網 可以幫助你升級 MariaDB 在託管上 Linux 服務器。 我們的 專用服務器 只是幾種選擇之一。 如果您需要進一步幫助配置您的網絡託管配置和服務器,請隨時與我們聯繫。

與我們聊天