Move mysql data folder to ZFS on CentOS 7

  1. change origin data folder as mount point
sudo systemctl stop mariadb.service

cd /var/lib

sudo mv mysql mysql.bak

sudo mkdir mysql

sudo chown mysql:mysql mysql

  1. create zfs file system
sudo zfs create -o mountpoint=/var/lib/mysql mysqldata/mysql

  1. mount zfs file system
sudo zfs mount -a

  1. change mount point owner as mysql and cp all data file to /var/lib/mysql
sudo chown mysql:mysql mysql

cd mysql.bak

sudo cp -p -r * ../mysql

cd ..

  1. install package policycoreutils-python
sudo yum install policycoreutils-python

  1. run semanage fcontext and restorecon
sudo semanage fcontext -a -t mysqld_db_t "/mysql(/.*)?"

sudo grep -i mysql /etc/selinux/targeted/contexts/files/file_contexts.local

sudo restorecon -R -v /var/lib/mysql

  1. start mysql
sudo systemctl start mariadb.service

Reference: MariaDB Changing Database Location

Written on November 5, 2016