MySQL 5.6 and SELinux are arguing

MySQLselinux

CentOS 6.4(x64) / MySQL 5.6.10

Installed MySQL from source files and started it fine under it's original location (/var/lib/mysql). I moved everything to a different volume (/u0/mysql) and went through a few rounds of exempting it from SELinux (cat /var/log/audit/audit.log | audit2allow -M mysql-* followed by semodule -i mysql-*.pp). After every round of this I try to restart the service and see this error:

Starting MySQL..The server quit without updating PID file (/u0/mysql/server.pid).
 [FAILED]

After 3-4 rounds of adding exemptions I noticed that the files weren't changing anymore. IE everything that could be added this way had already been added. Out of curiosity I ran audit2why -a and got a slew of:

type=AVC msg=audit(1387207317.009:666): avc:  <some permission> for  pid=20640 
  comm="mysqld" dev=sdc1 ino=36831373 scontext=unconfined_u:system_r:mysqld_t:s0 
  tcontext=system_u:object_r:default_t:s0 tclass=file
 Was caused by:
     Unknown - would be allowed by active policy
     Possible mismatch between this policy and the one under which the audit message was generated.
     Possible mismatch between current in-memory boolean settings vs. permanent ones.

This leads me to believe that it should be working. If I disable SELinux: setenforce 0 then mysql will start just fine so it (SE) is still getting in the way.

Searching through SF turned this up – have tried it with no change in outcome.

SO: how do I find out where the blockage is?

EDIT:

[root@server u0]# ls -ldZ /var/lib/mysql
drwxr-xr-x. mysql mysql unconfined_u:object_r:mysqld_db_t:s0 /var/lib/mysql

[root@server u0]# ls -ldZ /u0/mysql
drwxr-xr-x. mysql mysql unconfined_u:object_r:mysqld_db_t:s0 /u0/mysql

Best Answer

You need to change the security context of the new directory to be the same as /var/lib/mysql.

For instance:

ls -ldZ /var/lib/mysql/
drwxr-x--x. mysql mysql system_u:object_r:mysqld_db_t:s0 /var/lib/mysql/

Then change the new directory to the same settings with chcon

chcon -R -u system_u -r object_r -t mysqld_db_t /u0/mysql
Related Topic