如何在Ubuntu 20.04(Focal Fossa)上安装MariaDB Server

时间:2020-02-23 14:32:18  来源:igfitidea点击:

MariaDB是MariaDB基金会开发的功能最强大,使用最广泛的关系数据库管理系统。我们有许多关于在各种Linux发行版上安装MariaDB的文章。本教程将重点介绍在Ubuntu 20.04(Focal Fossa)上安装MariaDB的过程。

对于MariaDB的新手来说,它是社区开发的MySQL数据库系统的分支。它最初被设计为免费和开源的,在速度,稳定性和可扩展性方面没有任何妥协。大多数Linux发行版将在其上游存储库中提供MariaDB,可使用默认的OS软件包管理器进行快速安装。

在Ubuntu 20.04(Focal Fossa)上安装MariaDB Server

我们总是通过确保系统已更新来开始安装。这可以通过运行以下命令来实现:

sudo apt update
sudo apt -y upgrade

系统更新后,使用以下命令在Ubuntu 20.04(Focal Fossa)上安装MariaDB Server。

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 Server

让我们确认我们在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