如何在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
使⽤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
使⽤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
服务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 and select the Linux distribution that we’re working with. In this case,
it’s Ubuntu 19.10 “eoan”.
要在Ubuntu上安装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:80 0xF1656F24C74CD1D8
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] mirrors.piconets.webwerks.in/mariadb/repo/10.4/ubuntu eoan main'
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] mirrors.piconets.webwerks.in/mariadb/repo/10.4/ubuntu eoan main
deb-src mirrors.piconets.webwerks.in/mariadb/repo/10.4/ubuntu eoan main
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
检查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
登录到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 .
另外,如果您有兴趣在Ubuntu系统上设置WordPress,请不要忘记查看我们的有关上的教程。
ubuntu安装教程