How to move MySQL to second drive | MyLiteratureTechLife.COM

How to move MySQL to second drive

January 6th, 2010 0 Comments






















If you ran out of space in your primary drive and wish to move MySQL to another drive then here is a simple procedure. Moving MySQL to another drive is very easy then it look.

1) Find out mount point of secondary drive.  If drive is not mounted yet then you can get help from article “How to mount drive in CentOS”

You can run below command to find mount point of secondary drive

df -h

It could be /dev/hdb or /dev/sdb and mount to (let suppose) /mydisk2

2) Stop Myqsl using command

# /etc/init.d/mysql stop    (for debian based linux)
OR
# service mysql stop     (for RH based linux)

3) Move MySQL files to second drive

# cp -R /var/lib/mysql/ /mydisk2/mysqldata

4) set permission on new mysql directory

# chown -R mysql.mysql /mydisk2/mysqldata/

5) remove or rename old mysql

# mv /var/lib/mysql/ /var/lib/mysql_old

6) Once data is moved to second drive, just create a symlink to it

# ln -s /mydisk2/mysql /var/lib/mysql

7) Now your data is moved, we will make changes in configuration file

# emacs /etc/my.cnf

8 ) Comment old line and add new

#datadir=/var/lib/mysql
datadir=/mydisk2/mysqldata
#socket=/var/lib/mysql/mysql.sock
socket=/mydisk2/mysqldata/mysql.sock
 
#basedir=/var/lib
basedir=/mydisk2

Save and exit

9) Start MySQL

# /etc/init.d/mysql start   (for debian based linux)
OR
# service mysqld start   (for RH based linux)

Thats all !!

Related posts:

  1. How to mount second hard drive in CentOS 5.x
  2. PHP script to test MySQL database Connection
  3. Advantages of choosing Linux web hosting
 

If You Like This Post, Share it With Your Friends & Peers

Digg
stumbleupon
Delicious
facebook
twitter
reddit
rss feed bookmar
 

No Comment to “How to move MySQL to second drive”

  1. No Comment yet. Be the first to comment...

Leave your comment here:

*

Alexa Rank