Running MariaDB & MySQL on the same node

Ever wondered how to run MariaDB and MySQL alongside flawlessly? Read this blog article to find out more…

First you’ll have to download the binaries, you can install either one of using a package of your choice however the second will have to be using binaries. In this how-to guide we make use of the binaries for both, the option is yours.

Now that you’ve downloaded your binaries, run tar xzvf <filename> in your “/usr/local” directory. I’ve already performed this action for both Oracle MySQL and MariaDB. The next step is to created symbolic links for your directories and set the ownership using commands such as:

ln -s /usr/local/mariadb-5.5.36-linux-x86_64 /usr/local/mariadb
ln -s mysql-5.5.36-linux2.6-x86_64/ /usr/local/mysql

chown -R mysql:mysql /usr/local/mysql*
chown -R mysql:mysql /usr/local/maria*

You should now have the following structure in your “/usr/local” directory:

lrwxrwxrwx.  1 mysql mysql   38 Feb 27 12:57 maria -> /usr/local/mariadb-5.5.36-linux-x86_64
drwxr-xr-x. 14 mysql mysql 4096 Feb 27 23:30 mariadb-5.5.36-linux-x86_64
lrwxrwxrwx.  1 mysql mysql   29 Feb 27 23:59 mysql -> mysql-5.5.36-linux2.6-x86_64/
drwxr-xr-x. 13 mysql mysql 4096 Feb 27 23:58 mysql-5.5.36-linux2.6-x86_64

So far so good, we have the files ready – now time for the wizardry… (its actually quite simple). You’ll have to edit two files for each installation, namely the “my.cnf” and the “/etc/init.d/mysql” files. I prefer to have seperate files for both so I’ve created the following pairs:

/etc/my.mariadb.cnf
/etc/init.d/mariadb

/etc/my.oracle.cnf
/etc/init.d/mysql

Initialize the startup scripts using the files located in the “/usr/local/mysql/support-files/mysql.server” and “/usr/local/maria/support-files/mysql.server”. Different data directories are also required to store the data files in exclusive directories, I’ve created these:

mkdir /ssd_data/mariadb_data_1
chown -R mysql:mysql /ssd_data/mariadb_data_1
mkdir /ssd_data/mysql_data_1
chown -R mysql:mysql /ssd_data/mysql_data_1

For the “my.oracle.cnf” file you’ll need to specify the following options (these are mandatory, feel free to add any others):

#
# The MySQL server
#
# generic configuration options
[mysqld]
port            = 3306
socket          = /ssd_data/mysql_data_1/mysql.sock
basedir         = /usr/local/mysql
datadir         = /ssd_data/mysql_data_1
pid-file        = /ssd_data/mysql_data_1/workstation.pid
log-bin       =/ssd_data/mysql_data_1/mysql-bin # if you want binary-logs

And likewise for the “my.mariadb.cnf”:

#
# The MariaDB server
#
[mysqld]
# generic configuration options
port        = 3307
socket        = /ssd_data/mariadb_data_1/mysql.sock
basedir        = /usr/local/maria
datadir        = /ssd_data/mariadb_data_1
pid-file    = /ssd_data/mariadb_data_1/workstation.pid
log-bin       =/ssd_data/mariadb_data_1/mysql-bin # if you want binary logs

Since the data directories and configuration files are ready, now we move on to the final step, customization of the start-up scripts. For Oracle MySQL just edit the following variables at the top of the script:

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.

basedir=’/usr/local/mysql’
datadir=’/ssd_data/mysql_data_1′
defaults_file=’/etc/my.oracle.cnf’

Then find and edit the following line adding the $defaults_file variable declared in the previous step:

# Give extra arguments to mysqld with the my.cnf file. This script
# may be overwritten at next upgrade.
$bindir/mysqld_safe –defaults-file=”$defaults_file” –datadir=”$datadir” –pid-file=”$mysqld_pid_file_path” $other_args >/dev/null 2>&1 &

The same will have to be performed for the MariaDB init script, however with one small difference, in the MariaDB script we also have to specify the “–defaults-file” for the “mysqladmin ping” command which tests if the instance has started, hence we change:

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.

basedir=’/usr/local/maria’
datadir=’/ssd_data/mariadb_data_1′
defaults_file=’/etc/my.mariadb.cnf’

And we also change:

# Give extra arguments to mysqld with the my.cnf file. This script
# may be overwritten at next upgrade.
$bindir/mysqld_safe –defaults-file=”$defaults_file” –datadir=”$datadir” –pid-file=”$mysqld_pid_file_path” $other_args >/dev/null 2>&1 &

As well as the “mysqladmin ping” command to look like:

if $bindir/mysqladmin –defaults-file=”$defaults_file” $sockopt ping >/dev/null 2>&1; then
log_success_msg
return 0
fi

Time to initialize the data directories for both MySQL & MariaDB, we’ll have to run the following commands:

cd /usr/local/mysql
./scripts/mysql_install_db –defaults-file=/etc/my.oracle.cnf
chown -R mysql:mysql /ssd_data/mysql_data_1

cd /usr/local/maria
./scripts/mysql_install_db –defaults-file=/etc/my.mariadb.cnf
chown -R mysql:mysql /ssd_data/mariadb_data_1

And if everything went as planned running the init scripts will result in the following wonderful output:

[root@workstation mysql_data_1]# /etc/init.d/mysql start
Starting MySQL..                                           [  OK  ]
[root@workstation mysql_data_1]# /etc/init.d/mariadb start
Starting MySQL..                                           [  OK  ]

You are now the happy owner of a MariaDB / MySQL installation running on the same node. Don’t forget to add either the “/usr/local/maria/bin” or the “/usr/local/mysql/bin” directory to your environment path to have access to the client tools – or you can create aliases to switch between the two on the fly.

Have fun!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s