/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?
- Stop MySQL
- Move MySQL data from
- 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.
Ideally, you'd give it it's own mountpoint on it's own partition, which can be mounted to
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.
- 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.