Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm working on a Debian machine with a bunch of different filesystems and I'm trying to manipulate a large amount of data in MySQL. I've run out of room in my home directory, but there's a ton of empty space in other systems (particularly one that's located in /srv). I want to make it so that /var/lib/mysql (the directory that stores MySQL data) seems to still be in its rightful location, but all of its data is stored in /srv/mysql. How can I do this?

share|improve this question
add comment

1 Answer

First, move or copy /var/lib/mysql to /srv/mysql.

$ mv -i /var/lib/mysql /srv
$ cp -ir /var/lib/mysql /srv

You may want to use a bind mount instead of a symbolic link. Bind mounts won't break in special roots.

$ mkdir /var/lib/mysql
$ mount --bind /srv/mysql /var/lib/mysql

if you decide to use a symbolic link, remove the old /var/lib/mysql directory and run the following.

$ ln -s /srv/mysql /var/lib/mysql
share|improve this answer
    
When I try that ln -s command I get: "ln: failed to create symbolic link `/var/lib/mysql/mysql': File exists". It may have something to do with the fact that /var/lib/mysql/mysql is a directory, but that seems like an error that shouldn't be happening regardless. –  Mike Jun 24 '13 at 17:10
    
You have to remove the old directory first. Make sure its contents have been copied to the new location (/srv/mysql) and run rm -r /var/lib/mysql. –  Evan Teitelman Jun 24 '13 at 17:12
    
It seems like it worked, but MySQL no longer recognizes any of the databases and gives me an Error 1006 errno 2 when I try to make one. –  Mike Jun 24 '13 at 17:43
    
Try using a bind mount instead. Delete the symlink (rm /var/lib/mysql), make a new directory there (mkdir /var/lib/mysql), and bind mount the new directory on the old one (mount --bind /srv/mysql /var/lib/mysql). –  Evan Teitelman Jun 24 '13 at 17:49
    
You'll have to add the mount to your /etc/fstab file for it to mount on boot. This line should work: /srv/mysql /var/lib/mysql bind defaults,bind 0 0. You could also change your mysql configuration to point to the new directory. Though, that may cause problems if you're using administration utilities that expect to find your mysql data at /var/lib/mysql. –  Evan Teitelman Jun 24 '13 at 17:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.