MySQL Forums
Forum List  »  Newbie

[SOLVED !!!] - Re: Moved datadir and now get: ERROR! The server quit without updating PID file
Posted by: Roman Shuvalov
Date: March 16, 2012 04:36PM

Hi, All.

So, yeah - that was SELinux on.

I fixed it, I believe, in a fairly correct way. So, the procedure of moving MySQL databases to a "larger disk" on a system with SELinux on described below. The post does not describe the concepts behind SELinux etc., because I am a newbie in the subject and do not understand them well, so you should refer other resources on the SELinux. This is just a step-by-step solution on the problem I lost a week on, so may be you will find it useful if you have something similar...

Ok, I did it on a virtual machine, so my box is:

VMWare Workstation 7.1.5
CentOS 6.2 (x64)
MySQL 5.5.21

I assume you want to move MySQL databases from its default location (/var/lib/mysql) to another disk mounted to /data, such that you new datadir would be /data/mysql

So start your terminal and type shell commands (# - preceeds my comments, shell> - preceeds to what you type):

#Stop MySQL before moving its stuff around
shell> service mysql stop

#Copy data folder to a "larger disk" preserving its permissions
shell> cp -rp /var/lib/mysql /data

#Create my.cnf by coping from some of the sample .cnf files provided with MySQL installation
#I took "huge", you can take any one whichever suites your situation best:
shell> cp /usr/share/mysql/my-huge.cnf /etc/my.cnf

#Edit (shell> vi /etc/my.cnf) by fixing paths for socket file and adding datadir option into [mysqld] section and fixing .


socket = /data/mysql/mysql.sock
datadir = /data/mysql
socket = /data/mysql/mysql.sock


#Now starting the server
shell> service mysql start

#O-ops! Getting error message ?
Starting MySQL.. ERROR! The server quit without updating PID file (/data/mysql/

#Checking MySQL status returns this error ?
shell> service mysql status
ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists

#Error log is not updated at all ? (/data/mysql/master.home.err)

#If that all happens to you, than most probably the issue is caused by SELinux.
#You can double-check whether you have it ON. If you see output below:

shell> sestatus

SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted

#then you have SELinux on.
#(If you see that SELinux is disabled, then probably you have some other root cause and the rest of the post will not be a solution for you.)

#You can turn SELinux off by editing file (/etc/selinux/config - update -> SELINUX=disabled , save, reboot)
#but this will reduce the security of your system and generally not recommended.

#So, better solution is to tell to SELinux, that your new location for MySQL databases must have been
#applied the proper security context (the one used for MySQL databases).

#Check the security type of default database folder and new location:

shell> ls -dZ /var/lib/mysql
drwxr-xr-x. mysql mysql system_u:object_r:mysqld_db_t:s0 /var/lib/mysql/

shell> ls -dZ /data/mysql
drwxr-xr-x. mysql mysql system_u:object_r:default_t:s0 /data/mysql/

#See the difference ? This difference causes the error message at MySQL startup. So, lets go and fix it!

#Check, whether you have policycoreutils-python package installed. If not - install it.
shell> yum install policycoreutils-python

#Map proper security context definition to new db locaion
shell> semanage fcontext --add --type mysqld_db_t '/data/mysql(/.*)?'

#Label new db location by security context just defined:
shell> restorecon -r /data/mysql

#Check whether you have got proper labeling for new db location:
shell> ls -dZ /data/mysql
drwxr-xr-x. mysql mysql system_u:object_r:mysqld_db_t:s0 /data/mysql/

#Basically, you are done! Reboot
shell> reboot

#After reboot you should have MySQL running ok:
shell> service mysql status
SUCCESS! MySQL running (2006)

#Also you should be able restart it successfully:
shell> service mysql restart
Shutting down MySQL. SUCCESS!
Starting MySQL.. SUCCESS!


I hope this will save you a day!

Good luck,

Options: ReplyQuote

Written By
[SOLVED !!!] - Re: Moved datadir and now get: ERROR! The server quit without updating PID file
March 16, 2012 04:36PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.