Pages

Wednesday, August 25, 2010

Changing mysql data directory to protect db corruption

Changing mysql data directory to protect db corruption


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:
Open the my.cnf file
#vi /etc/mysql/my.cnf
--- change your new directory path
datadir=/usr/local/mysql/ #old - /var/lib/mysql/
Step 3:
Create a /home/mysql directory and give required permission to mysql users
mkdir /usr/local/mysql
chown -R mysql /usr/local/mysql
chgrp -R mysql /usr/local/mysql
Copy data and preserve permissions, etc.
cp -Rp /var/lib/mysql/* /usr/local/mysql
Step 4:
Start the mysql service
/etc/init.d/mysql start




Cheers!!!!!

No comments: