Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save linuxmalaysia/dee5dbf62e8ad1065cd0eb96b7419c55 to your computer and use it in GitHub Desktop.
Save linuxmalaysia/dee5dbf62e8ad1065cd0eb96b7419c55 to your computer and use it in GitHub Desktop.
MySQL / MariaDB / Percona Server For MySQL Directory Move Into New Partition (Example /home)

MySQL Directory Move Into New Partition (Example /home)

Login as root or any user that NOT using /home stop mariadb service such as systemctl stop MariaDB

Make sure SELINUX is permissive mode. View file /etc/selinux/config

Step 1 - Copy /home Contents

To backup the contents of /home, do the following:

mkdir /newhome
cp -rfp /home/* /newhome

Once that is finished at your back at the prompt, you can proceed to step 2. Make sure your / is still enough by using command df -h

Step 2 - Unmount the /home directory

umount -fl /home

Step 3 - Remove the /home

rmdir /home

Step 4 - rename /newhome to /home directory

mv /newhome /home

Step 5 - Change the entry from /etc/fstab

Using your preferred text editor, ensure you open /etc/fstab and change of the line for /dev/mapper/cl-home (mount point at the begining of line)

Change only word /home to /var/lib/mysql

Step 6 - rename /var/lib/mysql to /var/lib/mysql-old directory

mv /var/lib/mysql /var/lib/mysql-old

Step 7 - mount the /var/lib/mysql directory

mkdir /var/lib/mysql
chown mysql:mysql /var/lib/mysql
mount /var/lib/mysql

Step 8 - Copy /var/lib/mysql-old Contents

To copy the contents of /var/lib/mysql-old, do the following:

chown mysql:mysql /var/lib/mysql
cp -rfp /var/lib/mysql-old/* /var/lib/mysql

Step 9 - check the disk space

df -h

Step 10 - Don't miss this!

Run the following command to sync systemd up with the changes.

dracut --regenerate-all --force

This rescue option is useful if you have problems after adding new hardware. You can use the rescue option to regenerate the initramfs for all boot entries using the above command.

MySQL / MariaDB / Percona Server For MySQL Directory Move Into New Partition (Example /home)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment