Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save blakesaunders/cdfe9a70ec534676637a754957748244 to your computer and use it in GitHub Desktop.
Save blakesaunders/cdfe9a70ec534676637a754957748244 to your computer and use it in GitHub Desktop.
Managing Multiple MySQL Versions with Homebrew

Multiple MySQL Versions with Homebrew

For Homebrew version 1.6.8.

brew -v # => Homebrew 1.6.8

Install the current version of mysql:

# Install current mysql version
brew install mysql

# Start agent for current version of mysql (including on login)
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Install the older version of mysql:

# Find older mysql versions
brew search mysql  

# Install older mysql version
brew install [email protected]

# Start agent for older version of mysql (including on login)
ln -sfv /usr/local/opt/[email protected]/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/[email protected]

Then to switch to the older version:

# Unlink current mysql version
brew unlink mysql

# Check older mysql version
ls /usr/local/Cellar/[email protected] # => 5.6.40

# Link the older version
brew switch [email protected] 5.6.40

And to switch back to the current version:

# Unlink older mysql version
brew unlink [email protected]

# Check current mysql version
ls /usr/local/Cellar/mysql # => 8.0.11

# Link the current version
brew switch mysql 8.0.11

To verify which mysql version you're on at any time.

# Check which version of mysql is currently symlinked
ls -l /usr/local/bin/mysql # => /usr/local/bin/mysql@ -> ../Cellar/[email protected]/5.6.40/bin/mysql

# Or using the mysql command
mysql --version

And to unload a mysql agent for a given version:

# Stop agent for current version of mysql
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

# Stop agent for older version of mysql
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql56.plist
rm ~/Library/LaunchAgents/[email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment