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.
1 Answer 1
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.
-
Hi Ahmad, Thank you for your suggestion. I changed the permission for /mysql to 755. The owner and group are mysql:mysql There is no bin folder in /mysql. /mysql is my data directory is and I modified /etc/my.cfn (datadir=/mysql) to point to that. I tried starting the service after the permission change but I am still getting the same error. Here is a listing of what is in /mysql folder. -rwxr-xr-x. 1 mysql mysql 56 Dec 23 00:00 auto.cnf drwxr-xr-x. 2 mysql mysql 4096 Dec 23 00:00 mysql drwxr-xr-x. 2 mysql mysql 4096 Dec 23 00:00 performance_schema Thank you again.Grace– Grace2014年12月23日 18:18:48 +00:00Commented Dec 23, 2014 at 18:18
-
did you installed MySQL via yum or apt-get command? or extract the compressed file?Ahmad Abuhasna– Ahmad Abuhasna2014年12月24日 10:43:39 +00:00Commented Dec 24, 2014 at 10:43
-
Hi Ahmad, Thank you! I installed via yum and I found the mysqld file to start it. This worked - ./mysqld --defaults-file=/etc/my.cnf --user=mysql &Grace– Grace2014年12月27日 03:40:00 +00:00Commented Dec 27, 2014 at 3:40
-
Hi Ahmad, how do I safely shutdown this instance of mysql short of using killing the pid? Is there anyway I can start mysql for the encrypted folders using the service mysqld commands? Thank you.Grace– Grace2014年12月27日 04:20:38 +00:00Commented Dec 27, 2014 at 4:20
-
1Hi Grace, please refer to my edit in the answer section aboveAhmad Abuhasna– Ahmad Abuhasna2014年12月29日 12:17:48 +00:00Commented Dec 29, 2014 at 12:17
mysqld_db_t
and after encryption this is gone. Instead of itecryptfs_t
is present. Try turning selinux off or better - set it temporarily into permissive mode withsetenforce 0
. If mysql starts, check selinux logs what it is complainging about.