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
? This could be a
relevant use-case for a developer's laptop or workstation, i.e. someone who
works with both database systems.
Can the dolphin and the
sea lion play nice?
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 even so you can have both sets of client tools installed!
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: Red Hat-like Linux, RPM package via DNF5
If the MySQL-client package is already available via your dnf and yum.repos,
then you can download the RPM from there using dnf
and extract the files from
it using the rpm2cpio
command shown:
dnf download mysql-community-client
rpm2cpio mysql-community-client-8.4.6-10.fc42.x86_64.rpm | cpio -di
The files are extracted into a usr/bin/
subdir. Jump to the next section's
'Install' sub-section for ideas of how to install these files.
Example: Linux, package/archive via MySQL website
If you don't already have access to the MySQL packages via your package manager, then 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:
Red Hat Enterprise / Oracle / Fedora Linux
If your host is either of the distros in this heading, then you can use the following procedure: Click on the "RPM package, client utilities". The downloaded .rpm package can then be decompressed with a command such as:
rpm2cpio mysql-community-client-8.4.6-10.fc42.x86_64.rpm | cpio -di
Linux - generic
For other distros, 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
Install
Decompressing 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 I happen to have a system with both a MySQL mysql
client and a MariaDB
server. Is that mysql
client able to connect to my MariaDB database?
Yes, as can be seen in the screen shot, that appears to be the case! It works as long as it's a TCP/IP connection and not a Unix socket connection.
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 is that you can't use your package manager to keep all the tools up-to-date.
Other solutions
- You could install some alternative third-party tools instead that support both MariaDB and MySQL such as mycli and mydumper.
- You could probably also make it work in a FreeBSD jail or in
podman
, but this might require some networking magic for the client tools to talk to databases outside of the jail/container. - 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