Moving my MySQL data files to a separate new partition in Linode.
This page is just really for my own notes… BACKUP YOUR DB AND SETTINGS FILES FIRST!
(Ubuntu 11.10)
Original database directory: /var/lib/mysql/
New directory: /srv/mysql/
- Log in to your Linode Manager
- Create the new disk image
- Label: /srv
- Type: ext3
- Size: size needed for database (10000MB)
- Click Create Image and wait for it to finish in the queue
- Click edit for your ‘Configuration Profile’
- Under ‘Block Device Assignment’ assign the next available /dev/xvdX device to the newly created disk image
- /dev/xvdc = /srv (The label you chose earlier)
- Click Save Changes
- You will need to reboot your server for it to see the new disk image so click “Reboot”
- Once it boots, log into it with a terminal
- Add the new disk image to /etc/fstab so it will auto mount at boot
/dev/xvdc /srv ext3 defaults 0 2 - Mount it
mount /srv - Shutdown the mysql dameon.
-
service mysql stop
-
- Edit the MySQL config file: /etc/mysql/my.cnf
- Change the datadir to the new location inside the [mysqld] section
- datadir = /var/lib/mysql
- to
- datadir = /srv/mysql
- If the server is using AppArmor then add in the following lines to /etc/apparmor.d/usr.sbin.mysqld
/srv/mysql/ r,
/srv/mysql/** rwk, - Restart AppArmor
service apparmor restart - Move the datadir to its new location
mv /var/lib/mysql/ /srv/ - Make a symlink just in case
ln -s /srv/mysql /var/lib/mysql - Now startup mysql
service mysql start
old stats:
$df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda 9.7G 4.9G 4.4G 54% / devtmpfs 249M 4.0K 249M 1% /dev none 50M 164K 50M 1% /run none 5.0M 0 5.0M 0% /run/lock none 249M 0 249M 0% /run/shm
$ cat /fstab # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> dev /dev devtmpfs rw 0 0 proc /proc proc defaults 0 0 /dev/xvda / ext3 noatime,errors=remount-ro 0 1 /dev/xvdb none swap sw 0 0
new stats:
$ df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda 5.8G 1.4G 4.2G 26% / devtmpfs 248M 4.0K 248M 1% /dev none 50M 168K 50M 1% /run none 5.0M 0 5.0M 0% /run/lock none 249M 0 249M 0% /run/shm /dev/xvdc 9.7G 3.7G 5.9G 39% /srv
$ cat /etc/fstab # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> dev /dev devtmpfs rw 0 0 proc /proc proc defaults 0 0 /dev/xvda / ext3 noatime,errors=remount-ro 0 1 /dev/xvdb none swap sw 0 0 /dev/xvdc /srv ext3 defaults 0 2