如何在 CentOS 7 中升级 MariaDB

玛丽亚数据库 是一个免费的开源数据库管理系统,它取代了专有的 MySQL 数据库管理系统。 许多 新功能和变化 已在每个 MariaDB 版本中添加和改进。 对于 10.8.0 版本,一些新功能包括:

  • 复制中无滞后的 ALTER TABLE。
  • 降序索引。
  • 自动创建分区。

对于那些希望利用新功能的人,本教程将引导您了解如何在 CentOS 7 上升级 MariaDB。

要求

  • 在 Centos 7 中运行的服务器。
  • 运行的不是最新版本的 MariaDB 版本。
  • 对服务器的根访问。

在 CentOS 中升级 MariaDB 7

1: 检查 MariaDB 和 CentOS 版本

使用以下命令检查当前 MariaDB 版本和 CentOS 版本。

mysql -V
cat /etc/centos-release

2 备份数据库

执行升级时,创建现有数据库的备份或转储非常重要。 使用以下命令转储数据库。

mysqldump --all-databases > /tmp/database-backup.sql

或者,使用此命令将数据库目录复制到单独的文件夹中。

cp -a /var/lib/mysql /var/lib/mysql.backup

使用此命令备份配置文件。

cp -a /etc/my.cnf /etc/my.cnf_bk

如果升级失败,您可以使用上述副本之一来恢复您的数据库。

第 3 步:卸载当前的 MariaDB 存储库。

在安装新版本之前,您需要卸载旧的 MariaDB 存储库。 为此,您必须首先使用以下命令停止 MariaDB 服务。

systemctl stop mariadb

使用此命令检查 MariaDB 的当前状态。

systemctl status mariadb

使用以下命令移动当前的 repo 文件。

mv /etc/yum.repos.d/mariadb.repo /etc/yum.repos.d/mariadb_bk

第 4 步:添加新的 MariaDB 存储库

所有软件包都需要是最新的。 使用以下命令更新您的软件包。

yum update

注意:本教程使用 Yum 包管理器。 更新软件包的命令将根据 CentOS 部署中使用的软件包管理器而有所不同。

为最新版本创建一个新的 repo 文件。

vim /etc/yum.repos.d/MariaDB.repo

将以下内容复制并粘贴到 /etc/yum.repos.d/mariadb.repo 文件中。

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

要退出并保存 Vim 文件,输入 :wq 并按 Enter.

第 5 步:卸载旧的 MariaDB 版本

使用以下命令卸载旧版本的 MariaDB。 此命令完全删除旧的 MariaDB 版本并保留数据库。

yum remove mariadb-server

使用此命令清理服务器上的存储库缓存。

yum clean all

第 6 步:在 Centos 7 上安装最新版本的 MariaDB

使用以下命令安装新版本的 MariaDB。

yum install MariaDB-server

要安装最新版本的 MariaDB 和最常用的软件包,请运行以下命令。

yum install MariaDB-server galera-4 MariaDB-client MariaDB-shared MariaDB-backup MariaDB-common

第 7 步:启动 MariaDB

使用此命令启动 MariaDB 服务。

systemctl start mariadb

第 8 步:将 MariaDB 设置为启动时启动

要将 MariaDB 设置为在服务器启动时自动启动,请使用以下命令。

systemctl enable mariadb

第 9 步在 CentOS 上升级 MariaDB 7

运行 upgrade 命令升级 MariaDB。

mysql_upgrade

小号第十步 检查当前 MariaDB 版本

使用此命令检查当前安装的 MariaDB 版本。

mysql -V

MariaDB 已成功升级到最新版本。

第 11 步:保护 MariaDB 数据库服务器

现在最新的 MariaDB 版本已经安装在 CentOS 7 上,通过运行以下命令来保护它。

mysql_secure_installation

按照脚本提示选择要执行的操作。

# 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.

You already have a root password set, so you can safely answer 'n'.

Change the 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] n
 ... skipping.

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
 ... skipping.

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] n
 ... skipping.

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

Reload privilege tables now? [Y/n] n
 ... skipping.

Cleaning up...

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

Thanks for using MariaDB!

总结

本教程将指导您如何在 CentOS 7 中升级 MariaDB。它包括备份、卸载旧版本以及升级后保护 MariaDB 的技巧。 对于数据库托管,MariaDB 是 MySQL 的绝佳替代品。

Liquid Web 协助升级托管 Linux 服务器上的 MariaDB。 我们的专用服务器只是可供选择的选项之一。 联系我们以获得进一步的帮助来配置您的服务器。