Jump to Navigation

Overcoming SELinux when changing the default MySQL data directory

This evening, I chose to install MySQL 5.5 instead of accepting the 5.1 version that shipped with my CentOS 6  Linux distribution.  After dutifully downloading the binaries and successfully installing the RPMs, I received the following error message when starting mysqld:

 

Starting MySQL. ERROR! The server quit without updating PID file (/data01/mysql/localhost.pid).

As it turns out, there is an active SELinux policy for MySQL.  The default policy expects /var/lib/mysql to be used instead of my desired /data01/mysql logical volume. 

After a few minutes of reviewing the SELinux documentation, the following commands were necessary to update the policy to use the desired MySQL data directory.

# semanage fcontext -a -t mysqld_db_t "/data01/mysql(/.^)?"
# restorecon -Rv /data01/mysql

If you don't have the policycore utilities installed, you may not have the SELinux management tools.  To install those on CentOS 6/RHEL6:

# yum install policycoreutils policycoreutils-python

I could have opted to disable or stop enforcement of SELinux all together.  I find value in it and prefer to try and make it work. I have to admit, however, there there are times that I just disable it to help simplify and application configuration or troubleshooting.  Many times, it is the culprit as to why an external package or non-standard configuration does not work.

All Categories: 


by Dr. Radut.