Skip to content

Instantly share code, notes, and snippets.

@robhrt7
Forked from nrollr/MySQL_macOS_Sierra.md
Last active October 12, 2024 02:48
Show Gist options
  • Save robhrt7/392614486ce4421063b9dece4dfe6c21 to your computer and use it in GitHub Desktop.
Save robhrt7/392614486ce4421063b9dece4dfe6c21 to your computer and use it in GitHub Desktop.
Install MySQL 5.7 on macOS using Homebrew

This is a fork of original gist https://gist.github.com/nrollr/3f57fc15ded7dddddcc4e82fe137b58e, with slight changes on pointing to 5.7 version branch, instead of 8 (latest default of MySQL in Hombrew).

Install MySQL 5.7 on macOS

This procedure explains how to install MySQL using Homebrew on macOS (Sierra 10.12 and up)

Install Homebrew

  • Installing Homebrew is effortless, open Terminal and enter :
    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Note: Homebrew will download and install Command Line Tools for Xcode 8.0 as part of the installation process.

Install MySQL

At this time of writing, Homebrew has MySQL version 8 as default, but as we're aiming to get 5.7, we'll need to append @5.7 to the default package key:

  • Enter the following command : $ brew info mysql@5.7
  • Expected output: mysql@5.7: stable 5.7.22 (bottled) [keg-only]

To install MySQL enter : $ brew install mysql@5.7

Additional configuration

Homebrew

  • Install brew services first : $ brew tap homebrew/services

  • Load and start the MySQL service : $ brew services start mysql@5.7.
    Expected output : Successfully started mysql (label: homebrew.mxcl.mysql)

  • Check of the MySQL service has been loaded : $ brew services list 1

  • Force link 5.7 version - $ brew link mysql@5.7 --force

  • Verify the installed MySQL instance : $ mysql -V.
    Expected output : Ver 14.14 Distrib 5.7.22, for osx10.13 (x86_64)

MySQL

Open Terminal and execute the following command to set the root password:
mysqladmin -u root password 'yourpassword'

Important : Use the single ‘quotes’ to surround the password and make sure to select a strong password!

Database Management

To manage your databases, I recommend using Sequel Pro, a MySQL management tool designed for macOS.
Current version available: 1.1.2

Comments

1 The brew services start mysql@5.7 - instruction is equal to :

$ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
@milo-lamar
Copy link

milo-lamar commented Aug 16, 2024 via email

@newtrat
Copy link

newtrat commented Aug 19, 2024

@ibadk5304 I was able to get part of the way to installing 5.7 again, but ended up reaching an error I couldn't resolve. Like Milo, I was able to switch to 8.0, but if you can't, I hope this might get you partway there:

  • Install Homebrew's packages locally: brew tap homebrew/core --force
  • open /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/m/mysql@5.7.rb and comment out the line disabling the formula (line 22). In my experience, Homebrew kept overwriting this change, so you might have better luck copying the file to some new name instead.
  • HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/m/mysql@5.7.rb Or use the new file copy if you created one in the last step.

This approach allowed MySQL to start installing, but I still ran into an error:

Error: An exception occurred within a child process:
  Errno::ENOENT: No such file or directory @ apply2files - /opt/homebrew/Cellar/mysql@5.7/5.7.44_1/data

... and I couldn't figure out how to solve that issue. The non-existent file here seems like it's something Homebrew is supposed to add during the installation process. When I created the file myself, Homebrew thought mysql@5.7 was "already installed."

@douglas
Copy link

douglas commented Aug 21, 2024

What I did here was to use instead mariadb@10.11, which is greatly compatible with MySQL 5.7 - so instead of using mysql@5.7 you can just use mariadb@10.11 to replace it 🎉

@Pezmc
Copy link

Pezmc commented Aug 26, 2024

brew tap homebrew/core --force
brew edit mysql@5.7
# Remove disable! line
HOMEBREW_NO_INSTALL_FROM_API=1 brew install mysql@5.7

@brobertsaz
Copy link

@Pezmc you solution worked great. I tried upgrading to mysql 8 and had issues but I had already uninstalled 5.7 :(

@EricFromCanada
Copy link

Error: An exception occurred within a child process:
  Errno::ENOENT: No such file or directory @ apply2files - /opt/homebrew/Cellar/mysql@5.7/5.7.44_1/data

@newtrat To fix this, follow instructions from @Pezmc and also add this just before the system "cmake" line:

mkdir prefix/"data"

@zbt78
Copy link

zbt78 commented Oct 12, 2024

HOMEBREW_NO_INSTALL_FROM_API=1 brew install mysql@5.7

this works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment