Thursday, April 10, 2008

Change the data directory in Redhat Linux Enterprise with sellinux on

Today I had to change the data directory for a MySQL database in Redhat 5 Enterprise Edition with selinux set to enforcing mode. This was in a NEW INSTALL so there was no existing data. I stress this because this method is not a method one uses to RELOCATE existing data.

Here are the steps:
  1. Stop the database => service mysqld stop
  2. Edit /etc/my.cnf and change the datadir value to the desired location.
  3. Change the selinux user / role and type on the new location.
    1. chcon -u system_u -r (cantremember_r) -t mysqld_db_t /full/path/to/mysql/data/dir
  4. Change the owner:group on the datadir
    1. chown mysql:mysql /full/path/to/mysql/data/dir
  5. Change the file permissions on the datadir
    1. chmod 755 /full/path/to/mysql/data/dir
  6. Start the database => service mysqld start
    1. Hold thumbs... :)

UPDATE *** 2011-07-21 ***