How to replace MySQL with MariaDB on a cPanel server

MariaDB is an enhanced drop-in replacement for MySQL. MySQL 5.1 is compatible with MariaDB 5.1, 5.2 and 5.3. MySQL 5.5 is compatible with MariaDB 5.5.

Features of MariaDB
>> Data and table definition files (.frm) are binary compatible.
>> All client APIs, protocols and struct are identical
>> All filenames, binaries, paths, ports, sockets etc should be the same.
>> All MySQL connectors (PHP, Perl, Python, Java, .NET, MyODBC, Ruby, MySQL C connector) works unchanged with MariaDB.
>> mysql-client package also works with MariaDB server
>> The shared client-library is binary compatible with MySQL’s client library

This indicates that we can just uninstall MySQL and install MariaDB.

Steps to replace MySQL with MariaDB

1. To be secure with our current data, make sure to take a backup:

# cp -Rf /var/lib/mysql /var/lib/mysql-orig
# mv /etc/my.cnf /etc/my.cnf.orig

2. Disable the targets so that cPanel won’t handle MySQL updates

# /scripts/update_local_rpm_versions --edit target_settings.MySQL50 uninstalled
# /scripts/update_local_rpm_versions --edit target_settings.MySQL51 uninstalled
# /scripts/update_local_rpm_versions --edit target_settings.MySQL55 uninstalled

3. Remove all the MySQL RPMs from the server

# /scripts/check_cpanel_rpms --fix --targets=MySQL50,MySQL51,MySQL55

The above command will uninstall all the MySQL RPMs from the server.

4. Create Yum repository for MariaDB

Create a file “MariaDB.repo”.

# vi /etc/yum.repos.d/MariaDB.repo

Place the following in the newly created repo file depending on the DISTRO ( https://downloads.mariadb.org/mariadb/repositories/ ):

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5.34/centos6-amd64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

5. Remove php from “exclude” list in /etc/yum.conf

6. Install MariaDB-sever, MariaDB-client, MariaDB-devel

# yum install MariaDB-server MariaDB-client MariaDB-devel

7. Start MySQL

# /etc/init.d/mysql start

8. Then, run mysql_upgrade

# mysql_upgrade

9. Restart MySQL

# /etc/init.d/mysql restart

10. Add PHP back to the /etc/yum.conf file in “exclude” list

11. Recompile Apache with PHP

# /scripts/easyapache --build

Done!! You can check it by executing the command ‘mysql -V’

-------
# mysql -V
mysql  Ver 15.1 Distrib 5.5.34-MariaDB, for Linux (x86_64) using readline 5.1
-------

That’s it 🙂

Also,
How to replace MySQL with PerconaDB on a cPanel server
How to enable remote MySQL for an IP address on a cPanel server via CSF
How to upgrade MySQL from 5.1 to 5.5 in a cPanel server – command line option
How to allow mysql client to access remote mysql databases

Post navigation

Arunlal A

Senior System Developer at Zeta. Linux lover. Traveller. Let's connect! Whether you're a seasoned DevOps pro or just starting your journey, I'm always eager to engage with like-minded individuals. Follow my blog for regular updates, connect on social media, and let's embark on this DevOps adventure together! Happy coding and deploying!

2 thoughts on “How to replace MySQL with MariaDB on a cPanel server

Leave a Reply

Your email address will not be published. Required fields are marked *