3

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?

  • put the following line in your /etc/my.cfg file. log-error=/var/log/mysqld.log Is the data dir owned by the mysql user? – Valentin Bajrami Nov 18 '16 at 12:55
  • 2
    symlink /var/lib/mysql to new directory – Ipor Sircer Nov 18 '16 at 13:37
  • Just do what @IporSircer said. Making symlinks instead of changing config files will avoid that kind of problems + no need to change any configuration + no need to write much extra documentation :D – sysfiend Nov 18 '16 at 16:49
  • symlinking worked indeed! i would accept that as an answer! – feedc0de Nov 19 '16 at 20:26
3

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.

2

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.