Changing MySQL data directory in CentOS is a very 6 simple steps.
You need root access to your CentOS. Login and do followings
- stop the mysql
123
#
# /etc/init.d/mysqld stop
#
- copy all the current data to your destination directory (you need to decide where you want to move your mysql data)
123
#
# cp /var/lib/mysql/ /mysqldata/mysql/ -R
#
- give your new directory proper rights
123
#
# chown mysql.mysql /mysqldata/mysql/ -R
#
- Add new directory path to you my.cnf
0102030405060708091011121314
# nano /etc/my.cnf
#
#
[mysqld]
#datadir=/var/lib/mysql
datadir=/mysqldata/mysql/
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
see the highlighted lines we changed the “datadir” to our new Path.
- Optional you should remove or atleast rename the actual MySQL directory. Just to make sure that you are using new data directory
123
#
# mv /var/lib/mysql /var/lib/mysql_ORIGNAL
#
- Start Mysql
123
#
# /etc/init.d/mysqld start
#
No Comments Yet