/var/lib/mysql is mounted on partition / which is now full. Is there a way to mount this under /home/mysql for more disk space?
Asked
Active
Viewed 4,684 times
2 Answers
1
- Stop MySQL
- Move MySQL data from
/var/lib/mysql
to/home/mysql
- Point MySQL to the new data directory
- Start MySQL
It could be implemented like this (WARNING: not tested)
/etc/init.d/mysql stop
mv /var/lib/mysql /home/.
ln -s /home/mysql /var/lib/mysql
/etc/init.d/mysql start
Always have a backup before you start moving the data directory.

pkhamre
- 6,120
- 3
- 17
- 27
-
Running this now! :D – Tiffany Walker Oct 25 '12 at 12:28
0
Ideally, you'd give it it's own mountpoint on it's own partition, which can be mounted to /var/lib/mysql
.
Failing that, you do have the option of using a loopback filesystem, though it definitely does introduce some I/O delays that MySQL may notice. Only you can know if increasing I/O latencies a bit will harm your expected performance.
The rough procedure....
- Use dd to create a loopback file somewhere.
dd if=/dev/zero of=/home/mysql/datavol bs=1M count=4096
- Attach the file to a loopback device
losetup /dev/loop0 /home/mysql/datavol
- Format the device as you will.
mkfs.ext3 /dev/loop0
- Mount it somewhere
mount /dev/loop0 /mnt
- Copy your data
cp -a /var/lib/mysql/ /mnt/
- Other methods may be used, this is just one.
- Clear /var/lib/mysql
- Remount to /var/lib/mysql
umount /mnt ; mount /dev/loop0 /var/lib/mysql
- Ensure that directory is owned by the right user
chown mysql:mysql /var/lib/mysql
At that point, you should have a larger /var/lib/mysql actually hosted from your larger partition.

sysadmin1138
- 133,124
- 18
- 176
- 300