如何在Ubuntu 20.04上安装MariaDB

MariaDB是从流行的数据库管理系统MySQL派生而来的开源数据库服务器。 它取代了MySQL作为大多数Linux操作系统的默认数据库服务器。

在这里,我们将看到如何在Ubuntu 20.04上安装MariaDB。

在Ubuntu 20.04上安装MariaDB

您可以从Ubuntu存储库或Official MariaDB镜像中获取MariaDB软件包。

  1. 安装MariaDB v10.4 – MariaDB镜像

  2. 安装MariaDB v10.3 – Ubuntu存储库

从MariaDB镜像安装MariaDB

MariaDB基金会为Ubuntu 20.04提供了MariaDB v10.4。 您可以从MariaDB下载页面中选择任何一个镜像进行下载。

sudo apt update

sudo apt install -y software-properties-common apt-transport-https ca-certificates

将MariaDB的签名密钥添加到您的系统。

sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'

使用add-apt-repository命令将MariaDB存储库添加到您的系统。

sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.4/ubuntu focal main'

读:
在Ubuntu上找不到add-apt-repository命令–快速修复

现在,使用以下命令安装MariaDB。

sudo apt update

sudo apt install -y mariadb-server mariadb-client

使用mysql_secure_installation设置MariaDB根密码并保护MariaDB服务器的安装。

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
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] N 
 ... skipping.

You already have your root account protected, 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!

从Ubuntu存储库安装MariaDB

从Ubuntu默认存储库安装是一种直接的方法。 Ubuntu 20.04发布了MariaDB v10.3。

使用apt命令安装MariaDB。

sudo apt update

sudo apt install -y mariadb-server mariadb-client

使用mysql_secure_installation设置MariaDB根密码并保护MariaDB服务器的安装。

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!

MariaDB使用Unix套接字身份验证机制,该机制可防止其他Unix用户登录或使用诸如phpMyAdmin之类的应用程序访问MariaDB根用户。 要禁用Unix套接字认证并启用本机密码,请遵循以下步骤。

以MariaDB根用户身份登录。

sudo mysql -u root -p

无需密码

use mysql;

update user set plugin='mysql_native_password' where user="root";

flush privileges;

quit;

现在,您可以毫无问题地以MariaDB根用户身份登录。

访问MariaDB

要访问MariaDB Shell以创建数据库或任何与数据库相关的活动,请在终端上运行以下命令。

sudo mysql -u root -p

输入在确保mysql_secure_installation安装安全时设置的MariaDB根用户的密码。

输入密码后,您将获得MariaDB shell。

Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 58
Server version: 10.3.22-MariaDB-1ubuntu1 Ubuntu 20.04

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)]>

控制MariaDB服务

如果要启动/停止MariaDB,可以使用以下命令。

sudo systemctl start mariadb

sudo systemctl stop mariadb

结论

就这样。 请在评论部分分享您的反馈。

Sidebar