Installation

Migrating from MySQL8 to MariaDB on Ubuntu 20

Migrating from MySQL8 to MariaDB on Ubuntu 20

by Ama Chefe -
Number of replies: 0

I upgraded my WW from 2.15 to 2.16, which was okay, except for some minor git issue that prevented the `git merge`, solved it by using git stash

I also used the opportunity to migrate from MySQL to MariaDB, which ended up being a bit more troublesome than anticipated, so i decided to make a guide for others.

The process would be easier if the ww backup and recovery has been implemented, so you can use the backup script to dump the database. https://webwork.maa.org/wiki/Backup_and_Disaster_Recovery

$ mysqldump --opt webwork | gzip -c > /webwork_backup/webwork.sql.gz

Remove MySQL:
$ sudo apt purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*

Delete MySQL configuration, data, and log directories:
$ sudo rm -Rf /etc/mysql /var/lib/mysql /var/log/mysql

Clean any hanging files:
$ sudo apt autoremove
$ sudo apt autoclean

Install MariaDB using the distro packages:
$ sudo apt install mariadb-server libdbd-mariadb-perl

While MariaDB is installed, most of the tools you'll be using will be aimed at MySQL.
The database would be automatically started after the installation:
$ sudo service mariadb status

If the status is not active check the system log.

Check /var/log/syslog

It is common to see an issues with app armor like below

Sep 25 01:07:06 webwork systemd[1]: Starting MariaDB 10.3.31 database server...
Sep 25 01:07:06 webwork systemd-udevd[369]: Network interface NamePolicy= disabled on kernel command line, ignoring.
Sep 25 01:07:06 webwork kernel: [50259.947729] audit: type=1400 audit(1632532026.320:89): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/etc/ld.so.cache" pid=31093 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=112 ouid=0
Sep 25 01:07:06 webwork kernel: [50259.947793] audit: type=1400 audit(1632532026.320:90): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/usr/lib/x86_64-linux-gnu/liblz4.so.1.9.2" pid=31093 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=112 ouid=0
Sep 25 01:07:06 webwork kernel: [50259.947819] audit: type=1400 audit(1632532026.320:91): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/usr/lib/x86_64-linux-gnu/liblz4.so.1.9.2" pid=31093 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=112 ouid=0
Sep 25 01:07:06 webwork mysqld[31093]: /usr/sbin/mysqld: error while loading shared libraries: liblz4.so.1: cannot open shared object file: No such file or directory

To resolve look for mysqld on the app armor status output:
$ sudo aa-status

Then follow the steps below to remove mysqld from the app armor:

$ echo "/usr/sbin/mysqld { }" | sudo tee /etc/apparmor.d/usr.sbin.mysqld
$ sudo apparmor_parser -v -R /etc/apparmor.d/usr.sbin.mysqld
$ sudo systemctl restart mariadb

The issue should be resolved, however if the database is still not starting, consult on your database logs.
Alternately, delete all database file and recreate the database

$ sudo rm -rf /var/lib/mysql/*
$ sudo mysql_install_db -u mysql

To secure the Maria DB installation
$ sudo mysql_secure_installation

$ sudo mysql
[sudo] password for wwadmin: <wwadmin password>

MariaDB > CREATE DATABASE webwork DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
MariaDB > CREATE USER 'webworkWrite'@'localhost' IDENTIFIED BY 'database_password';
MariaDB > GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, LOCK TABLES ON webwork.* TO 'webworkWrite'@'localhost';
MariaDB > FLUSH PRIVILEGES;
MariaDB > exit
$
Where database_password is the password you set on site.conf.

Restore the MySQL database from the backup:
$ gunzip webwork.sql.gz
$ mysql -p webwork < webwork.sql