Create a gist now

Instantly share code, notes, and snippets.

@nrollr /MySQL.md
Last active Mar 22, 2017

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

@iplus26
iplus26 commented Jul 30, 2016 edited

Thanks for your guide!

For some one might be here, if you ran into ERROR 1045 (28000): Access denied for user 'Ivan'@'localhost' (using password: NO) like me, try this: mysql -v -uroot -pYourpasswordhere.

@TheRojam

this is a great How-To and works fine even in Mac OS X El Capitan! 👍

@beritou
beritou commented Aug 15, 2016

@nrollr thank you for this Gist. Please consider updating it for v5.7.14 as per my fork

@rdp
rdp commented Oct 20, 2016

latest seems to be just "brew install mysql" then homebrew itself outputs instructions on how to install the daemon/change the root password (FWIW)...

@frankdejonge

Alternatively, to start mysql one could also use brew services (brew tap homebrew/services):

brew install mysql
brew services start mysql
@hassanabidpk
hassanabidpk commented Jan 22, 2017 edited

I tried mysqladmin -u root password 'yourpassword' and mysql -v -uroot -pYourpasswordhere on MACOS Sierra but still getting the error ERROR 1045 (28000): Access denied for user 'root'@'localhost' Anyone facing similar problem ?

@Carromattsson

Thank you!!

@gwokudasam

Thanks a lot

@james-prado

I followed the instructions thoroughly, entered mysql -v into terminal, and got a weird error ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

@amfische
amfische commented Feb 15, 2017 edited

I received the same error as james-prado. All I ran was brew install mysql

This article helped me solve my problem:
http://stackoverflow.com/questions/15016376/cant-connect-to-local-mysql-server-through-socket-homebrew

@gpinkham

is there a way to install only the cli client?

@tejasmanohar

same problem as @hassanabidpk. no luck

@khadkaPratik

@hassanabidpk and @tejasmanohar hope this helps.
Just type following in your terminal instead
Note : -u represent your mysql username which is root in my case and -p represent password

mysql -uroot -p
Enter password:

@collinhaines

Seeing some people on here run into problems with using mysql -uroot -p. If you didn't set up a password, try entering a blank one.

Source: The last 5 minutes of my life.

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