下午好,这次我们将讨论如何在CentOS 8上轻松安装MariaDB。对于不熟悉MariaDB的人,我来介绍下:

MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。MariaDB继承了MySQL的所有特点,并且二者之间在许多功能上也是兼容的,同时MariaDB还进行了大量的改进。在存储引擎方面,Maria DB使用XtraDB来代替MySQL的InnoDB。MariaDB基于事务的Maria存储引擎,替换了MySQL的MyISAM存储引擎。

2008年 Sun Microsystems以10亿美元收购MySQL AB这家开发并拥有MySQL数据库的公司。2011年Oracle收购了SUN Microsystems从而将MySQL也一并收归旗下。 虽然Oracle没有中止MySQL项目,但从MySQL项目的后继开发进程来看,MySQL存在巨大的闭源风险。开源社区采用分支的方式避免这种风险,于是创建了MySQL的新分支MariaDB。

如何在CentOS 8上安装MariaDB

安装很简单,仅需要几个步骤,如图所示。首先,使用软件包管理器从官方存储库安装MariaDB软件包,如下所示:

[linuxmi@localhost ~/www.linuxmi.com]$sudo dnf install mariadb

在MariaDB软件包之后,您需要使用以下命令启动该服务,将其激活以在启动时自动启动并查看其状态:

[linuxmi@localhost ~/www.linuxmi.com]$systemctl enable mariadb
[linuxmi@localhost ~/www.linuxmi.com]$systemctl start mariadb
[linuxmi@localhost ~/www.linuxmi.com]$systemctl status mariadb

● mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor pre>
   Active: active (running) since Tue 2020-03-03 00:51:49 EST; 10min ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 1476 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 23831)
   Memory: 95.8M
   CGroup: /system.slice/mariadb.service
           └─1476 /usr/libexec/mysqld --basedir=/usr

303 00:51:44 localhost.localdomain systemd[1]: Starting MariaDB 10.3 databas>

最后,您想通过键入以下命令来保护MariaDB安装:

[linuxmi@localhost ~/www.linuxmi.com]$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] 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:

[linuxmi@localhost ~/www.linuxmi.com]$mysql -u root -p

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 25
Server version: 10.3.17-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)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| linuxmi            |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.000 sec)

MariaDB [(none)]>

注意:本教程在发布之前已经在Linux CentOS 8上进行了测试,并且可以完美运行,因此希望我的朋友在执行上述步骤后不会遇到任何障碍。

祝您好运,希望这篇在CentOS上轻松安装MariaDB的文章对Linux新手有所帮助。

发表评论

电子邮件地址不会被公开。 必填项已用*标注