1

I am trying to move the /var/lib/mysql data directory to a different drive. I have tried the solutions listed in https://www.digitalocean.com/community/tutorials/how-to-move-a-mysql-data-directory-to-a-new-location-on-ubuntu-16-04 and https://www.digitalocean.com/community/tutorials/how-to-change-a-mysql-data-directory-to-a-new-location-using-a-symlink. In both cases I had similar issues to others where mysql could not be restarted.

I finally stumbled on to a solution in the comments to this thread: How do I move the MySQL data directory? by but in order to make it work I had to add another step. Currently what Im doing is:

  1. sudo mount /dev/nvme1n1p1 /mnt/test1 - here Im mounting the other hd (/dev/nvme1n1p1) on to a folder I created (/mnt/test1)
  2. sudo rsync -avzh /var/lib/mysql /mnt/test1 - per the commentary of the thread above I copied the mysql data directory to the mounted drive, so now the mysql data is on the external hd
  3. I deleted /var/lib/mysql and created an empty directory (sudo mkdir /var/lib/mysql)
  4. sudo mount -B /mnt/test1/mysql /var/lib/mysql - here I mount the /mnt/test1/mysql directory back into /var/lib/mysql

I am sure this is the wrong way to do this, so any advice on the correct process would be helpful.

Thanks.

2
  • "I am sure this is the wrong way to do this" why do you believe that? :) It is not the safest method (I would have used a symlink) but it reads as a correct method
    – Rinzwind
    Apr 4, 2021 at 4:12
  • The symlink was one of the solutions provided on digitalocean but in both digitalocean solutions i got to the last step and was unable to restart mysql. I say this is the wrong solution because the absence of a cleaner solution makes me suspicious. Its also unclear why I cant mount the external hd directly to /var/lib/mysql but instead have to mount to a /mnt/test1 first.
    – Soap
    Apr 4, 2021 at 11:58

0

You must log in to answer this question.

Browse other questions tagged .