如何在Ubuntu 20.04(Focal Fossa)上安装MariaDB服务器

MariaDB是由MariaDB基金会开发的功能最强大,使用最广泛的关系数据库管理系统。关于在各种Linux发行版上安装MariaDB的文章很多。本指南重点介绍在Ubuntu 20.04 Focal Fossa上安装MariaDB。

如果您不熟悉MariaDB,那么它是社区开发的MySQL数据库系统的分支。主要设计为免费的开放源代码,而不会影响速度,稳定性或可伸缩性。 MariaDB是大多数Linux发行版的上游存储库,可以使用默认的OS软件包管理器快速安装。

在Ubuntu 20.04(Focal Fossa)上安装MariaDB服务器

确保系统已更新,并始终开始安装。这可以通过运行以下命令来实现:

sudo apt update
sudo apt -y upgrade

更新系统后,使用以下命令在Ubuntu 20.04(Focal Fossa)上安装MariaDB服务器:

sudo apt install software-properties-common mariadb-server mariadb-client

验证服务已启动。

$ systemctl status mariadb
● mariadb.service - MariaDB 10.3.19 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2019-12-23 18:31:46 UTC; 46s ago
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 2144 (mysqld)
     Status: "Taking your SQL requests now..."
      Tasks: 31 (limit: 614)
     Memory: 65.8M
     CGroup: /system.slice/mariadb.service
             └─2144 /usr/sbin/mysqld

Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: Running 'mysqlcheck' with connection arguments: --socket='/var/run/mysqld/mysqld.sock' --host='>
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: # Connecting to localhost...
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: # Disconnecting from localhost...
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: Processing databases
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: information_schema
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: performance_schema
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2182]: OK
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2244]: Checking for insecure root accounts.
Dec 23 18:31:46 ubuntu20 /etc/mysql/debian-start[2248]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables

默认情况下,您应该能够以root用户身份访问mysql命令行,而无需提示输入密码。加固MariaDB服务器并设置root密码。

$ 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!

验证Ubuntu 20.04(Focal Fossa)上的MariaDB服务器安装

检查Ubuntu 20.04上的MariaDB服务器安装

$ mysql -V
mysql  Ver 15.1 Distrib 10.3.19-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

创建一个测试数据库。

MariaDB [(none)]> CREATE DATABASE testdb;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> DROP  DATABASE testdb;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> QUIT
Bye

在Ubuntu 20.04 Focal Fossa Linux上享受MariaDB数据库服务器。对于其他系统,请检查以下内容:

在Fedora上安装MariaDB

如何在Debian 10(Buster)上安装MariaDB

如何在CentOS 7上安装MariaDB

如何在CentOS 8 / RHEL 8上安装MariaDB

Sidebar