I'm using Homebrew to stop the service
brew services stop mysql
If you're using Homebrew, it should be located at /usr/local/Cellar/mysql/[your-version]
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.
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>
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
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.
On mac,If /usr/local/mysql is soft connected,you can stop mysql, "cp -R mysql-5.** newDir", " ln -snf newDir /usr/local/mysql ","chown -R _mysql:_mysql newDir/data " ,start mysql.