Can’t change the data-directory for MariaDB Centos7.6

centos7database-administrationmariadb

I have a fresh install of Centos 7.6 which includes standard partition scheme for Centos 7.6 install. Which includes a "/" directory partition of 50GB. I would like to move the default nysql (mariadb) data directory so I don't fill up the root partition with a big database. I want to move the directory to a directory in a user's home directory. MariaDB will not start after the changes and I don't understand the reason based on the error message.

I have tried following the instructions:

# Check the current data-dir
mysql -u root -p
MariaDB [(none)]> select @@datadir;

# Edit the my.cnf file and change:
[mysqld]
datadir=/home/development/mysql
socket=/home/development/mysql/mysql.sock
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
!includedir /etc/my.cnf.d
[client]
port=3306
socket=/home/development/mysql/mysql.sock


# Restart MariaDB
systemectl start mariadb

MariaDB fails to start and the following is output.

Dec 10 12:19:52 localhost.localdomain mariadb-prepare-db-dir[24554]: Database MariaDB is not initialized, but the directory /home/development/mysql is not empty, so initialization cannot be done.
Dec 10 12:19:52 localhost.localdomain mariadb-prepare-db-dir[24554]: Make sure the /home/development/mysql is empty before running mariadb-prepare-db-dir.

The directory in question is in fact empty. The permissions on the folder are mysql:mysql.

Also, I have disabled SELinux entirely with:

setenforce 0

Here the output of permissions on the home directory:

$ ls -haltr /home
total 4.0K
drwxr-xr-x.  3 root        root          25 Dec 10 15:41 .
dr-xr-xr-x. 17 root        root         242 Dec 10 15:59 ..
drwx------. 19 development development 4.0K Dec 10 18:00 development

$ ls -haltr /home/development/mysql
total 29M
drwx------.  2 mysql       mysql       4.0K Dec 10 17:56 mysql
drwx------.  2 mysql       mysql       4.0K Dec 10 17:56 performance_schema
-rw-rw----.  1 mysql       mysql         52 Dec 10 17:56 aria_log_control
-rw-rw----.  1 mysql       mysql        16K Dec 10 17:56 aria_log.00000001
-rw-rw----.  1 mysql       mysql       5.0M Dec 10 17:56 ib_logfile1
srwxrwxrwx.  1 mysql       mysql          0 Dec 10 17:56 mysql.sock
-rw-rw----.  1 mysql       mysql        18M Dec 10 17:56 ibdata1
-rw-rw----.  1 mysql       mysql       5.0M Dec 10 17:56 ib_logfile0
drwx------. 19 development development 4.0K Dec 10 18:00 ..
drwxrwxr-x.  4 mysql       mysql        165 Dec 10 18:01 

and the permissions of the mysql directory itself:

ls -haltr /home/development | grep mysql
drwxrwxr-x.  4 mysql       mysql        165 Dec 10 18:01 mysql

Best Answer

Look at your systemd mariadb.service script. The default one includes ProtectHome to ensure mysqld cannot access anything under /home/ for security reasons.

Do you have an overwhelmingly good reason to deviate from default paths instead of using a bind-mount? SELinux and other security features are there for very good reasons.