配置 MariaDB

默认情况下,安装后 MariaDB 将不会运行,也不会在启动时启动,如下所示。

[jack@onitroad ~]# systemctl is-active mariadb
unknown
[jack@onitroad ~]# systemctl is-enabled mariadb
disabled

使用“systemctl enable”和“systemctl start”,我们可以将 MariaDB 配置为在启动时启动,并立即启动服务。

[jack@onitroad ~]# systemctl enable mariadb
ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'
[jack@onitroad ~]# systemctl start mariadb

要确认我们已启用 MariaDB 并且服务正在运行,请执行这些检查。

[jack@onitroad ~]# systemctl is-enabled mariadb
enabled
[jack@onitroad ~]# systemctl is-active mariadb
active

有关使用 systemctl 进行基本服务管理的更多信息,请参阅本教程。

现在 MariaDB 正在运行,我们可以通过简单地运行“mysql”来访问命令行,因为还没有任何密码,为了保证服务安全,使用“mysql_secure_installation”命令设置 root 密码很重要,如下所示。

[jack@onitroad ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
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: NewPasswordHere
Re-enter new password: NewPasswordHere
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 -u root -p”访问命令行,此时将提示我们输入刚刚设置的 root 密码。

可以在 /etc/my.cnf 文件中定义其他配置更改。

安装 MariaDB

MariaDB 在默认的 RHEL/CentOS 存储库中可用,但与这些操作系统的传统一样,此处提供的软件包不会是最新版本。
例如在 2014 年 8 月撰写本文时,CentOS 7 将提供 2014 年 12 月发布的 MariaDB 5.5.41.
MariaDB 存储库提供最新版本,目前 5.5.45 发布于 2014 年 8 月。
我们可以选择在此处为最新版本的 MariaDB 生成存储库配置,并从 MariaDB 存储库安装。

MariaDB 只需使用 'yum' 安装,如下所示。
建议这样做而不是从源代码编译或者使用 RPM 文件,因为将来 MariaDB 将更容易通过“yum update”通过包管理器进行更新。

yum install mariadb mariadb-server -y

现在应该安装 MariaDB,我们可以确认安装的软件包版本如下所示。

[jack@onitroad ~]# mysql -V
mysql  Ver 15.1 Distrib 5.5.45-MariaDB, for Linux (x86_64) using readline 5.1
如何安装和配置 MariaDB

MariaDB 是 MySQL 的替代品,是 MySQL 的开源分支,由原始 MySQL 开发人员创建。
从 Red Hat Enterprise Linux (RHEL7) 和 CentOS 7 开始,MariaDB 现在是默认的 SQL 数据库,而不是以前操作系统版本中的默认值 MySQL。

在这里,我们将介绍如何安装和配置 MariaDB。

日期:2020-07-07 20:55:04 来源:oir作者:oir