How to reinstall MariaDB on DirectAdmin server

09.08.2019

If you need to reinstall MariaDB on DirectAdmin server. Here is how you can do it.

Dump MySQL tables

First, make sure to dump all existing databases

cd /usr/local/directadmin/custombuild/
./build update
./build mysql_backup

You should have sufficient free disk space for it and it might take a while to dump big databases. You should never skip this step.

Copy MySQL config file 

If you have customized the file /etc/my.cnf you will need to copy it to a safe place:

\cp -p /etc/my.cnf /etc/my.cnf~poralix

Remove existing MariaDB

On CentOS and CloudLinux servers run the following command:

rpm -qa | grep mariadb -i | xargs rpm -e --noscripts

Here you might need to kill a running copy of a SQL-server.

Rename /var/lib/mysql/

Later after you re-install the SQL-server you can remove the old data directory, but now it would be better to rename folder.

\mv /var/lib/mysql /var/lib/mysql.moved

Re-install /etc/my.cnf

It you have a customized version of settings for SQL-server it is the right time to install it.

\cp -p /etc/my.cnf~poralix  /etc/my.cnf

Re-install MariaDB:

Now we do a fresh installation of a SQL-server:

cd /usr/local/directadmin/custombuild/
./build update
./build mysql

As soon as the installation complete we need to set a password.

Set root's password

By default when installing MariaDB, there might be empty root's password, so we need to set it. It can be done with a help of mysql_secure_installation:

mysql_secure_installation

Follow the steps, and answer Yes, when asked whether or not you want to set a password.

Recover mysql database

First we recover mysql database to restore all users accounts:

cd /usr/local/directadmin/custombuild/mysql_backups
mysql mysql -p < mysql.sql

Enter the root's password when asked.

Restart SQL-server:

systemctl restart mysqld

Restore other databases

And now we can restore all databases:

cd /usr/local/directadmin/custombuild/mysql_backups
wget http://files1.directadmin.com/services/all/mysql/restore_sql_files.sh
chmod 755 restore_sql_files.sh
./restore_sql_files.sh

That's it.

https://help.poralix.com/articles/how-to-reinstall-mariadb-on-directdamin-server