We are going to to move the entire MariaDB or Mysql Server – inclusive all users and databases – to a new Server. We don’t have to struggle with mysqldump, we just need tar and ssh.

At first make sure on both machines is installed the same Server version:

server # mysql --version
mysql  Ver 15.1 Distrib 10.3.10-MariaDB, for Linux (x86_64) using readline 5.1

Stop MariaDB/Mysql on both servers:

systemctl stop mariadb

Tar, compress and copy the mysql directory to the server. Copy as a regular user, because root login ist hopefully disabled:

old-server# tar -zcvf database.tar.gz /var/lib/mysql
old-server# scp database.tar.gz user@new-server/tmp

Extract archive on new server and make sure, owner of the new files is the database user:

new-server# tar -xzf /tmp/database.tar.gz -C /
new-server# chown -R mysql:mysql /var/lib/mysql/

The last thing you have to do, is to delete the old log files:

new-server# rm /var/lib/mysql/ib_logfile*

Thats it. Now restart the database server and you are done.