1. 前言
本文主要是为帮助您在RHEL8或CentOS8上安装MariaDB而编写的。讲解如何在CentOS8或RHEL8上安装MariaDB数据库服务器。CentOS8是与MariaDB 10.3一起发布的,它与MySQL是二进制兼容的。MariaDB 10.3是一个多用户、多线程的SQL数据库服务器。你可以在我之前的文章Red Hat Enterprise Linux 8 (RHEL 8)的新特性和评论中找到所有的RHEL8新特性
MariaDB是一个社区开发的MySQL关系型数据库管理系统的分支。它是一个快速和健壮的数据库服务器,在它的开发和改进背后有一个巨大的社区。
2. RHEL8 上的 MariaDB 10.3版本 vs RHEL7系统上的5.5版本
MariaDB 10.3在RHEL 8中提供了比在RHEL 7中提供的5.5更多的新特性。一些新的变化是:
- InnoDB被用作默认的存储引擎,而不是XtraDB。
- System-versioned表
- FOR循环
- MariaDB Galera集群是一个同步多主集群,现在是MariaDB的标准部分。
- 序列
- 即时添加列InnoDB
- 看不见的列
- 并行复制
- 多源复制
- 公共表表达式
- 独立于存储引擎的列压缩
3. 在CentOS8或RHEL8上安装MariaDB 10.3
按照以下步骤在RHEL8或CentOS8上安装和配置MariaDB 10.3。
3.1 步骤1: 升级你的RHEL 8系统
sudo dnf -y update
3.2 步骤2: 在CentOS8或RHEL8上安装MariaDB数据库服务器
mariadb
包在AppStream
存储库中可用,可以通过运行以下命令来安装:
sudo dnf module install mariadb
按下y确认安装
Transaction Summary
=======================================================================================================================================================
Install 13 Packages
Total download size: 32 M
Installed size: 164 M
Is this ok [y/N]: y
检查MariaDB
的安装情况
rpm -qi mariadb-server
Name : mariadb-server
Epoch : 3
Version : 10.3.10
Release : 2.el8+2039+dffd8723
Architecture: x86_64
Install Date: Sat 01 Dec 2018 04:31:39 AM EST
Group : Unspecified
Size : 87570890
License : GPLv2 with exceptions and LGPLv2 and BSD.
Signature : RSA/SHA256, Mon 15 Oct 2018 05:22:06 AM EDT, Key ID 199e2f91fd431d51
Source RPM : mariadb-10.3.10-2.el8+2039+dffd8723.src.rpm
Build Date : Fri 12 Oct 2018 09:48:53 AM EDT
Build Host : x86-vm-05.build.eng.bos.redhat.com
Relocations : (not relocatable)
Packager : Red Hat, Inc. http://bugzilla.redhat.com/bugzilla
Vendor : Red Hat, Inc.
URL : http://mariadb.org
Summary : The MariaDB server and related files
Description :
MariaDB is a multi-user, multi-threaded SQL database server. It is a
client/server implementation consisting of a server daemon (mysqld)
and many different client programs and libraries. This package contains
the MariaDB server and some accompanying files and directories.
MariaDB is a community developed branch of MySQL.
3.3 步骤3: 在CentOS8或者RHEL 8上启动和配置MariaDB
使用下面的命令激活mariadb服务,即设置开机自启动:
sudo systemctl enable --now mariadb
服务启动后,运行命令mysql_secure_installation
来加强MariaDB数据库服务器的安全性。
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!
以上操作确保你:
- 设置数据库root用户密码
- 删除匿名用户
- 不允许root用户远程登录
- 删除测试数据库并访问它
完成后,使用root用户测试访问
mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.10-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
MariaDB [(none)]> SELECT VERSION();
+—————–+
| VERSION() |
+—————–+
| 10.3.10-MariaDB |
+—————–+
1 row in set (0.001 sec)
4. 总结
通过本教程,您现在可以在CentOS8或RHEL8上安装MariaDB数据库服务器了。如果您更喜欢通过web界面管理MariaDB数据库服务器,请参阅我们的指南,了解如何在RHEL 8上安装和配置phpMyAdmin。
评论前必须登录!
注册