Move MySQL to another *Nix disk

from the Artful MySQL Tips List

#Stop MySQL before moving its stuff around
shell> service mysql stop 
#Copy data folder to 2nd disk preserving its permissions
shell> cp -rp /var/lib/mysql /data 
#Create my.cnf by coping from sample .cnf file provided with MySQL installation
shell> cp /usr/share/mysql/my-huge.cnf /etc/my.cnf 
#Edit (shell> vi /etc/my.cnf) to fix paths for socket file, add data option
socket = /data/mysql/mysql.sock 
datadir   = /data/mysql 
socket = /data/mysql/mysql.sock 
#Start the server
shell> service mysql start 
#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 this ...
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 another problem you'll need to attend to.) #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 is not recommended. It is a berter solution to tell SELinux your new location for MySQL databases must have 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/ 
#This difference causes the error message at MySQL startup. Fix it. #Check whether you have policycoreutils-python package installed.
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/ 
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!
(Based on,520100,520469#msg-520469)

Last updated 30 Sep 2013

Return to the Artful MySQL Tips page