Change MySQL Database Location

General Information

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.

Requirements

  1. Local root access on the box or be able to su to root.
  2. A SSH client that supports ANSI colors such as puTTy or SecureCRT (if you aren’t on the box).
  3. Your favorite text editor (I like nano).
  4. MySQL installed.

Configuration

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

Note: Change /path/to/dir to wherever you want the new databases to be stored.

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.

Speak Your Mind

*