MySQL server does not start after moving data dir

I am trying to move MySQL's data dir to an external drive on an odroid (raspberry-like mini computer).

I am using Ubuntu 14.04.

I changed the paths in all configuration files containing /var/lib/mysql and moved all mysql folders on my new drive.

The service does not start anymore and I dont know how to fix that.

Here are all changed paths:

root@odroid-server:/etc# grep -rnw '/etc' -e "/var/lib/mysql"
root@odroid-server:/etc# grep -rnw '/etc' -e "/media/md0/mysql"
/etc/apparmor.d/abstractions/mysql:12:   /media/md0/mysql{,d}/mysql{,d}.sock rw,
/etc/apparmor.d/tunables/alias:16:# alias /media/md0/mysql/ -> /home/mysql/,
/etc/apparmor.d/usr.sbin.mysqld:49:  /media/md0/mysql/ r,
/etc/apparmor.d/usr.sbin.mysqld:50:  /media/md0/mysql/** rwk,
/etc/apparmor.d/usr.sbin.mysqld:53:  /media/md0/mysql-files/ r,
/etc/apparmor.d/usr.sbin.mysqld:54:  /media/md0/mysql-files/** rwk,
/etc/apparmor.d/usr.sbin.mysqld:57:  /media/md0/mysql-keyring/ r,
/etc/apparmor.d/usr.sbin.mysqld:58:  /media/md0/mysql-keyring/** rwk,
/etc/imscp/imscp.conf:37:DATABASE_DIR = /media/md0/mysql
/etc/mysql/mysql.conf.d/mysqld.cnf:36:datadir           = /media/md0/mysql
/etc/mysql/mysql.conf.d/mysqld.cnf:92:# InnoDB is enabled by default with a 10MB datafile in /media/md0/mysql/.
/etc/mysql/mysql.conf.d/mysqld.cnf:98:# chroot = /media/md0/mysql/

Then starting the service:

root@odroid-server:/etc# service mysql start
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.

I tried that command for more details and I can see that it still uses the old mysql datadir.

root@odroid-server:/etc# journalctl -xe
Nov 18 13:06:45 odroid-server systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has begun starting up.
Nov 18 13:06:45 odroid-server mysql-systemd-start[24276]: MySQL data dir not found at /var/lib/mysql. Please create one.
Nov 18 13:06:45 odroid-server systemd[1]: mysql.service: Control process exited, code=exited status=1
Nov 18 13:06:45 odroid-server systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.
Nov 18 13:06:45 odroid-server systemd[1]: mysql.service: Unit entered failed state.
Nov 18 13:06:45 odroid-server systemd[1]: mysql.service: Failed with result 'exit-code'.
Nov 18 13:06:45 odroid-server systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Nov 18 13:06:45 odroid-server systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has finished shutting down.
Nov 18 13:06:45 odroid-server systemd[1]: mysql.service: Start request repeated too quickly.
Nov 18 13:06:45 odroid-server systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.

Maybe there is some command to reload the configuration files back into ram?


From the comments:

Simply symlink /var/lib/mysql to the new directory.

Making symlinks is a quick, easy way of moving important files and directories. No need to change any configuration, and there is minimal documentation to keep track of.


I just found a solution for this (years after it happened to me time).

The problem simply was that ubuntu server shipps with the malware apparmor. I only noticed that after inspecting dmesg. To get rid of it I simply ran

sudo apt remove --purge apparmor -y

and this made mysql start with my new mysql datadir (and fixed other problems too).