您的位置:首页 > 数据库 > MariaDB

如何在Ubuntu 20.04上安装MariaDB [快速入门]

2020-08-13 15:05 1306 查看

A previous version of this tutorial was written by Brian Boucheron

本教程的先前版本由Brian Boucheron撰写

介绍 (Introduction)

MariaDB is an open-source relational database management system, commonly used as an alternative for MySQL as the database portion of the popular LAMP (Linux, Apache, MySQL, PHP/Python/Perl) stack. It is intended to be a drop-in replacement for MySQL.

MariaDB是一个开放源代码的关系数据库管理系统,通常用作MySQL的替代方案,作为流行的LAMP (Linux,Apache,MySQL,PHP / Python / Perl)堆栈的数据库部分。 它旨在替代MySQL。

This quickstart tutorial describes how to install MariaDB on an Ubuntu 20.04 server and set it up with a safe initial configuration. It will also cover how to set up an additional administrative account for password access.

本快速入门教程介绍了如何在Ubuntu 20.04服务器上安装MariaDB并使用安全的初始配置进行设置。 它还将介绍如何设置其他管理帐户来访问密码。

先决条件 (Prerequisites)

To follow this tutorial, you will need a server running Ubuntu 20.04. This server should have a non-root administrative user and a firewall configured with UFW. Set this up by following our initial server setup guide for Ubuntu 20.04.

要遵循本教程,您将需要运行Ubuntu 20.04的服务器。 该服务器应具有非root用户,并且应使用UFW配置防火墙。 请遵循我们针对Ubuntu 20.04的初始服务器设置指南进行设置

第1步-安装MariaDB (Step 1 — Installing MariaDB)

Before you install MariaDB, update the package index on your server with

apt
:

在安装MariaDB之前,请使用

apt
更新服务器上的软件包索引:

  • sudo apt update

    sudo apt更新

Then install the package:

然后安装软件包:

  • sudo apt install mariadb-server

    sudo apt安装mariadb-server

When installed from the default repositories, MariaDB will start running automatically. To test this, check its status.

从默认存储库安装后,MariaDB将自动开始运行。 要对此进行测试,请检查其状态。

  • sudo systemctl status mariadb

    sudo systemctl状态mariadb

You’ll receive output that is similar to the following:

您将收到类似于以下内容的输出:

Output● mariadb.service - MariaDB 10.3.22 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-05-12 13:38:18 UTC; 3min 55s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 25914 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 31 (limit: 2345)
Memory: 65.6M
CGroup: /system.slice/mariadb.service
└─25914 /usr/sbin/mysqld
. . .

If MariaDB isn’t running, you can start it with the command

sudo systemctl start mariadb
.

如果MariaDB未运行,则可以使用命令

sudo systemctl start mariadb
启动它。

第2步-配置MariaDB (Step 2 — Configuring MariaDB)

Run the security script that came installed with MariaDB. This will take you through a series of prompts where you can make some changes to your MariaDB installation’s security options:

运行随MariaDB一起安装的安全脚本。 这将引导您完成一系列提示,您可以在其中对MariaDB安装的安全性选项进行一些更改:

  • sudo mysql_secure_installation

    须藤mysql_secure_installation

The first prompt will ask you to enter the current database root password. Since you have not set one up yet, press

ENTER
to indicate “none”.

第一个提示将要求您输入当前的数据库密码。 由于尚未设置,请按

ENTER
表示“无”。

Output. . .
Enter current password for root (enter for none):

The next prompt asks you whether you’d like to set up a database root password. On Ubuntu, the root account for MariaDB is tied closely to automated system maintenance, so we should not change the configured authentication methods for that account. Type

N
and then press
ENTER
.

下一个提示询问您是否要设置数据库密码。 在Ubuntu上,MariaDB的帐户与自动系统维护紧密相关,因此我们不应更改该帐户的已配置身份验证方法。 键入

N
,然后按
ENTER

Output. . .

Set root password? [Y/n] N

From there, you can press

Y
and then
ENTER
to accept the defaults for all the subsequent questions. This will remove some anonymous users and the test database, disable remote root logins, and then load these new rules.

在此处,您可以按

Y
,然后按
ENTER
以接受所有后续问题的默认设置。 这将删除一些匿名用户和测试数据库,禁用远程root登录,然后加载这些新规则。

步骤3 —(可选)创建使用密码身份验证的管理用户 (Step 3 — (Optional) Creating an Administrative User that Employs Password Authentication)

On Ubuntu systems running MariaDB 10.3, the root MariaDB user is set to authenticate using the

unix_socket
plugin by default rather than with a password. Because the server uses the root account for tasks like log rotation and starting and stopping the server, it is best not to change the root account’s authentication details. Instead, the package maintainers recommend creating a separate administrative account for password-based access.

在运行MariaDB 10.3的Ubuntu系统上,默认情况下,将root MariaDB用户设置为使用

unix_socket
插件而不是使用密码进行身份验证。 由于服务器使用root帐户执行日志轮换以及启动和停止服务器等任务,因此最好不要更改root帐户的身份验证详细信息。 相反,软件包维护者建议为基于密码的访问创建一个单独的管理帐户。

To this end, open up the MariaDB prompt from your terminal:

为此,请从终端打开MariaDB提示符:

  • sudo mariadb

    苏多·玛丽亚德

Then create a new user with root privileges and password-based access. Be sure to change the username and password to match your preferences:

然后创建一个具有root用户特权和基于密码的访问权限的新用户。 确保更改用户名和密码以匹配您的首选项:

  • GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

    授予所有权限*。*至' admin '@'localhost'由' password '标识,并带有GRANT选项;

Flush the privileges to ensure that they are saved and available in the current session:

刷新特权以确保它们已保存并在当前会话中可用:

  • FLUSH PRIVILEGES;

    冲洗特权;

Following this, exit the MariaDB shell:

之后,退出MariaDB shell:

  • exit

    出口

You can test out this new user with the

mysqladmin
tool, a client that lets you run administrative commands. The following
mysqladmin
command connects to MariaDB as the admin user and returns the version number after prompting for the user’s password:

您可以使用

mysqladmin
工具(可以运行管理命令的客户端)测试该新用户。 以下
mysqladmin
命令以admin用户身份连接到MariaDB,并在提示用户输入密码后返回版本号:

  • mysqladmin -u admin -p version

    mysqladmin -u admin -p版本

You will receive output similar to this:

您将收到类似于以下的输出:

Outputmysqladmin  Ver 9.1 Distrib 10.3.22-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Server version      10.3.22-MariaDB-1ubuntu1
Protocol version    10
Connection      Localhost via UNIX socket
UNIX socket     /var/run/mysqld/mysqld.sock
Uptime:         4 min 49 sec

Threads: 7  Questions: 467  Slow queries: 0  Opens: 177  Flush tables: 1  Open tables: 31  Queries per second avg: 1.615

结论 (Conclusion)

In this guide you installed the MariaDB relational database management system, and secured it using the

mysql_secure_installation
script that it came installed with. You also had the option to create a new administrative user that uses password authentication.

在本指南中,您安装了MariaDB关系数据库管理系统,并使用安装时附带的

mysql_secure_installation
脚本对其进行了保护。 您还可以选择创建一个使用密码身份验证的新管理用户。

Now that you have a running and secure MariaDB server, here some examples of next steps that you can take to work with the server:

既然您已经有一个运行中且安全的MariaDB服务器,那么下面是您可以使用该服务器的一些后续步骤示例:

翻译自: https://www.digitalocean.com/community/tutorials/how-to-install-mariadb-on-ubuntu-20-04-quickstart

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: