I have a server where there are two RAID1 disks where the second disk is mounted on /mnt/data, having the MySQL database there would be great as it then would have a whole disk all by itself without having to share with other processes that read and write to the same disk. I/O is often the bottleneck and now we make sure it gets as good as it can be with the hardware we have.
First we will do the noatime trick to avoid things slowing down due to timestamp updates:
Make sure the noatime is there on the line of the disk in question:
/dev/sdb1 /mnt/data ext4 defaults,noatime 1 1
That was that, now let’s move the databases.
First we need to make sure apparmor allows the new location:
And add the following lines:
Copy the database directory (note the pr flag, very important to preserve ownership):
cp -pr /var/lib/mysql /mnt/data/
We open the MySQL config file:
And change the following line to point to our new directory:
datadir = /mnt/data/mysql
Remove these pesky logfiles that prevents MySQL from starting up after changing stuff: