Moving mysql datadir to other location

Issues related to applications and software problems
okli
Posts: 2
Joined: 2011/08/29 07:57:46

Moving mysql datadir to other location

Post by okli » 2011/08/29 08:13:22

Hi,

I've spent very long time trying to move my mysql datadir from ist current location /var/lib/mysql to my /data partition without any luck. The problem as stated already in google is that SELinux denies the access to the new created datadir. I've followed some very good instructions provided to set the fscontext so that the filesystem will be accessible to mysql, but the access is still denied. Someone got this to work on CentOS 6 64bit with the provided mysql-5.1 version, as installed by yum install mysql-server mysql? I'm cosidering this is almost "stadard installation", so can someone here describe the necessary security options please. Any help will be highly appreciated.

TIA,
Ilko

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Moving mysql datadir to other location

Post by TrevorH » 2011/08/29 12:11:08

How about sharing with us the commands you ran to change the context and an `ls -laZ` of the current settings.

okli
Posts: 2
Joined: 2011/08/29 07:57:46

Re: Moving mysql datadir to other location

Post by okli » 2011/08/30 07:38:51

Hi, thanks for the reply and sorry for my delay. Unfortunately, I've re-installed the machine completely and replaced mysql with postgresql. Now I can define my data storage on /data/postgres and this "solves" my problem. OTOH, it will be interesting if someone can share the knowledge how this problem can be really solved on CentOS 6. As far as I can see others had success with this issue on 5.5, but I couldn't find anything regarding v6 so far.

Sorry for the noise and thanks again,
Ilko

sisko255
Posts: 6
Joined: 2011/09/06 09:14:54

Re: Moving mysql datadir to other location

Post by sisko255 » 2011/09/06 09:23:44

You are right ! SElinux will not allow to change default mysql database directory.


Have u tried something like :


[code] chcon -R system_u:object_r:mysqld_db_t /NEWDATABASEDIR/[/code] .

Maybe u have to modify this command to your needs .


Try [code] man chcon [/code] for more information !


Also check your user and file permissions or copy databases with cp -rp option to preserve user and file permissions

Cheers

Sisko

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Moving mysql datadir to other location

Post by TrevorH » 2011/09/06 11:30:17

Using chcon can be a bit dangerous because the changed context may be reset if the entire filesystem is relabeled at some point in the future. Better to look at using `semanage fcontext ...` as that puts persistent rules in place that a relabel uses.

sisko255
Posts: 6
Joined: 2011/09/06 09:14:54

Re: Moving mysql datadir to other location

Post by sisko255 » 2011/09/08 08:31:04

Does anybody know what default / core package has to be install for semanage ?

Cheers

Sisko

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Moving mysql datadir to other location

Post by TrevorH » 2011/09/08 09:35:30

[code]
# rpm -qf `which semanage`
policycoreutils-1.33.12-14.8.el5.x86_64
[/code]

sisko255
Posts: 6
Joined: 2011/09/06 09:14:54

Re: Moving mysql datadir to other location

Post by sisko255 » 2011/09/08 12:20:29

Interesting ..... it seems the policycoreutils.x86_64 (policycoreutils-2.0.83-19.8.el6_0.x86_64) does not include the semanage bin in my case.


Very strange ....

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Moving mysql datadir to other location

Post by TrevorH » 2011/09/08 12:41:30

Sorry, that was from my main CentOS 5 machine

[code]
# rpm -qf `which semanage`
policycoreutils-python-2.0.83-19.8.el6_0.i686
[/code]

sisko255
Posts: 6
Joined: 2011/09/06 09:14:54

Re: Moving mysql datadir to other location

Post by sisko255 » 2011/09/08 13:00:42

Thanks,

but this does not change my problem . It seems there is no binary called " semanage " in my policycoreutils-2.0.83-19.8.el6_0.x86_64 package. I installed the policycoreutils via yum . But still no semanage . That is very strange.


[code]
yum install policycoreutilsPackage policycoreutils-2.0.83-19.8.el6_0.x86_64

.... already installed and latest version


rpm -qf `which semanage`


/usr/bin/which: no semanage in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/open-xchange/sbin/:/root/bin)

find / |grep semanager

nothing found ! [/code]

I also did a yum remove of the package and yum install it again. To check if i deleted semanage without intention. - Still same problem .

Any Ideas ?

Cheers

Sisko

Post Reply