Moving MySQL databases to a Different Location
Friday, May 1st, 2009I decided to try to move my own MySQL database files to a different location on an external hard drive. This is for MySQL on Mac OS X 10.5. The original database files are located at /usr/local/mysql/data. Here are the steps I took:
1. Stopped the MySQL server. You can do this using the System Preferences MySQL pane, or you can do it like so:
mysqladmin -p shutdown
Then give it your MySQL root user password and the MySQL server will shut down.
2. Became the system root user.
3. copied the /usr/local/mysql/data directory and all of its files and subdirectories to the new location at /Volumes/Elements1TB/mydbs/ like so:
cd /Volumes/Elements1TB/mydbs
cp -R /usr/local/mysql/data .
4. Added a line to my /etc/my.cnf file. My /etc/my.cnf file now looks like this:
[mysqld]
max_allowed_packet=200M
connect_timeout=60
datadir=/Volumes/Elements1TB/mydbs/data/
5. Navigated to the /Volumes/Elements1TB/mydbs/ directory and executed this command:
chown -R _mysql:wheel data
6. Started the MySQL server. Again, you can do this with the System Preferences MySQL pane or you can do it like this:
mysqld_safe &