The default location for your MySQL database data files may need to be moved to another partition that offers more storage space, or you may want to keep your data organized. These simple steps allows you to move your MySQL data without losing any information.
- Local root access on the box or be able to su to root.
- A SSH client that supports ANSI colors such as puTTy or SecureCRT (if you aren’t on the box).
- Your favorite text editor (I like nano).
- MySQL installed.
Changing where the databases are stored is quite simple. Just stop the running MySQL processes:
# /usr/local/etc/rc.d/mysql-server.sh stop
Then edit /etc/rc.conf:
# echo 'mysql_dbdir="/path/to/dir"' >> /etc/rc.conf
Copy the existing MySQL databases (including the master mysql database):
# cp -R /var/db/mysql/* /path/to/dir
Now start MySQL:
# /usr/local/etc/rc.d/mysql-server.sh start
All of your databases are now residing in /path/to/dir.