Installing MariaDB 10.6 alongside MySQL 8.0.26 on Red Hat 8.5

Installing MariaDB 10.6 alongside MySQL 8.0.26 on Red Hat 8.5
Photo by Nicole Baster / Unsplash

In this article, we are installing MariaDB alongside MySQL as seen on this article.

Execute the following commands to install MySQL 8.

dbuser@redhat:/home/dbuser>
$ sudo yum install @mysql
dbuser@redhat:/home/dbuser>
$ sudo systemctl enable --now mysqld

dbuser@redhat:/home/dbuser>
$ sudo systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-01-28 15:29:03 GMT; 4min 56s ago
 Main PID: 4839 (mysqld)
   Status: "Server is operational"
    Tasks: 38 (limit: 23692)
   Memory: 409.2M
   CGroup: /system.slice/mysqld.service
           └─4839 /usr/libexec/mysqld --basedir=/usr

We connect to MySQL 8.0.26

dbuser@redhat:/home/dbuser>
$ sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.26 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select version () ;
+------------+
| version () |
+------------+
| 8.0.26     |
+------------+
1 row in set (0.00 sec)

mysql>

Once MySQL is up and running.

$ ps axf | grep mysqld
   4996 pts/0    S+     0:00  |           \_ grep --color=auto mysqld
   4839 ?        Ssl    0:01 /usr/libexec/mysqld --basedir=/usr

Let's follow the official documentation to install MariaDB on the same server.

Download software

Using wget and from /opt, download the MariaDB installaton files.

root@redhat:/opt>
$ wget https://dlm.mariadb.com/1920008/MariaDB/mariadb-10.6.5/bintar-linux-systemd-x86_64/mariadb-10.6.5-linux-systemd-x86_64.tar.gz

Using tar we uncompress and extract all files.

root@redhat:/opt>
$ tar xfz mariadb-10.6.5-linux-systemd-x86_64.tar.gz

root@redhat:/opt>
$ ls -lrt
total 334508
drwxrwxr-x. 11 dbuser dba        245 Nov  6 17:09 mariadb-10.6.5-linux-systemd-x86_64
-rw-r--r--.  1 root   root 342534912 Nov  8 23:55 mariadb-10.6.5-linux-systemd-x86_64.tar.gz

root@redhat:/opt>
$ cd mariadb-10.6.5-linux-systemd-x86_64

root@redhat:/opt/mariadb-10.6.5-linux-systemd-x86_64>
$ ls -lrt
total 164
drwxr-xr-x.  2 dbuser dba  4096 Oct 22  2020 bin
drwxr-xr-x.  5 dbuser dba   273 Jul 28  2021 lib
-rw-r--r--.  1 dbuser dba 86263 Nov  5 20:03 THIRDPARTY
-rw-r--r--.  1 dbuser dba 19520 Nov  5 20:03 README-wsrep
-rw-r--r--.  1 dbuser dba  2697 Nov  5 20:03 README.md
-rw-r--r--.  1 dbuser dba  8782 Nov  5 20:03 INSTALL-BINARY
-rw-r--r--.  1 dbuser dba  2093 Nov  5 20:03 CREDITS
-rw-r--r--.  1 dbuser dba 17987 Nov  5 20:03 COPYING
drwxrwxr-x.  3 dbuser dba    19 Nov  5 20:39 include
drwxrwxr-x.  9 dbuser dba  4096 Nov  5 20:40 mysql-test
drwxrwxr-x.  4 dbuser dba  4096 Nov  5 20:40 sql-bench
drwxrwxr-x.  2 dbuser dba    56 Nov  5 20:40 scripts
drwxrwxr-x.  5 dbuser dba    42 Nov  5 20:40 man
drwxrwxr-x.  4 dbuser dba   180 Nov  5 20:40 support-files
drwxrwxr-x. 31 dbuser dba  4096 Nov  5 20:40 share
root@redhat:/opt/mariadb-10.6.5-linux-systemd-x86_64>
$

