Setup Multiple MySql’s with homebrew in Mac local machine
Had a specific scenario in my projects where two services are using MySql
but different versions. So had to switch between different MySql
versions on demand.
- Will try to support for brew version For homebrew version 0.9.5.
-v # => Homebrew 0.9.5 brew
- Install the current/latest version of mysql.
# Install current mysql version
brew install mysql
)
# Start agent for current version of mysql (including on login-sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
ln /Library/LaunchAgents/homebrew.mxcl.mysql.plist launchctl load ~
- Install the older/Specific version of mysql.
# Find older mysql versions
brew search mysql
# Install older mysql version/versions/mysql56
brew install homebrew
)
# Start agent for older version of mysql (including on login-sfv /usr/local/opt/mysql56/*.plist ~/Library/LaunchAgents
ln /Library/LaunchAgents/homebrew.mxcl.mysql56.plist launchctl load ~
- Then to switch to the older version.
# Unlink current mysql version
brew unlink mysql
# Check older mysql version/usr/local/Cellar/mysql56 # => 5.6.27
ls
# Link the older version brew switch mysql56 5.6.27
- switch back to the current version.
# Unlink older mysql version
brew unlink mysql56
# Check current mysql version/usr/local/Cellar/mysql # => 5.7.10
ls
# Link the current version brew switch mysql 5.7.10
- Verify which mysql version you’re on at any time.
# Check which version of mysql is currently symlinked-l /usr/local/bin/mysql # => /usr/local/bin/mysql@ -> ../Cellar/mysql56/5.6.27/bin/mysql
ls
# Or using the mysql command-version mysql -
- unload a mysql agent for a given version.
# Stop agent for current version of mysql/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
rm ~
# Stop agent for older version of mysql/Library/LaunchAgents/homebrew.mxcl.mysql56.plist
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql56.plist rm ~