Overcoming SELinux when changing the default MySQL data directory


![](http://upload.wikimedia.org/wikipedia/en/thumb/6/62/MySQL.svg/489px- MySQL.svg.png)

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

&nbsp_place_holder;

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. &nbsp_place_holder;The default policy expects /var/lib/mysql to be used instead of my desired /data01/mysql logical volume.&nbsp_place_holder;

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. &nbsp_place_holder;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. &nbsp_place_holder;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. &nbsp_place_holder;Many times, it is the culprit as to why an external package or non-standard configuration does not work.