Changing mysql data directory to protect db corruption

Published July 16, 2009 by Siva

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

Advertisements

2 comments on “Changing mysql data directory to protect db corruption

  • Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s

    %d bloggers like this: