0

I've a server with CentOS 6.3 and Mysql installed on. I've created two partition, one for system and the bigger one for data mounted in /data Right after installed Mysql I've created the dir /data/mysql then as root I changed the selinux context of this folder typing chcon -R -t mysqld_db_t /data/mysql and modified the Mysql configuration file (my.cnf) to this:

[mysqld] datadir=/data/mysql socket=/data/mysql/mysql.sock user=mysql symbolic-link=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid 

but now i can't start mysqld service! It give me Can't change dir to /data/mysql (errcode 13)

This is the output of the ls -Z /data | grep mysql:

drwxr-xr-x. mysql mysql system_u:object_r:mysqld_db_t:s0 mysql 

The strange thing is that every time I try to start the mysqld service and it fails the context of myslq dir become system_u:object_r:default_t:s0 and two dirs (mysql and test) are created in it.

Anyway if I disable selinux evreything works great....

2 Answers 2

1

You need to use semanage fcontext to set the default file context for your non-standard location for the MySQL databases.

semanage fcontext -a -t mysqld_db_t "/data/mysql(/.*)?" 

Once done, use restorecon to fix any mislabeled files/directories:

restorecon -r -v /data/mysql 

Now you should have no further SELinux issues.

-4

I have the same problem, and I solved:

The problem is permission, my.cnf execute mysqld whit user mysql [mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
user=mysql
symbolic-link=0

Then I move used mysql files and references all over /var/lib/mysql/, then I modified:

/etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
[mysqld_safe]
log-error=/var/lib/mysql/mysqld.log
pid-file=/var/lib/mysql/mysqld.pid

/etc/init.d/mysqld

get_mysql_option mysqld datadir "/var/lib/mysql"
datadir="$result"
get_mysql_option mysqld socket "$datadir/mysql.sock"
socketfile="$result"
get_mysql_option mysqld_safe log-error "/var/lib/mysql/mysqld.log"
errlogfile="$result"
get_mysql_option mysqld_safe pid-file "/var/lib/mysql/mysqld.pid"
mypidfile="$result"
.
.
.
fi [ $ret -eq 0 ] && touch /var/lib/mysql/mysqld.lock (this and another reference to lock file.)
return $ret

I change the name of mysql lock file by mysqld.lock in /etc/init.d/mysqld but is not necesary.

finally I change owner of /var/lib/mysql chown mysql:mysql /var/lib/mysql -R

and set permissions:

chmod 755 /var/lib/mysql -R

now

/etc/init.d/mysqld start

2
  • 2
    You do not seem to have the same problem as the person who posted this question. Commented Dec 28, 2012 at 22:10
  • You're absolutely right, it's just like, because the error that I was getting in mysqld.log was the same. Commented Dec 29, 2012 at 12:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.