如何在Ubuntu上安装MariaDB

We can install MariaDB on Ubuntu from the Ubuntu repositories or the official MariaDB repositories. In this tutorial, we’ll go over both the methods in detail.

我们可以从Ubuntu存储库或官方MariaDB存储库在Ubuntu上安装MariaDB。 在本教程中,我们将详细介绍这两种方法。

The preferred way is to make use of the Ubuntu repositories but if you want to download packages that are compiled by MariaDB, then you can the MariaDB repository.

首选方法是利用Ubuntu存储库,但是如果您要下载MariaDB编译的软件包,则可以使用MariaDB存储库。

什么是MariaDB? (What is MariaDB?)

MariaDB is an open-source, community-supported fork of the MySQL relational database system. It is also backward compatible with the MySQL server, so any scripts you’ve written with MySQL in mind will work with MariaDB.

MariaDB是MySQL关系数据库系统的开源,社区支持的分支。 它也与MySQL服务器向后兼容,因此您在考虑MySQL时编写的所有脚本都可与MariaDB一起使用。

MariaDB can be used in a wide array of applications including but not limited to banking and websites to turn data into structured information.

MariaDB可用于各种应用程序中,包括但不限于银行和网站,以将数据转换为结构化信息。

如何在Ubuntu上安装MariaDB? (How to Install MariaDB on Ubuntu?)

We’ll first go over the steps to install MariaDB in Ubuntu using the Ubuntu repository.

我们将首先介绍使用Ubuntu存储库在Ubuntu中安装MariaDB的步骤。

1.使用Ubuntu存储库安装MariaDB (1. Install MariaDB Using Ubuntu Repositories)

Ubuntu gives us access to a pre-compiled package for MariaDB which is accessible through the apt repositories without any configuration. Let’s run the below commands to update the repository index.

Ubuntu使我们可以访问MariaDB的预编译软件包,可以通过apt信息库进行访问,而无需进行任何配置。 让我们运行以下命令来更新存储库索引。


root@ubuntu:~# apt update
Update Ubuntu Packages Using Apt
Update Ubuntu Packages Using Apt
使用Apt更新Ubuntu软件包

Once the repositories are updated, we will move on to installing the mariadb-server package.

更新存储库后,我们将继续安装mariadb-server软件包。


root@ubuntu:~# apt install mariadb-server
Install Mariadb Server Using Apt
Install MariaDB Server Using Apt
使用Apt安装MariaDB Server

This would take some time depending on the speed of your internet. But once done, you will have a MariaDB server installed in your system.

这将需要一些时间,具体取决于您的互联网速度。 但是一旦完成,您将在系统中安装MariaDB服务器。

We will check the service status of the MariaDB server to check if it’s running, and start the service if it isn’t already.

我们将检查MariaDB服务器的服务状态,以检查其是否正在运行,如果尚未运行,则启动该服务。


root@ubuntu:~# service mariadb status
Service Mariadb Status Output
Service MariaDB Status Output
服务MariaDB状态输出

If you receive the above output stating that the service is active, you’ve successfully installed MariaDB in your system and can verify this by typing one of the below commands.

如果收到上述输出,表明该服务处于活动状态 ,则说明您已经在系统中成功安装了MariaDB,并可以通过键入以下命令之一来进行验证。


root@ubuntu:~# mariadb -V
OR
root@ubuntu:~# mysql -V

The reason why it works with both the commands brings us back to what we discussed at the beginning of this tutorial.

这两个命令都可以使用的原因使我们回到了本教程开头所讨论的内容。

The MariaDB server was made to be backward compatible with MySQL. So any scripts that you’ve written for MySQL should work with MariaDB.

MariaDB服务器被设计为与MySQL向后兼容。 因此,您为MySQL编写的所有脚本都应与MariaDB一起使用。

If you do not see the MariaDB service status as active, you can activate it by using the following command.

如果看不到MariaDB服务状态为活动,则可以使用以下命令将其激活。


root@ubuntu:~# service mariadb start

2.使用MariaDB存储库安装MariaDB (2. Installing MariaDB Using MariaDB Repositories)

To install MariaDB on Ubuntu, we’ll first visit the MariaDB repositories page and select the Linux distribution that we’re working with. In this case, it’s Ubuntu 19.10 “eoan”.

要在Ubuntu上安装MariaDB,我们首先将访问MariaDB存储库页面,然后选择要使用的Linux发行版。 在这种情况下,它是Ubuntu 19.10“ eoan”。

