如何在Ubuntu 18.04 LTS上安装MariaDB

时间:2019-05-29 14:48:03  来源:igfitidea点击:

MariaDB是一个增强的,直接替换MySQL的工具。
对于正在寻找健壮、可伸缩和可靠的SQL服务器的数据库专业人员来说,MariaDB是一个更好的选择。

本文将通过apt包管理器 在Ubuntu 18.04 LTS上安装MariaDB 10.3

步骤1 -准备工作

MariaDB Apt配置文件可以在官网找到。
导入系统上的MaraiDB包的key。

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

在此之后,使用以下命令为MariaDB创建一个新的Apt配置文件。

sudo vim /etc/apt/sources.list.d/mariadb.list

# MariaDB 10.3 Repository
deb [arch=amd64,arm64,ppc64el] http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.3/ubuntu bionic main
deb-src http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.3/ubuntu bionic main

第2步-在Ubuntu 18.04上安装MariaDB

将存储库添加到系统后,使用以下命令在Ubuntu系统上安装MariaDB-server。
这将删除任何以前版本的MariaDB包,并在系统上安装最新的包。
在运行以下命令之前,请确保对数据库进行了适当的备份。

sudo apt update
sudo apt install mariadb-server

这还将在系统上安装其他必需的依赖项。

当使用上面的命令安装MariaDB时,安装程序将提示输入MariaDB root帐户密码。

步骤3 -验证MariaDB设置

在Ubuntu 18.04系统上成功安装MariaDB之后。
安装程序还将在安装过程中启动服务。
我们可以通过运行下面的命令来验证服务。

sudo systemctl status mariadb

然后通过下面的命令连接到MariaDB shell。

mysql -u root -p

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 47
Server version: 10.3.10-MariaDB-1:10.3.10+maria~bionic mariadb.org binary distribution

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

步骤4 -管理MariaDB服务

有时我们需要停止或启动MariaDB服务。
使用以下命令停止、启动、重启MariaDB服务或检查它的状态。

sudo systemctl stop mariadb.service      # 停止MariaDB 服务 
sudo systemctl start mariadb.service     # 启动MariaDB 服务 
sudo systemctl status mariadb.service    # 检查MariaDB 服务状态 
sudo systemctl restart mariadb.service   # 重启MariaDB 服务