Have you ever been annoyed that in e.g. Linux or FreeBSD, due to "conflicts",
you can't install the MariaDB client package alongside the MySQL client
package? Specifically, you're not able to have tools such as MariaDB's mariadb
and mariadb-dump
alongside MySQL's mysql
and mysqldump
?
... sea lion play nice?
Can a dolphin and a ...
Well, whenever there is a will, there is a hack!
Scope
This approach has only been tested on FreeBSD and Linux, but I think it should work in principle on most Unix-like OSes. You can still only install one of the packages, but you can have both sets of client tools.
The examples below assume you already have installed the MariaDB clients via your package manager. Of course we can also do this the other way around: If we have the MySQL client package already installed, then you can use a similar approach to install the MariaDB client tools.
Example: Linux
Navigate to the MySQL Community Downloads and sign up for an Oracle account if you don't have one already. Then once logged in to the aforementioned page, you are faced with several options about the format of the download. Choose one of the following:
Linux - generic
Choose "Linux - generic" for operating system. OS version (glibc version) doesn't matter, as far as I can tell. Then download the "Compressed TAR Archive, Minimal install". The resulting .tar.xz package can then be uncompressed with a command such as:
tar xvfz mysql-8.4.6-linux-glibc2.28-x86_64-minimal.tar.xz
Red Hat Enterprise / Oracle / Fedora Linux
If your host is either of the distros in this heading, then you can also use that. Click on the "RPM package, client utilities". The resulting .rpm package can then be uncompressed with a command such as:
rpm2cpio mysql-community-client-8.4.6-10.fc42.x86_64.rpm | cpio -di
Install
Unzipping one of the above options should give you a directory with a usr/bin/
subdir in which you will find all the client tools, which is what you want. If
you used the "Linux - generic" option then it will contain server tools as well
that you can safely ignore.
Now just create a directory such as /opt/mysql/bin/
and copy the client tools
into there.
Then you can either go to that directory and execute the tools from there, or
give the full path whenever you execute the tools. Alternatively, you can also
put them in your PATH
variable somewhere before the MariaDB client tools, but
beware that you then need to use the MariaDB-specific names (mariadb
,
mariadb-dump
etc) when you want to use the MariaDB client tools.
Example: FreeBSD
pkg fetch mysql84-client
cp /var/cache/pkg/mysql84-client-8.4.5~79f68c9bfb.pkg /tmp/
cd /tmp
tar xvf mysql84-client-8.4.5~79f68c9bfb.pkg
This extracts the client tool binaries into the sub-dir usr/local/bin/
from
which you can copy it to somewhere permanent.
By the way ...
Now that I have a system with both a MariaDB server and a MySQL mysql
client,
is that client able to connect to our MariaDB database?
Yes, as long as it's a TCP/IP connection and not a socket connection, it seems!
Other Unix-like OSes
Presumably, as long as you can get hold of a MariaDB or MySQL client package file, and you're able to extract the tools from this file, then the same approach should work for other Unix-like OSes.
Other uses
You can also use this approach to install multiple versions of each set of tools: E.g. MariaDB 10.11 + 11.4 + 11.8 as well as MySQL 8.4 + 9.4 etc:
/opt/mariadb/10.11
/opt/mariadb/11.4
/opt/mariadb/11.8
/opt/mysql/8.4
/opt/mysql/9.4
Disadvantages
The only downside I can think of it that you can't use your package manager to keep all the tools up-to-date.
Other solutions
- You could probably also make it work in
podman
, but it might require some networking magic for the client tools to talk to databases outside of the pods. - You could of course use VMs but that seems a bit overkill.
- You can also always go and compile MySQL from source code, but that again seems overkill.
- There used to be a tool called
dbdeployer
for deploying multiple MySQL, MariaDB and Percona MySQL client and server instances on the same host, but the project is no longer maintained.
Notes
- Sea lion SVG by Bjorn Lammars - Apache 2.0
- Dolphin SVG by Open Clipart Library, via Wikimedia Commons - CC0 1.0 Universal