Create a gist now

Instantly share code, notes, and snippets.

@nrollr /MySQL.md
Last active Jul 14, 2018

Embed
What would you like to do?
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

This comment has been minimized.

Show comment
Hide comment
@iplus26

iplus26 Jul 30, 2016

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.

iplus26 commented Jul 30, 2016

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 comment has been minimized.

Show comment
Hide comment
@TheRojam

TheRojam Aug 15, 2016

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

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

@beritou

This comment has been minimized.

Show comment
Hide comment
@beritou

beritou Aug 15, 2016

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

beritou commented Aug 15, 2016

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

@rdp

This comment has been minimized.

Show comment
Hide comment
@rdp

rdp 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)...

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

This comment has been minimized.

Show comment
Hide comment
@frankdejonge

frankdejonge Dec 30, 2016

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

brew install mysql
brew services start mysql

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

brew install mysql
brew services start mysql
@hassanabidpk

This comment has been minimized.

Show comment
Hide comment
@hassanabidpk

hassanabidpk Jan 22, 2017

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 ?

hassanabidpk commented Jan 22, 2017

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

This comment has been minimized.

Show comment
Hide comment

Thank you!!

@gwokudasam

This comment has been minimized.

Show comment
Hide comment
@gwokudasam

gwokudasam Feb 2, 2017

Thanks a lot

Thanks a lot

@james-prado

This comment has been minimized.

Show comment
Hide comment
@james-prado

james-prado Feb 9, 2017

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)

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

This comment has been minimized.

Show comment
Hide comment
@amfische

amfische Feb 15, 2017

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

amfische commented Feb 15, 2017

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

This comment has been minimized.

Show comment
Hide comment
@gpinkham

gpinkham Feb 15, 2017

is there a way to install only the cli client?

is there a way to install only the cli client?

@tejasmanohar

This comment has been minimized.

Show comment
Hide comment
@tejasmanohar

tejasmanohar Mar 2, 2017

same problem as @hassanabidpk. no luck

same problem as @hassanabidpk. no luck

@khadkaPratik

This comment has been minimized.

Show comment
Hide comment
@khadkaPratik

khadkaPratik Mar 11, 2017

@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:

@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

This comment has been minimized.

Show comment
Hide comment
@collinhaines

collinhaines Mar 22, 2017

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.

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.

@innokenty

This comment has been minimized.

Show comment
Hide comment
@innokenty

innokenty Mar 29, 2017

Right after I installed it with homebrew I get this:

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

UPD: mysql --version works by the way!

innokenty commented Mar 29, 2017

Right after I installed it with homebrew I get this:

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

UPD: mysql --version works by the way!

@rubi0

This comment has been minimized.

Show comment
Hide comment
@rubi0

rubi0 May 7, 2017

For those having ERROR 1045 (28000): Access denied for user 'x'@'localhost' (using password: NO) just do sudo mysql -v ...

rubi0 commented May 7, 2017

For those having ERROR 1045 (28000): Access denied for user 'x'@'localhost' (using password: NO) just do sudo mysql -v ...

@abhsrivastava

This comment has been minimized.

Show comment
Hide comment
@abhsrivastava

abhsrivastava May 9, 2017

for me everything works fine locally. but when I try to connect remotely. I get error

ERROR 2003 (HY000): Can't connect to MySQL server on '10.15.52.125' (61)

I can connect using the same user locally. I have already disabled firewall.

for me everything works fine locally. but when I try to connect remotely. I get error

ERROR 2003 (HY000): Can't connect to MySQL server on '10.15.52.125' (61)

I can connect using the same user locally. I have already disabled firewall.

@jotacedesigner

This comment has been minimized.

Show comment
Hide comment
@jotacedesigner

jotacedesigner Jun 23, 2017

if you have this problem ERROR 1045 (28000): Access denied for user 'x'@'localhost' (using password: NO),
###Configure MySQL Open Terminal and execute the following command to set the root password:
mysqladmin -u root password 'yourpassword'.
And crate a alias for mi work this:
The alias create in your bash_profile in your terminal:
nano ~/.bash_profile
When open paste this:
alias mysql='/usr/local/Cellar/mysql/5.7.18_1/bin/mysql -u root -p'

jotacedesigner commented Jun 23, 2017

if you have this problem ERROR 1045 (28000): Access denied for user 'x'@'localhost' (using password: NO),
###Configure MySQL Open Terminal and execute the following command to set the root password:
mysqladmin -u root password 'yourpassword'.
And crate a alias for mi work this:
The alias create in your bash_profile in your terminal:
nano ~/.bash_profile
When open paste this:
alias mysql='/usr/local/Cellar/mysql/5.7.18_1/bin/mysql -u root -p'

@marcelolfilho

This comment has been minimized.

Show comment
Hide comment
@marcelolfilho

marcelolfilho Jun 29, 2017

yeah not working for me either...

yeah not working for me either...

@JamesTheHacker

This comment has been minimized.

Show comment
Hide comment
@JamesTheHacker

JamesTheHacker Aug 1, 2017

People are likely having issues because the OP has set the path wrong. Rather than doing:

export MYSQL_PATH=/usr/local/Cellar/mysql/5.6.27  
export PATH=$PATH:$MYSQL_PATH/bin

It should be:

export MYSQL_PATH=/usr/local/Cellar/mysql/5.6.27  
export PATH=$MYSQL_PATH/bin:$PATH

... See how the $PATH is added to the end. If you don't do this when you call mysql it's going to load the version installed with OSX. You can test this by doing which mysql ... it should show /usr/local/Cellar/mysql/5.7.19/bin/mysql when you set the path correctly.

JamesTheHacker commented Aug 1, 2017

People are likely having issues because the OP has set the path wrong. Rather than doing:

export MYSQL_PATH=/usr/local/Cellar/mysql/5.6.27  
export PATH=$PATH:$MYSQL_PATH/bin

It should be:

export MYSQL_PATH=/usr/local/Cellar/mysql/5.6.27  
export PATH=$MYSQL_PATH/bin:$PATH

... See how the $PATH is added to the end. If you don't do this when you call mysql it's going to load the version installed with OSX. You can test this by doing which mysql ... it should show /usr/local/Cellar/mysql/5.7.19/bin/mysql when you set the path correctly.

@svaponi

This comment has been minimized.

Show comment
Hide comment
@svaponi

svaponi 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 ;)

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

This comment has been minimized.

Show comment
Hide comment
@morenoh149

morenoh149 Oct 24, 2017

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

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

@tarantsoff

This comment has been minimized.

Show comment
Hide comment
@tarantsoff

tarantsoff Dec 29, 2017

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

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

@tarantsoff

This comment has been minimized.

Show comment
Hide comment
@tarantsoff

tarantsoff Dec 29, 2017

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

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

@ViniciusPaldes

This comment has been minimized.

Show comment
Hide comment
@ViniciusPaldes

ViniciusPaldes Jan 15, 2018

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

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

This comment has been minimized.

Show comment
Hide comment

@amfische , thanks buddy!

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