Stop the MySQL Service
I'm using Homebrew to stop the service
brew services stop mysql
Locate MySQL Data Directory
If you're using Homebrew, it should be located at
Go to the directory and make a backup for
homebrew.mxcl.mysql.plist and open
homebrew.mxcl.mysql.plist - either using nano or Sublime Text, doesn't matter.
Update Your Data Directory Path
Following are the default setting. All you need to do is to update the
/usr/local/var/mysql to the new path. Save the file.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>KeepAlive</key> <true/> <key>Label</key> <string>homebrew.mxcl.mysql</string> <key>ProgramArguments</key> <array> <string>/usr/local/opt/mysql/bin/mysqld_safe</string> <string>--bind-address=127.0.0.1</string> <string>--datadir=/usr/local/var/mysql</string> </array> <key>RunAtLoad</key> <true/> <key>WorkingDirectory</key> <string>/usr/local/var/mysql</string> </dict> </plist>
Copy the Old Databases
Make sure to copy all files under
/usr/local/var/mysql to new directory. You may use the following command to copy the files recursively.
cp -R /usr/local/var/mysql /your/new/path
Start the MySQL Service
Once you are done with above steps, do start the service.
brew services start mysql
Try to connect to the database, create a new database - see either the new database created in old directory
/usr/local/var/mysql or you new path.