Mysql – Cannot start MySQL service on linux RHEL when pointing datadir to mounted ecryptfs folder

linuxMySQL

I moved the data directory for MySQL to an ecryptfs encrypted folder.
When I run service mysqld start as root, the service will not start.

[Warning] Can't create test file /mysql/ip-172-31-29-184.lower-test
^G/usr/sbin/mysqld: Can't change dir to '/mysql/' (Errcode: 13 - Permission denied)

When it used to start before my encrypting the folder

ls -lZ /mysql outputs

drwx------. mysql mysql unconfined_u:object_r:mysqld_db_t:s0 mysql

now

ls -lZ /mysql outputs
drwx------. mysql mysql system_u:object_r:ecryptfs_t:s0  mysql

I think the issue is with how I mounted the encrypted directory.
mount -t ecryptfs /mysql /mysql

mount outputs

/mysql on /mysql type ecryptfs
 (rw,ecryptfs_sig=6860c372da7bc418,ecryptfs_cipher=aes,ecryptfs_key_bytes=16,ecryptfs_unlink_sigs)

I am running Red Hat Enterprise Linux Server release 6.6 (Santiago), MySQL 5.6.22

Any advice is appreciated. Thank you for your help in advance.

Best Answer

Make sure the MySQL server owner is MySQL:MySQL using chown -R mysql:mysql /mysql and the permission level is 755 for everything except my.cnf 644. chmod 644 my.cnf then execute the following commands after changing the information inside my.cnf to the correct one.

cd /mysql/bin
./mysqld --defaults-file=/mysql/my.cnf --user=mysql &

Edit to answer the comment below To shutdown MySQL safely without killing the SID (or PID) you can use one of the following commands:

/usr/local/mysql/bin/mysqladmin -u root -p shutdown 

or

sudo mysqld stop

note: in-case you can more than SID running you need to specify the port for it.