Menu Close

How to migrate/upgrade mysql to mariaDB in Ubuntu

Here we will see how we can replace mysql 5.7 with mariaDB 10.3 in Ubuntu 18.04.

Note that by default Ubuntu 18.04 has in its repositories the mariaDB 10.1 version which is not compatible with mysql 5.7!! If you try to install mariaDB 10.1 directly over mysql 5.7 you will hit an error which will lead to unpredictable concequences (eg. not being able to install or run mysql 5.7 again etc.). Any version greater than 10.2 should be capable of replacing mysql 5.7 without any problems.

As first and most important step we suggest you to make a backup of your existing mysql installation and databases in case that something fails.

The fastest and easiest way to do this is make backups of the important directories:

sudo service mysql stop
sudo cp -R /etc/mysql /etc/mysql_bak
sudo cp -R /var/lib/mysql /var/lib/mysql_bak

Now, let’s set the mariaDB repository, necessary to get a version 10.2 or greater. Visit this page and select your own repository:
https://downloads.mariadb.org/mariadb/repositories/#mirror=crete&distro=Ubuntu&distro_release=bionic–ubuntu_bionic

After making your selections in the above webpage you will see commands similar to the following:

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://ftp.cc.uoc.gr/mirrors/mariadb/repo/10.3/ubuntu bionic main'

Run the commands you got from the above link one by one (note the above commands are the example I used for my installation. You should change them accordingly)
Next run the following:
sudo apt update
sudo service mysql stop (in case you didn’t do it earlier)
sudo apt install mariadb-server

This will prompt you to uninstall the following packages (these or similar):
mysql-client-5.7
mysql-server-5.7
mysql-server-core-5.7
libevent-core-2.1.6


and install the following:
mariadb-client-10.3
mariadb-server
mariadb-server-core-10.3
mariadb-server-core-10.3

After the above installation you should run the following command:
sudo mysql_secure_installation
To make your installation secure. Normally, you should answer Y to all questions.
In my installation I noticed that mysql 5.7 was including a database named sys. This unfortunately is not recognised by mariaDB and was leading to errors.
So I manually dropped it (deleted it). To do so run:
sudo mysql -p
write you password when prompted
then
mariaDB>DROP DATABASE sys;
exit
Then run:
mysql_upgrade -p
After the above command you should see all the conversions of your existing databases showing “OK”.

You are now done! MariaDB should be now running masked under the name mysql. To check if it is so run:
sudo service mysql status
and you will see something similar to the following:
mariadb.service – MariaDB 10.3.11 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) since Sun 2018-12-02 13:28:18 EET; 4h 52min ago

Now in my case I had a rather peculiar problem. After restarting my PC mariaDB was being terminated after some time. The problem probably exists only in case you upgraded your ubuntu from version 16.04 to 18.04 (Linux Mint 18.3 to 19).
The problem comes from AppArmor which is not configured correctly to keep the mariaDB service running, so it terminates it after a timeout.
To solve this problem remove the file /etc/apparmor.d/usr.sbin.mysqld. I’m telling you to remove this file completely as in my case it was including only comments and no valid lines of code, and secondly in another clear installation of ubuntu 18.04 it was not even existing!

Leave a Reply

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