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:
- sudo mount /dev/nvme1n1p1 /mnt/test1 – here Im mounting the other hd (/dev/nvme1n1p1) on to a folder I created (/mnt/test1)
- 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
- I deleted /var/lib/mysql and created an empty directory (sudo mkdir /var/lib/mysql)
- 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.