0

Base OS: Centos 7 Atomic Host

I installed Mariadb 10.2 & changed the data directory to a folder under /home directory. I made the respective changes to /etc/my.cnf to point to the data directory & mysql socket. I also did the concerned changes in SE linux context. Now, when I start the mariadb service by systemctl start mariadb it fails. The output to the system status mariadb.service is

Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
# systemctl status mariadb.service
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: failed (Result: exit-code) since Tue 2017-09-12 13:54:15 CEST; 23s ago
  Process: 3099 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=1/FAILURE)
  Process: 3066 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
  Process: 3063 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 3099 (code=exited, status=1/FAILURE)
   Status: "MariaDB server is down"

/etc/my.cnf is

[client-server]

[mysqld]
datadir=/home/data/db/mysql
socket=/home/data/db/mysql/mysql.sock

[client]
port=3306
socket=/home/data/db/mysql/mysql.sock

Any ideas on how to get MariaDB up & running?

Sunny
  • 407
  • 5
  • 15
  • 1
    Please check the owners and permissions on /home/data/db/mysql. They should be mysql:mysql and 755. This shoudl start from /home all the way to .../mysql – Jacques Amar Sep 13 '17 at 00:25
  • Thanks Jaques for your comment. It's a good point & I thought in that direction as well. For both my /home/data/db/mysql as well as /var/lib/mysql have been set to mysql:mysql and 755 & yet the problem persists. There is one small detail I noticed though. In /var/lib/mysql it's system_u:object_r:var_lib_t:s0 but in /home/data/db/mysql it's unconfined_u:object_r:mysqld_db_t:s0 . Now I did try setting the /home/data/db/mysql to system_u as well by using -s system_u,but it somehow didn't change inspite of restorecon in SE linux context. However, I'll reboot the system soon to check for changes. – Sunny Sep 13 '17 at 09:06
  • It didn't work even after reboot. :( – Sunny Sep 13 '17 at 09:11
  • okie I'm able to change it to system_u as well by **restorecon -vF /home/data/db/mysql/*** but mariadb still fails when I start it. – Sunny Sep 13 '17 at 10:21

1 Answers1

2

Finally, I got the solution. The link below should help anyone stuck in similar problem. The 1st task is to do the usual procedure for changing data directory for mariadb & the 2nd task is to allow mariadb.service to use /home as the base directory for data storage.

Task 1:

Following by Gabriel Cánepa's advice at Tecmint.com:

1.1.Changing the default MySQL/MariaDB Data Directory

# mkdir /mnt/mysql-data
# chown -R mysql:mysql /mnt/mysql-data

1.2.Identify Current MySQL Data Directory

# mysql -u root -p -e "SELECT @@datadir;"

1.3.Copy MySQL Data Directory to a New Location

# systemctl stop mariadb
# systemctl is-active mariadb
# cp -R -p /var/lib/mysql/* /mnt/mysql-data

1.4.Configure a New MySQL Data Directory

# vi /etc/my.conf

[mysqld]:
datadir=/mnt/mysql-data
socket=/mnt/mysql-data/mysql.sock
[client]:
port=3306
socket=/mnt/mysql-data/mysql.sock

1.5.Set SELinux Security Context to Data Directory

# semanage fcontext -a -t mysqld_db_t "/mnt/mysql-data(/.*)?"
# restorecon -R /mnt/mysql-data

1.6.Restart mariadb.service after Task 2

# systemctl start mariadb

1.7.Verify the location

# mysql -u root -p -e "SELECT @@datadir;"

Task 2:

As suggested by Thomas:

To run MariaDB SQL from /home, in the file /usr/lib/systemd/system/mariadb.service, just change :

ProtectHome=true

to :

ProtectHome=false
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Sunny
  • 407
  • 5
  • 15