Moved my MySQL data directory onto it's own drive last night. Went pretty smoothly with only a couple minutes of down time. For my records, here's what I did. In my case I'm changing it from the stock /var/lib/mysql location to /data/mysql.

Make a copy of MySQL conf file in case anything goes horribly wrong and we need to revert to where we were:
cp /etc/my.cnf /etc/my.cnf.bak
Edit my.cnf and in the [mysqld] section change
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
to
datadir=/data/mysql
socket=/data/mysql/mysql.sock
Then in the [mysql.server] section change
basedir=/var/lib
to
basedir=/data
Save /etc/my.cnf when done. Then do
service mysqld stop
rsync -vrplogDtH /var/lib/mysql/ /data/mysql/
to stop MySQL (so no data gets lost while we are changing locations) and then rsync to copy all the data to the new location. Then here's where I'm not 100% sure, but after one false start where I couldn't connect to MySQL after starting it up at this point I did it all again adding this step after the rsync:
ln -s /data/mysql/mysql.sock /var/lib/mysql/mysql.sock
to create a link in the new data location to the old mysql.sock (which is what a client uses to connect to the database.) Then just:
service mysqld start
Works fine although I'd like to understand better about having to link mysql.sock. I would think this wouldn't be necessary since my.cnf should contain enough info to figure out where the socket is. But maybe other things on the system expect it to be in /var/lib/mysql? I guess that's the case since it seems like you need that link.
- jim 9-18-2009 3:58 pm




add a comment to this page:

Your post will be captioned "posted by anonymous,"
or you may enter a guest username below:


Line breaks work. HTML tags will be stripped.