1

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

2 Answers 2

1

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.

0

Make sure the below actions are performed.

1- Clean data directory :

rm -rf /home/development/mysql/*

2- Give data directory the correct permissions :

chown -R mysql:mysql /home/development/mysql

3- Copy the content of the old directory with preserving the original permissions :

cp -R -p /var/lib/mysql/* /home/development/mysql

4- mysql.sock path should be the same on client & mysld section.

5- Start mariadb service :

systemctl start mariadb

EDIT :

I would suggest last thing to create another directory and try within it. If it still not work then go back to /var/lib/mysql backup your database, change /var/lib/mysql name and do a fresh install or initiate mariadb-install-db on the new dir and then restore your database. Also avoid putting a database under home dir, create a dedicated fs because if the user "development" are deleted the database will go with it.

13
  • I followed those instructions, but I still have the error: Dec 10 18:05:26 localhost.localdomain mariadb-prepare-db-dir[3753]: Database MariaDB is not initialized, but the directory /home/development/mysql is not empty, so initialization cannot be done. Dec 10 18:05:26 localhost.localdomain mariadb-prepare-db-dir[3753]: Make sure the /home/development/mysql is empty before running mariadb-prepare-db-dir. Dec 10, 2019 at 23:07
  • MariaDB keep complaining that the directory is not initialized and I have also tried a removable USB drive. Dec 10, 2019 at 23:14
  • Could you log the output with ls -haltr of the home dir ?
    – Reda Salih
    Dec 10, 2019 at 23:22
  • 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 Dec 10, 2019 at 23:23
  • And ls -haltr /home/developement/mysal ?
    – Reda Salih
    Dec 10, 2019 at 23:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .