Linux and Windows System Administrators Stuffs

July 16, 2009

Changing mysql data directory to protect db corruption

Filed under: Mysql — Tags: , , — siva2009 @ 10:07 am

MySQL data are located under /var/lib/mysql by default, which could cause a problem to corrupt huge database.

Here the steps to change the data directory

Step1 :

To stop mysql deamon, simply drop the command line

/etc/init.d/mysql stop

Step 2:

to open the my.cnf file

#whereis my.cnf

#vim /etc/mysql/my.cnf (this is my server location…it may change…)

datadir=/home/mysql/ #was /var/lib/mysql/

Step 3:

Create a /home/mysql directory and give clearance to mysql

mkdir /home/mysql
chown -R mysql /home/mysql
chgrp -R mysql /home/mysql

Copy data and preserve permissions, etc.

cp -Rp /var/lib/mysql/* /home/mysql/

Step 4

Start the mysql service

/etc/init.d/mysql start

Regards
Siva

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.