Skip to content

Instantly share code, notes, and snippets.

@nrollr
Last active October 28, 2020 02:53
Show Gist options
  • Save nrollr/a8d156206fa1e53c6cd6 to your computer and use it in GitHub Desktop.
Save nrollr/a8d156206fa1e53c6cd6 to your computer and use it in GitHub Desktop.
Install MySQL on El Capitan using Homebrew

Install MySQL on OS X El Capitan

Normally the installation of MySQL can be achieved with a single command, which executes a script provided by MacMiniVault : bash <(curl -Ls http://git.io/eUx7rg)

However, at the time of writing the script is not compatible with OS X El Capitan (10.11)

Install MySQL using Homebrew

An alternative to the aforementioned installation script is installing MySQL using Homebrew. This gist assumes you already have Homebrew installed, if not first read the article "Homebrew and El Capitan"

Make sure Homebrew has the latest formulae, so run brew update first
-OR- make sure Homebrew has MySQL version 5.6.27 as default formulae in its main repository :

  • Enter the following command : brew info mysql
  • Expected output: mysql: stable 5.6.27 (bottled)

Next install MySQL with : brew install mysql

###Additional configuration Open Terminal and execute the following commands :

  • To have launchd start mysql at login :
    ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
  • To load mysql immediately :
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  • Finally add the mysql directory to your PATH environment variable in .bash_profile :
export MYSQL_PATH=/usr/local/Cellar/mysql/5.6.27  
export PATH=$PATH:$MYSQL_PATH/bin
  • Reload shell and type mysql -v to confirm
    Expected output : Server version: 5.6.27 Homebrew
    Quit the mysql CLI via mysql> \q

###Configure 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 OS X

@svaponi
Copy link

svaponi commented Sep 17, 2017

If you have this error:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Type mysql -uroot -p and as password type exactly yourpassword (not your actual sudo password). It works ;)

@morenoh149
Copy link

Great document! I'm a fan of https://dbeaver.jkiss.org/ as a database GUI.

@tarantsoff
Copy link

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
yourpassword - doesn't work

@tarantsoff
Copy link

mysqladmin -u root password 'yourpassword'
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

@ViniciusPaldes
Copy link

Thanks for guide.

@innokenty same for me, it was crashing for me after installing from brew and type mysql.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Just start server and works. mysql.server start then mysql

@speedtreammanga
Copy link

@amfische , thanks buddy!

@ricketybridge
Copy link

Thank you so much!!!

@suzanmanchandia
Copy link

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES/NO)

Solution-
While running the installation command -> bash <(curl -Ls http://git.io/eUx7rg)
system autogenerates a password, look for line 'Setting MySQL root password to '

Use this password to connect to mysql -> mysql -uroot -p

@sktrinh12
Copy link

When I type in brew install mysql I am getting: mysql: macOS Sierra or newer is required. Error: An unsatisfied requirement failed this build. Anyone run into this issue? If so, what did you do to successfully install mysql?

@pirkka
Copy link

pirkka commented Jan 7, 2019

When I type in brew install mysql I am getting: mysql: macOS Sierra or newer is required. Error: An unsatisfied requirement failed this build. Anyone run into this issue? If so, what did you do to successfully install mysql?

You need to specify an older version that is compatible with your operating system, for example:

brew install [email protected]

To see what versions are available, use this command:

brew search mysql

@rahulkathet
Copy link

Thanks
Works for me

@zakirsajib
Copy link

zakirsajib commented May 22, 2019

whatever version i try to install it says following

Updating Homebrew...
Warning: You are using macOS 10.11.
We (and Apple) do not provide support for this old version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience, as you are running this old version.
Error: The following formula
[email protected]
cannot be installed as binary package and must be built from source.
Install the Command Line Tools:
xcode-select --install

If I type mysql command, it says:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

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