Mounting mysql on a second drive

***WARNING***

***WARNING***

***WARNING***

***WARNING***

***WARNING***

***WARNING***

***WARNING***


Use this guide at your own risk! Fdisk is a very powerful tool and can easily screw up a server if you are not careful. This guide was designed around a server that has SCSI disks and it is mounted in the secondary positions, sdb. If you have a ide drive it would be hdb.

This guide is pretty vague, that was done on purpose. It is very hard to do something like this if you are not familiar with linux and fdisk. I do not want people screwing around with this if they are not confident in what they are doing. I am just trying to stop people from getting mad at me. Anyways below is the guide it is to be used totaly at your own risk but I can say that if done correctly it will work just fine.

That all say here is the actual guide.


fdisk /dev/sdb

The first step is to delete all of the old partitions. If you have a lot of partitions you are going to have to keep trying to go to higher numbers. Once you have deleted all partitions it will say there are no paritions.

d --delete
1 -- partition 1
d
2
d
3
d
4

Create a new partition as /dev/sdb1
n -- new
p -- primary
1 -- first partition
<enter> -- use default cylinder value, which is the first available
+5000M -- make ~ a 5Gb partition which I think is a good size for a mysql database directory

Create a /tmp partition as /dev/sdb2 that will be ~1Gb
n
p
2
<enter>
+1000M

Create a backup partition as /dev/sdb3 which will take up whatever extra space the disk has.
n
p
3
<enter>
<enter> - uses the rest of the disk

w -- writes out and saves


Now we are going to format the filesystem as ext3 which is what most servers run with and is in my opinion the best choice.
mkfs -t ext3 /dev/sdb1
mkfs -t ext3 /dev/sdb2
mkfs -t ext3 /dev/sdb3


Now add the following in /etc/fstab so that they are mounted automatically on boot.

/dev/sdb1 /var/lib/mysql ext3 defaults,usrquota 1 1
/dev/sdb2 /tmp ex3 noexec,nosuid,rw 0 0
/dev/sdb3 /backup ext3 defaults 0 0


service mysql stop; killall -9 mysqld

Now copy the old dir so we can copy
mv /tmp /tmp_old; mkdir /tmp
mv /var/lib/mysql /var/lib/mysql_old; mkdir /var/lib/mysql

mount /var/lib/mysql
mount /tmp

cp -R /var/lib/mysql_old/* /var/lib/mysql/
chmod 755 /var/lib/mysql
chown mysql:mysql -R /var/lib/mysql


cp -R /tmp_old/* /tmp/
chmod 0777 /tmp


service mysql start

 

Hopefully it should all be working fine.

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

MySQL folder sharing on cPanel servers

Cool Stuff,

Something I was looking for many years, Thanks

This is very helpful.

Just want to ask three questions,

A) Is this setup will work with cPanel servers? (cPanel 11)
B) If so, will it overwrite by cPanel updates? Have you ecounterd any issues with cPanel server with this setup?
C) Can I share this MySQL folder with 2 cPanel servers through the NFS? So both servers chase same mysql setting and database.

Thanks again,

Neo Nash

Powered by Drupal - Theme created by Danger4k