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.

    # 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
      
    # Find older mysql versions
    brew search mysql  
      
    # Install older mysql version
    brew install homebrew/versions/mysql56
    
    # Start agent for older version of mysql (including on login)
    ln -sfv /usr/local/opt/mysql56/*.plist ~/Library/LaunchAgents
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql56.plist
    # Unlink current mysql version
    brew unlink mysql 
    
    # Check older mysql version
    ls /usr/local/Cellar/mysql56 # => 5.6.27
    
    # Link the older version
    brew switch mysql56 5.6.27
    # Unlink older mysql version
    brew unlink mysql56 
    
    # Check current mysql version
    ls /usr/local/Cellar/mysql # => 5.7.10
    
    # Link the current version
    brew switch mysql 5.7.10
    # Check which version of mysql is currently symlinked
    ls -l /usr/local/bin/mysql # => /usr/local/bin/mysql@ -> ../Cellar/mysql56/5.6.27/bin/mysql
    
    # Or using the mysql command
    mysql --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/homebrew.mxcl.mysql56.plist