blog-banner

Install Mariadb along with Mysql in Centos

  • CENTOS
  • Drupal Planet
  • MariaDB
  • MySql

MariaDB is a community-developed fork of the MySQL relational database management system intended to remain free under the GNU GPL. You can use the link to know more about MariaDB and its features. If you want to try MariaDB without losing MySQL, then here is the tutorial for running MariaDB alongside MySQL.

Let's start with the steps to install MariaDB along with Mysql

  • Download the latest version (mariadb-10.0.20-linux-i686.tar.gz - as of writing this article) from here and extract the files in /opt directory.
  • Create a directory for storing the mariadb data
[root@knackforge opt]# mkdir mariadb-data
  • Create symlinks from mariadb-10.0.20-linux-i686 to mariadb
[root@knackforge opt]# ln -s mariadb-10.0.20-linux-i686 mariadb
[root@knackforge opt]# ls -al
total 32
lrwxrwxrwx  1 root       root         26 Jun 24 10:06 mariadb -> mariadb-10.0.20-linux-i686
drwxr-xr-x 12 mariadb    mariadb    4096 Jun 24 10:05 mariadb-10.0.20-linux-i686
drwxr-xr-x  9 mariadb    mariadb    4096 Jun 24 09:42 mariadb-data
  • Create group mariadb and user mariadb and set correct ownerships:
[root@knackforge opt]# groupadd --system mariadb
[root@knackforge opt]# useradd -c "MariaDB User" -d /opt/mariadb -g mariadb --system mariadb
[root@knackforge opt]# chown -R mariadb:mariadb mariadb-10.0.20-linux-i686/
[root@knackforge opt]# chown -R mariadb:mariadb mariadb-data/
  • Create a new my.cnf in /opt/mariadb from support files:
[root@knackforge opt]# cp mariadb/support-files/my-medium.cnf mariadb-data/my.cnf
[root@knackforge opt]# chown mariadb:mariadb mariadb-data/my.cnf
  • Edit the file /opt/mariadb-data/my.cnf. We need to add custom paths, socket, port, user, data directory and base directory. Finally the file should look something like the following:
[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
  • Copy the init.d script from support files to the correct location:
[root@knackforge opt]# cp mariadb/support-files/mysql.server /etc/init.d/mariadb
[root@knackforge opt]# chmod +x /etc/init.d/mariadb
  • Edit /etc/init.d/mariadb file, we need to replace mysql with mariadb as below:
- # Provides: mysql
+ # Provides: mariadb
- basedir=
+ basedir=/opt/mariadb
- datadir=
+ datadir=/opt/mariadb-data
- lock_file_path="$lockdir/mysql"
+ lock_file_path="$lockdir/mariadb"
  • We need to inform mariadb to use only one cnf file. These changes need to be done carefully. In the start section after $bindir/mysqld_safe add --defaults-file=/opt/mariadb-data/my.cnf. Finally, the lines should look like this:
# Give extra arguments to mysqld with the my.cnf file. This script
# may be overwritten at next upgrade.
$bindir/mysqld_safe --defaults-file=/opt/mariadb-data/my.cnf --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
  • The same change needs to be made to the mysqladmin command below in the wait_for_ready() function so that the mariadb start command can properly listen for the server start. In the wait_for_ready() function, after $bindir/mysqladmin add --defaults-file=/opt/mariadb-data/my.cnf. The lines should look like:
wait_for_ready () {
[...]
    if $bindir/mysqladmin --defaults-file=/opt/mariadb-data/my.cnf ping >/dev/null 2>&1; then
  • Run mysql_install_db by explicitly giving it the my.cnf file as an argument:
[root@knackforge opt]# cd mariadb
[root@knackforge mariadb]# scripts/mysql_install_db --defaults-file=/opt/mariadb-data/my.cnf
  • Now MariaDB can be started by
[root@mariadb-near-mysql opt]# /etc/init.d/mariadb start
Starting MySQL...
                                 [  OK  ]
  • To make MariaDB start at system boot, we need to do the following:
[root@knackforge opt]# cd /etc/init.d
[root@knackforge init.d]# chkconfig --add mariadb
[root@knackforge init.d]# chkconfig --levels 3 mariadb on
  • Finally, test that you have both instances running:
[root@knackforge ~]# mysql -e "SELECT VERSION();"
5.5.32
[root@knackforge ~]# mysql -e "SELECT VERSION();" --socket=/opt/mariadb-data/mariadb.sock
10.0.20
 
Get awesome tech content in your inbox