Moving MySQL datafiles to home partition

Discussion in 'Systems Administration' started by DarkBoomba, Jan 14, 2020.

  1. Hello eveyone,

    I'm trying to move my mysql datafiles (/var/lib/mysql) to my home partition (/home/user/mysql). I want to this because the var partition isn't large enough and figured I could get it to work with a symlink. I followed this guide but when I started mysql again it failed to start. The output of sudo tail /var/log/syslog gave me the following message: Failed to create test file (permission denied).

    I then found this page and followed the instruction to setup the right ownership and permissions for the new mysql dir and removed the ProtectSystem and ProtectHome options in /usr/lib/systemd/system/mariadb.service. I reloaded the systemctl daemon but mysql still failed to start. This time with a different error though, I can't make much out of it

    Does anyone where I have gone wrong? And how I can get this to work? Any help would be greatly appreciated
  2. sudo chown mysql:mysql -R /home/user/mysql

    Symlinks won't work properly aswell afaik & you need to change the /var/lib directory in /etc/mysql/mariadb.conf.d/50-server.cnf (assuming you use MariaDB on a modern operating system)
  3. Hi, thank you for your response. I'm running on Debian 10. I tried using your solution, changed the 50-server.cnf directory to the new one (/home/user/mysql).

    However I still get the same error on start of mysql. Any clue?
  4. electronicboy

    IRC Staff

    looks like you didn't update apparmor properly?
  5. I added this line to it
    Code (Text):
    alias /var/lib/mysql/ -> /home/user/mysql/,
    At first I forgot the comma and apparmor didn't restart (obviously),
    but when I added it it ran fine. Is that line correct though?
  6. Why don’t you just remove the home partition and assign the unallocated space to /?
  7. There are minecraft servers located in that same home partition. Also, can that even be done without an OS reinstall?
  8. Make a backup, and yes.
  9. How would I do this? And would I be able to restore the home directories for my user?
    1. Stop your server(s)
    2. Archive (I recommend 7z) your /home directory
    3. Download the archive
    4. Perform partition updates
    5. Upload archive & extract
    6. Start server(s)
    • Like Like x 1