In my last article, I mentioned that you can decrease I/O usage and hence decrease the load on the server making it run faster, by moving MySQL to a second drive. If your server disk's I/O usage is very high, it's either due to a kernel fault (specificially, 2.6.9-xx kernels) or your disk is being accessed heavily. In such a situation, you should spread the load onto multiple drives.
If your server is using much MySQL, then it would be wise to move MySQL to a second drive. (Provided the second drive isn't busy as well!)
Note: This how to is written with linux in mind although it may work on many other *nix operating systems
I) Do you really need to move MySQL to a second disk?
Please check my last article title "Server overloading explained" and find out if your I/O usage is high. If it is higher than what you may consider normal, then follow on with the how to.
II) Mount point - Where is the second disk mounted?
You need to know where your second disk is mounted (obviously, you aren't throwing your data away in the space, are you?). If you aren't sure about your disk's mount point, then run the following command:
# df -h
It should show you the output which can help you identify the mount point of your disk. Make sure you can differentiate between disks. /dev/hdaX are usually the parititions of the main disk, while /dev/hdb or /dev/hdc are commonly used for secondary drives.
Teaching you how to mount is beyond the scope of this How To. Step to our Server Optimization & Help section to get help with mounting a second disk.
III) Move MySQL data to the second disk!
Now that you have identified your mount point of the second disk, you can move the data over. It should take some time to move data from your main disk to the second disk so make sure you do it at an off-peak time.
a) Stop the MySQL service
# service mysqld stop
b) Move data from your main disk to second disk (please make sure there is no directory named "mysql" in /disk2/ -- Replace /disk2/ with the mount point of your secondary disk)
# mv /var/lib/mysql /disk2/
c) Create a symlink (Replace /disk2/ with the mount point of your secondary disk)
# ln -s /disk2/mysql /var/lib/mysql
d) Restart MySQL now
# service mysqld start
That's it, you're done! If MySQL isn't accessed heavily and instead you want to move some of your very popular content, you can do that in a similar manner. Basically, all you need to do is copy the data over to the second disk and create a symlink from the previous location to the new one.
Author and Copyright
Asad Niazi is currently studying for Bachelors in Computer Sciences with passionate interest in PHP coding and Server Optimization.
Copyright 2006, Asad Niazi & SpiceFuse. May not be republished in any form without permission.