From /opt

root@redhat:/opt/mariadb-10.6.5-linux-systemd-x86_64>
$ cd ..

root@redhat:/opt>
$ ls -lrt
total 334508
drwxrwxr-x. 11 dbuser dba        245 Nov  6 17:09 mariadb-10.6.5-linux-systemd-x86_64
-rw-r--r--.  1 root   root 342534912 Nov  8 23:55 mariadb-10.6.5-linux-systemd-x86_64.tar.gz

root@redhat:/opt>
$ mkdir mariadb-data

root@redhat:/opt>
$ ln -s mariadb-10.6.5-linux-systemd-x86_64 mariadb

root@redhat:/opt>
$ ls -al
total 334508
drwxr-xr-x.  4 root   root       134 Jan 28 15:51 .
dr-xr-xr-x. 17 root   root       224 Jan 19 16:24 ..
lrwxrwxrwx.  1 root   root        35 Jan 28 15:51 mariadb -> mariadb-10.6.5-linux-systemd-x86_64
drwxrwxr-x. 11 dbuser dba        245 Nov  6 17:09 mariadb-10.6.5-linux-systemd-x86_64
-rw-r--r--.  1 root   root 342534912 Nov  8 23:55 mariadb-10.6.5-linux-systemd-x86_64.tar.gz
drwxr-xr-x.  2 root   root         6 Jan 28 15:51 mariadb-data

Create group, user and assign privileges.

We create a mariadb group, add a mariadb user and change the owner of /opt/mariadb and /opt/mariadb-10.6.5-linux-systemd-x86_64

root@redhat:/opt>
$ groupadd --system mariadb

root@redhat:/opt>
$ useradd -c "MariaDB Server" -d /opt/mariadb -g mariadb --system mariadb

root@redhat:/opt>
$ ls -lrt
total 334508
drwxrwxr-x. 11 dbuser dba        245 Nov  6 17:09 mariadb-10.6.5-linux-systemd-x86_64
-rw-r--r--.  1 root   root 342534912 Nov  8 23:55 mariadb-10.6.5-linux-systemd-x86_64.tar.gz
drwxr-xr-x.  2 root   root         6 Jan 28 15:51 mariadb-data
lrwxrwxrwx.  1 root   root        35 Jan 28 15:51 mariadb -> mariadb-10.6.5-linux-systemd-x86_64

root@redhat:/opt>
$ chown -R mariadb:mariadb mariadb-10.6.5-linux-systemd-x86_64

root@redhat:/opt>
$ chown -R mariadb:mariadb mariadb-data/

Create configuration file

I could not find the my-medium.cnf file on this path mariadb/support-files/, so instead, I used the mysql config file.

root@redhat:/opt>
$ cp /etc/my.cnf.d/mysql-server.cnf /opt/mariadb-data/my.cnf

root@redhat:/opt>
$ chown mariadb:mariadb /opt/mariadb-data/my.cnf

Edit configuration file

Edit the config file and add the following.

root@redhat:/opt>
$ vi /opt/mariadb-data/my.cnf

[client]
port            = 3307
socket          = /opt/mariadb-data/mariadb.sock

[mysqld]
datadir         = /opt/mariadb-data
basedir         = /opt/mariadb
port            = 3307
socket          = /opt/mariadb-data/mariadb.sock
user            = mariadb

log-error=/var/log/mariadb/mariadb.log
pid-file=/run/mariadb/mariadb.pid

Therefore, we create the following directories and assign privileges.

root@redhat:/opt>
$ mkdir /var/log/mariadb

root@redhat:/opt>
$ mkdir /run/mariadb

root@redhat:/opt>
$ touch /var/log/mariadb/mariadb.log

root@redhat:/opt>
$ touch /run/mariadb/mariadb.pid

root@redhat:/opt>
$ chown mariadb:mariadb /var/log/mariadb/

root@redhat:/opt>
$ chown -R mariadb:mariadb /var/log/mariadb/

root@redhat:/opt>
$ chown -R mariadb:mariadb /run/mariadb/

Copy the init.d script from support files

root@redhat:/opt>
$ cp mariadb/support-files/mysql.server /etc/init.d/mariadb

root@redhat:/opt>
$ chmod +x /etc/init.d/mariadb

We edit the file and update the following lines 18, 45, 46 and 57 first:

root@redhat:/opt>
$ vi /etc/init.d/mariadb

Line
18			# Provides: mariadb
45			basedir=/opt/mariadb
46			datadir=/opt/mariadb-data
57			lock_file_path="$lockdir/mariadb"

and add the following to the same file.

In the wait_for_ready() function line 255, after $bindir/mysqladmin line 260 add --defaults-file=/opt/mariadb-data/my.cnf

255 wait_for_ready () {
256
257   i=0
258   while test $i -ne $service_startup_timeout ; do
259
260     if $bindir/mysqladmin --defaults-file=/opt/mariadb-data/my.cnf ping >/dev/null 2>&1; then
261       log_success_msg
262       return 0
263     elif kill -0 $! ; then
264       :  # mysqld_safe is still running
265     else
266       # mysqld_safe is no longer running, abort the wait loop
267       break
268     fi
269
270     echo $echo_n ".$echo_c"
271     i=`expr $i + 1`
272     sleep 1
273
274   done
275
276   log_failure_msg
277   return 1
278 }

in line 309 add --defaults-file=/opt/mariadb-data/my.cnf after $bindir/mysqld_safe

307       # Give extra arguments to mysqld with the my.cnf file. This script
308       # may be overwritten at next upgrade.
309       $bindir/mysqld_safe --defaults-file=/opt/mariadb-data/my.cnf --datadir="$datadir" --pid-file="$mariadbd_pid_file_path" "$@" &
310       wait_for_ready; return_value=$?

Also as mentioned in the comment section:

in line 210 add --defaults-file=/opt/mariadb-data/my.cnf after $print_defaults

210 parse_server_arguments `$print_defaults --defaults-file=/opt/mariadb-data/my.cnf $extra_args --mysqld mysql.server`
211 parse_server_arguments "$@"

Run mysql_install_db

root@redhat:/opt>
$ cd mariadb

root@redhat:/opt/mariadb>
$ scripts/mysql_install_db --defaults-file=/opt/mariadb-data/my.cnf
Installing MariaDB/MySQL system tables in '/opt/mariadb-data' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system


Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mariadb@localhost, it has no password either, but
you need to be the system 'mariadb' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo

See the MariaDB Knowledgebase at https://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/opt/mariadb' ; /opt/mariadb/bin/mysqld_safe --datadir='/opt/mariadb-data'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/opt/mariadb/mysql-test' ; perl mysql-test-run.pl

Please report any problems at https://mariadb.org/jira

The latest information about MariaDB is available at https://mariadb.org/.
You can find additional information about the MySQL part at:
https://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

Now you can start MariaDB

$ /etc/init.d/mariadb start
Starting mariadb (via systemctl):                          [  OK  ]
root@redhat:/run>

$ /etc/init.d/mariadb status
 SUCCESS! MariaDB running (5329)
root@redhat:/run>

Connect to MySQL and MariaDB

root@redhat:/run>
$ mysql -e "SELECT VERSION();"
+-----------+
| VERSION() |
+-----------+
| 8.0.26    |
+-----------+

root@redhat:/run>
$  mysql -e "SELECT VERSION();" --socket=/opt/mariadb-data/mariadb.sock
+----------------+
| VERSION()      |
+----------------+
| 10.6.5-MariaDB |
+----------------+

Together on the same server!

Thanks to Stanislav David

Want to thank me?

Buy Me A Coffee