Post Reply  Post Thread 
[Optimization] How To: Move MySQL on a second drive
Pacifier
Administrator
*******

Posts: 222
Group: Administrators
Joined: May 2006
Status: Offline
Reputation: 1
Post: #1
[Optimization] How To: Move MySQL on a second drive

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.

06-01-2006 02:01 PM
Find all posts by this user Quote this message in a reply
Pepo
Junior Member
**

Posts: 9
Group: Registered
Joined: Jan 2007
Status: Offline
Reputation: 0
Post: #2
RE: [Optimization] How To: Move MySQL on a second drive

thanks mate for this great article Smile


تطوير منتديات ماى بى بى - اشهار المواقع - cheap web host
01-21-2008 01:34 PM
Find all posts by this user Quote this message in a reply
Johny
Junior Member
**

Posts: 2
Group: Registered
Joined: Oct 2008
Status: Offline
Reputation: 0
Post: #3
RE: [Optimization] How To: Move MySQL on a second drive

Thanks !! great Tutorial.

10-26-2008 11:58 PM
Find all posts by this user Quote this message in a reply
Stenna1
Junior Member
**

Posts: 2
Group: Registered
Joined: Sep 2009
Status: Offline
Reputation: 0
Post: #4
RE: [Optimization] How To: Move MySQL on a second drive

great article. Thanks for the same.

Keep on posting nice tutorials like this.


New Zealand Car Rental
Auckland Car Rental
New Zealand Car Hire
Car Hire New Zealand
09-08-2009 03:22 AM
Find all posts by this user Quote this message in a reply
welllyn07
Junior Member
**

Posts: 1
Group: Registered
Joined: Oct 2009
Status: Offline
Reputation: 0
Post: #5
RE: [Optimization] How To: Move MySQL on a second drive

That's it, I'm done! If MySQL isn't accessed heavily and instead you just want to move some of your very popular content, you can also 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. I hope it also helps!




___________________________________
Multivariate Testing

10-10-2009 05:44 AM

This post was last modified: 11-29-2009 05:17 PM by welllyn07.

Find all posts by this user Quote this message in a reply
drmostafa88
Junior Member
**

Posts: 2
Group: Registered
Joined: Feb 2010
Status: Offline
Reputation: 0
Post: #6
RE: [Optimization] How To: Move MySQL on a second drive

thanks alot for the great articles

02-04-2010 01:32 PM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: