Skip to content

Instantly share code, notes, and snippets.

@robhrt7
Forked from nrollr/MySQL_macOS_Sierra.md
Last active October 5, 2025 11:57
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:

To install MySQL enter : $ brew install [email protected]

Additional configuration

Homebrew

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

  • Load and start the MySQL service : $ brew services start [email protected].
    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 [email protected] --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 [email protected] - instruction is equal to :

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

nima-z commented Nov 5, 2022

Thank you, It worked on macOS Monterey.

@claide
Copy link

claide commented Mar 23, 2023

Not working for me on mac os m2 ventura.

I did start [email protected] and gives me Successfully started [email protected] (label: [email protected]) message. But, when I tried to view the list of services to check if it's really started, I got this status below which is stopped.

image

@minily
Copy link

minily commented Feb 28, 2024

much good!

@milo-lamar
Copy link

Any suggestions since 2024-08-01?
% brew install [email protected] Error: [email protected] has been disabled because it is not supported upstream! It will be disabled on 2024-08-01.

@ibadk5304
Copy link

@milo-lamar Have you managed to resolve this

@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/[email protected] 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/[email protected] 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/[email protected]/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 [email protected] was "already installed."

@douglas
Copy link

douglas commented Aug 21, 2024

What I did here was to use instead [email protected], which is greatly compatible with MySQL 5.7 - so instead of using [email protected] you can just use [email protected] to replace it 🎉

@Pezmc
Copy link

Pezmc commented Aug 26, 2024

brew tap homebrew/core --force
brew edit [email protected]
# Remove disable! line
HOMEBREW_NO_INSTALL_FROM_API=1 brew install [email protected]

@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/[email protected]/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 [email protected]

this works for me!

@andrew-bierman
Copy link

Thanks, everyone, for this thread! The steps from @Pezmc worked great for me. The only change I had to make was updating depends_on "[email protected]" to depends_on "openssl@3" when modifying the mysql formula in my set up.

I didn’t experience any breaking changes with this patch, but your mileage may vary.

@zenHeart
Copy link

zenHeart commented Nov 19, 2024

Finally make mysql5.7 work on my m3 chip mac.

  1. make sure you have uninstalled all other version mysql , follow this gist
brew remove mysql
rm -rf /opt/homebrew/var/mysql
  1. follow @newtrat instruction
brew tap homebrew/core --force
brew edit [email protected]
  1. use a old install rb script replace ,like this version https://github.com/Homebrew/homebrew-core/blob/c73c9d6baacb82c60df84cb07c1fe6209438cfc1/Formula/m/mysql%405.7.rb
  2. now use HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/m/[email protected] to install from source
  3. when install, Maybe throw error likeError: [email protected] has been disabled because it is not supported upstream! It was disabled on 2024-10-24., use same way . brew edit [email protected] to comment this line # disable! date: "2024-10-24", because: :unsupported
  4. after step5 ,now install [email protected] from source code HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/o/[email protected]
  5. after success install openssl ,reinstall [email protected] follow step 4
  6. just wait, mysql compilation will takes some time
  7. after mysql5.7 install success just start use brew brew services start [email protected]
  8. use brew services list check mysql start success
  9. if not ,read cat /opt/homebrew/var/mysql/${HOST}.err file to check the error
  10. if throw like Table 'mysql.plugin' doesn't exist follow this
brew services stop [email protected]
rm -rf /opt/homebrew/var/mysql
mysqld --initialize-insecure --user=`whoami`
brew services start [email protected]
  1. enjoy it

@himanshu-disney
Copy link

Just what @Pezmc did but instead of what @andrew-bierman said to change openssl version in the mysql formulae we edit the openssl 1.1 formula instead.

List of Steps

Force tap the homebrew core tap
Edit the mysql 5.7 formula to remove the disable line
mysql5.7 depends on openssl 1.1
edit openssl 1.1 as well using same way as above
and then use HOMEBREW_NO_INSTALL_FROM_API=1 to use the locally edited formulae
Then run-
brew install [email protected]

@ferrucc-io
Copy link

ferrucc-io commented Sep 9, 2025

This doesn't work for me anymore because

The brew tap homebrew/core --force doesn't work because MySQL 5.7 was completely removed from the repository, not just disabled.

See https://github.com/Homebrew/homebrew-core/blob/main/Formula/m/mysql%405.7.rb

What worked for me was running:
brew tap homebrew/core --force

Then placing the formula that was previously there in: /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/m

Did this doing:

sudo curl -fL "https://raw.githubusercontent.com/Homebrew/homebrew-core/6c907880b95a3702348c1fcce1c661fcc03336e5/Formula/m/mysql%405.7.rb" \
  -o "/opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/m/[email protected]"

Followed by this to remove the disable from the formula:

sudo sed -i '' '/disable! date: "2024-08-01", because: :unsupported/d' /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/m/[email protected]

And you need to do the same for [email protected]:

sudo curl -fL "https://raw.githubusercontent.com/Homebrew/homebrew-core/6c907880b95a3702348c1fcce1c661fcc03336e5/Formula/o/openssl%401.1.rb" \
  -o "/opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/o/[email protected]"
 
 sudo sed -i '' '/disable! date: "2024-10-24", because: :unsupported/d' /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/o/[email protected]

Note, if the previous steps fails because of missing directories not existing you might also need to create them for both (sudo mkdir -p "/opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/o" and sudo mkdir -p "/opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/m"`)

Then you can install both mysql and openssl like:

brew tap-new local/old-openssl
cp /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/o/[email protected] \
   $(brew --repository local/old-openssl)/Formula/[email protected]
brew install local/old-openssl/[email protected]

brew tap-new local/old-mysql
cp /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/m/[email protected] \
   $(brew --repository local/old-mysql)/Formula/[email protected]
brew install local/old-mysql/[email protected]

brew install local/old-mysql/[email protected]

@nivank7
Copy link

nivank7 commented Sep 10, 2025

@ferrucc-io trying the same workaround but it does not work on sequoia, which OS are you using?

@damekolla2
Copy link

damekolla2 commented Sep 18, 2025

@ferrucc-io trying the same workaround but it does not work on sequoia, which OS are you using?

  1. First, make sure you’ve run brew tap homebrew/core --force, then follow ferrucc-io’s article step by step (I’ve removed all the sudo commands).
  2. After finishing those steps, remember to run echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc and source ~/.zshrc
  3. Run brew services start local/old-mysql/[email protected] to start, then can run mysql_secure_installation to continue with the remaining setup.

Thanks to @ferrucc-io , I was able to install MySQL 5.7.44 on my MBP (M1 Pro), macOS 26.0 (Tahoe).

@ferrucc-io
Copy link

I'm on a MBP M4 Max running Sequoia @nivank7 if that's helpful

@daffaromero
Copy link

This doesn't work for me anymore because

The brew tap homebrew/core --force doesn't work because MySQL 5.7 was completely removed from the repository, not just disabled.

See https://github.com/Homebrew/homebrew-core/blob/main/Formula/m/mysql%405.7.rb

What worked for me was running: brew tap homebrew/core --force

Then placing the formula that was previously there in: /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/m

Did this doing:

sudo curl -fL "https://raw.githubusercontent.com/Homebrew/homebrew-core/6c907880b95a3702348c1fcce1c661fcc03336e5/Formula/m/mysql%405.7.rb" \
  -o "/opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/m/[email protected]"

Followed by this to remove the disable from the formula:

sudo sed -i '' '/disable! date: "2024-08-01", because: :unsupported/d' /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/m/[email protected]

And you need to do the same for [email protected]:

sudo curl -fL "https://raw.githubusercontent.com/Homebrew/homebrew-core/6c907880b95a3702348c1fcce1c661fcc03336e5/Formula/o/openssl%401.1.rb" \
  -o "/opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/o/[email protected]"
 
 sudo sed -i '' '/disable! date: "2024-10-24", because: :unsupported/d' /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/o/[email protected]

Note, if the previous steps fails because of missing directories not existing you might also need to create them for both (sudo mkdir -p "/opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/o" and sudo mkdir -p "/opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/m"`)

Then you can install both mysql and openssl like:

brew tap-new local/old-openssl
cp /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/o/[email protected] \
   $(brew --repository local/old-openssl)/Formula/[email protected]
brew install local/old-openssl/[email protected]

brew tap-new local/old-mysql
cp /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/m/[email protected] \
   $(brew --repository local/old-mysql)/Formula/[email protected]
brew install local/old-mysql/[email protected]

brew install local/old-mysql/[email protected]

FWIW, this still works by October 2025 on my M1 MacBook Pro (2020) running Sequoia 15.6.1. Thanks @ferrucc-io!

@oleksandr133
Copy link

oleksandr133 commented Oct 5, 2025

This doesn't work for me anymore because
The brew tap homebrew/core --force doesn't work because MySQL 5.7 was completely removed from the repository, not just disabled.

Thanks, its working!

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