How to Move MySQL Database Data Directory
Thursday, July 28, 2011 EDT (Updated on: Sunday, January 29, 2012 EST)
by: Eric Potvin
Tags:ubuntulinuxmysql
If for some reason your database expands at a high rate, you might need to consider to move your data to another disk. Here's a simple trick on how to move the MySQL database directory to another location or drive.
First stop the mysql service :
sudo /etc/init.d/mysql stop
Create new MySQL directory
sudo mkdir /path/to/new/mysql
Move the data from the current data directory to new data directory.
sudo mv /var/lib/mysql /path/to/new/mysql
Or
sudo cp -R /var/lib/mysql/* /path/to/new/mysql/
Assign the MySQL group and owner for the new data directory.
chown -R mysql:mysql /data/mysql
Edit the my.cnf file to update the new path
sudo vi /etc/mysql/my.cnf
Look for:
datadir = /var/lib/mysql
and update to:
datadir = /path/to/new/mysql
Restart the mysql deamon (best during off-peak hours in case of errors)
sudo /etc/init.d/mysqld restart
After few days or weeks if you feel confident and everything is good you can remove the old data:
sudo rm -rf /var/lib/mysql
Link to this Article
To link directly to this article from your web site, use one of the following snippets below.
How to Move MySQL Database Data Directory | Book Of Zeus<a href="http://www.bookofzeus.com/articles/how-to-move-mysql-database-data-directory/" title="How to Move MySQL Database Data Directory">How to Move MySQL Database Data Directory | Book Of Zeus</a>
Short URL:
How to Move MySQL Database Data Directory | Book Of Zeus<a href="http://s.bookofzeus.com/8XZyW" title="How to Move MySQL Database Data Directory Short URL">How to Move MySQL Database Data Directory | Book Of Zeus</a>