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
1 |
df -h |
It could be /dev/hdb or /dev/sdb and mount to (let suppose) /mydisk2
2) Stop Myqsl using command
1 2 3 |
# /etc/init.d/mysql stop (for debian based linux) OR # service mysql stop (for RH based linux) |
3) Move MySQL files to second drive
1 |
# cp -R /var/lib/mysql/ /mydisk2/mysqldata |
4) set permission on new mysql directory
1 |
# chown -R mysql.mysql /mydisk2/mysqldata/ |
5) remove or rename old mysql
1 |
# mv /var/lib/mysql/ /var/lib/mysql_old |
6) Once data is moved to second drive, just create a symlink to it
1 |
# ln -s /mydisk2/mysql /var/lib/mysql |
7) Now your data is moved, we will make changes in configuration file
1 |
# emacs /etc/my.cnf |
8 ) Comment old line and add new
1 2 3 4 5 6 7 |
#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
1 2 3 |
# /etc/init.d/mysql start (for debian based linux) OR # service mysqld start (for RH based linux) |
Thats all !!
Thank you!