Now, we download the software-properties-common package which allows us to easily add, manage, and remove apt repositories from multiple independent software vendors.

现在,我们下载了software-properties-common软件包,该软件包使我们能够轻松地从多个独立的软件供应商处添加,管理和删除apt存储库。


root@ubuntu:~# apt install software-properties-common
2.1)导入公钥并添加MariaDB源 (2.1) Importing Public Key and Adding MariaDB Sources)

Once installed, we’ll move on to adding the public keys required to access the MariaDB repositories and download packages from there.

安装完成后,我们将继续添加访问MariaDB存储库并从那里下载软件包所需的公钥。

The below line can have a different key-value depending on the distribution you’re working with.

根据您使用的发行版,下一行可以具有不同的键值。


root@ubuntu:~# apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
Import Mariadb Public Keys
Import MariaDB Public Keys
导入MariaDB公钥

Now, we’ll add the official MariaDB repositories to our sources list using the command below.

现在,我们将使用下面的命令将正式的MariaDB存储库添加到我们的源列表中。


root@ubuntu:~# add-apt-repository 'deb [arch=amd64] https://mirrors.piconets.webwerks.in/mariadb/repo/10.4/ubuntu eoan main'
Add MariaDB Apt Repositories
Add MariaDB Apt Repositories
添加MariaDB Apt存储库
2.2)替代方法–手动添加MariaDB源 (2.2) Alternative – Manually Adding MariaDB Sources)

If you do not wish to download an additional package to add sources, you can manually add MariaDB sources at the end of the /etc/apt/sources.list file.

如果您不想下载其他软件包来添加源,则可以在/etc/apt/sources.list文件末尾手动添加MariaDB源。

Open the file in your favorite text editor, and paste the two lines at the end of the file.

在您喜欢的文本编辑器中打开文件,然后将两行粘贴到文件末尾。


deb [arch=amd64] https://mirrors.piconets.webwerks.in/mariadb/repo/10.4/ubuntu eoan main
deb-src https://mirrors.piconets.webwerks.in/mariadb/repo/10.4/ubuntu eoan main
Manually Add Mariadb Repositories In Sources
Manually Add MariaDB Repositories In Sources
在源中手动添加MariaDB存储库
2.3)更新源代码并安装MariaDB (2.3) Updating Sources and Installing MariaDB)

Now comes the easy part. You’ve added the sources and imported the keys. All we need to do now is to install MariaDB.

现在来简单的部分。 您已经添加了源并导入了密钥。 我们现在要做的就是安装MariaDB。


root@ubuntu:~# apt update
root@ubuntu:~# apt install mariadb-server

If all went well, you should have the MariaDB server installed in your system.

如果一切顺利,则应该在系统中安装MariaDB服务器。

2.4)检查MariaDB安装版本 (2.4) Checking MariaDB Installed Version)

You can check the installed version with either of the commands below. Both of the commands will give you the MariaDB version that’s installed in your system.

您可以使用以下任一命令来检查安装的版本。 这两个命令都将为您提供系统中已安装的MariaDB版本。


root@ubuntu:~# mariadb -V
OR
root@ubuntu:~# mysql -V
Checking Mariadb Installation Version
Checking MariaDB Installation Version
检查MariaDB安装版本

登录到MariaDB (Logging Into MariaDB)

Similar to how the MariaDB and MySQL commands were used interchangeably above, we can log in to the MariaDB server using either of the commands.

与上面可互换使用MariaDB和MySQL命令的方式类似,我们可以使用任一命令登录到MariaDB服务器。


root@ubuntu:~# mysql -u root
OR
root@ubuntu:~# mariadb -u root
Login To Mariadb Server
Login To MariaDB Server
登录到MariaDB服务器

结论 (Conclusion)

In this tutorial, we covered how to install MariaDB in Ubuntu. After following all the steps, you should have a working installation of the MariaDB server on your system.

在本教程中,我们介绍了如何在Ubuntu中安装MariaDB。 完成所有步骤之后,您应该在系统上可以正常安装MariaDB服务器。

Also, if you’re interested in setting up WordPress on your Ubuntu system, don’t forget to check out our tutorial on installing WordPress with Nginx on Ubuntu.

另外,如果您有兴趣在Ubuntu系统上设置WordPress,请不要忘记查看我们的有关在Ubuntu使用Nginx安装WordPress的教程。

翻译自: https://www.journaldev.com/33714/install-mariadb-ubuntu

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值