如何在 Ubuntu 18.04 LTS 上安装 MariaDB 10.4?

在Ubuntu 18.04 LTS上安装MariaDB 10.4。

首先

为了以后重新安装MariaDB 10.4,我记录了安装步骤,因为在工作环境中安装时遇到了困难。
我参考了一篇在Google上找到的文章来进行安装,但是由于出现了错误,无法确定原因并解决,因此我决定重新安装Ubuntu。最终,在参考安装MariaDB 10.4到Ubuntu 18.04 LTS的过程中,一切都顺利进行了。

开发环境

Ubuntu 18.04 LTS,WSL 1

途径

首先,配置MariaDB软件包的存储库访问。

$ curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
[info] Checking for script prerequisites.
[info] Repository file successfully written to /etc/apt/sources.list.d/mariadb.list
[info] Adding trusted package signing keys...
[info] Running apt-get update...
[info] Done adding trusted package signing keys

然后,确认以下文件是否生成。

# MariaDB Server
# To use a different major version of the server, or to pin to a specific minor version, change URI below.
deb [arch=amd64,arm64] https://dlm.mariadb.com/repo/mariadb-server/10.6/repo/ubuntu bionic main

deb [arch=amd64,arm64 lang=none target-=CNF] https://dlm.mariadb.com/repo/mariadb-server/10.6/repo/ubuntu bionic main/debug

# MariaDB MaxScale
# To use the latest stable release of MaxScale, use "latest" as the version
# To use the latest beta (or stable if no current beta) release of MaxScale, use "beta" as the version
deb [arch=amd64] https://dlm.mariadb.com/repo/maxscale/latest/apt bionic main

# MariaDB Tools
deb [arch=amd64] http://downloads.mariadb.com/Tools/ubuntu bionic main

MariaDB服务器的版本号是10.6。由于我想要安装MariaDB 10.4版本,因此需要将版本更改为10.4。这时候由于只有root有写入权限,所以需要更改权限以进行编辑。

$ sudo chmod 766 mariadb.list
mariadb.list
$ vi mariadb.list
$ cat mariadb.list
# MariaDB Server
# To use a different major version of the server, or to pin to a specific minor version, change URI below.
deb [arch=amd64,arm64] https://dlm.mariadb.com/repo/mariadb-server/10.4/repo/ubuntu bionic main

deb [arch=amd64,arm64 lang=none target-=CNF] https://dlm.mariadb.com/repo/mariadb-server/10.4/repo/ubuntu bionic main/debug

# MariaDB MaxScale
# To use the latest stable release of MaxScale, use "latest" as the version
# To use the latest beta (or stable if no current beta) release of MaxScale, use "beta" as the version
deb [arch=amd64] https://dlm.mariadb.com/repo/maxscale/latest/apt bionic main

# MariaDB Tools
deb [arch=amd64] http://downloads.mariadb.com/Tools/ubuntu bionic main

更新可安装软件包的“列表”。

$ sudo apt-get -y update
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:2 https://dlm.mariadb.com/repo/mariadb-server/10.4/repo/ubuntu bionic InRelease [6265 B]
・・・(略)

更新已安装的软件包,并升级到新版本。

kmri18@DESKTOP-OAP1VIU:/etc/apt/sources.list.d$ sudo apt-get -y upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
・・・(略)

显示MariaDB服务器

$ apt list | grep -i mariadb-server

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

mariadb-server/unknown,unknown 1:10.4.22+maria~bionic all
mariadb-server-10.1/bionic-updates,bionic-security 1:10.1.48-0ubuntu0.18.04.1 amd64
mariadb-server-10.4/unknown 1:10.4.22+maria~bionic amd64
mariadb-server-10.4-dbgsym/unknown 1:10.4.22+maria~bionic amd64
mariadb-server-core-10.1/bionic-updates,bionic-security 1:10.1.48-0ubuntu0.18.04.1 amd64
mariadb-server-core-10.4/unknown 1:10.4.22+maria~bionic amd64
mariadb-server-core-10.4-dbgsym/unknown 1:10.4.22+maria~bionic amd64

安装MariaDB服务器10.4版本

$ sudo apt install mariadb-server-10.4 -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
・・・(略)

$ dpkg -l | grep -i mariadb
ii  libdbd-mysql-perl              4.046-1
                amd64        Perl5 database interface to the MariaDB/MySQL database
ii  libmariadb3:amd64              1:10.4.22+maria~bionic              amd64        MariaDB database client library
ii  mariadb-client-10.4            1:10.4.22+maria~bionic              amd64        MariaDB database client binaries
ii  mariadb-client-core-10.4       1:10.4.22+maria~bionic              amd64        MariaDB database core client binaries
ii  mariadb-common                 1:10.4.22+maria~bionic              all          MariaDB database common files (e.g. /etc/mysql/mariadb.conf.d/)
ii  mariadb-server-10.4            1:10.4.22+maria~bionic              amd64        MariaDB database server binaries
ii  mariadb-server-core-10.4       1:10.4.22+maria~bionic              amd64        MariaDB database core server files

最后,连接到MySQL服务器。

$ sudo mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 55
Server version: 10.4.22-MariaDB-1:10.4.22+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)]>

确认MariaDB版本已经升级到10.4并完成安装。

总结

最终,重新安装Ubuntu解决了问题。考虑到尝试各种方法可能导致混乱的环境,以及意外的错误产生,将来我打算将环境重置作为选项之一。

请自取

在Ubuntu 18.04 LTS上安装MariaDB 10.4。