Skip to content

Instantly share code, notes, and snippets.

@nrollr
Last active September 19, 2024 08:26
Show Gist options
  • Save nrollr/3f57fc15ded7dddddcc4e82fe137b58e to your computer and use it in GitHub Desktop.
Save nrollr/3f57fc15ded7dddddcc4e82fe137b58e to your computer and use it in GitHub Desktop.
Install MySQL on Sierra using Homebrew

Install MySQL on macOS Sierra

This procedure explains how to install MySQL using Homebrew on macOS Sierra 10.12

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 5.7.15 as default formulae in its main repository :

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

To install MySQL enter : $ brew install mysql

Additional configuration

Homebrew

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

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

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

  • Verify the installed MySQL instance : $ mysql -V.
    Expected output : Ver 14.14 Distrib 5.7.15, for osx10.12 (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 - instruction is equal to :

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

Use brew install mysql --client-only install mysql client only

@areal060781
Copy link

No matter what I attempt I keep getting this error

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

I followed the above instructions:

Install MySQL

At this time of writing, Homebrew has MySQL version 5.7.15 as default formulae in its main repository :

Enter the following command : $ brew info mysql
Expected output: mysql: stable 5.7.15 (bottled)
To install MySQL enter : $ brew install mysql

Additional configuration

Homebrew

Install brew services first : $ brew tap homebrew/services

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

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

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

MySQL

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

I still get this error :

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

Please help.

mysql_upgrade -u root

@ov-i
Copy link

ov-i commented Nov 2, 2018

Thank you a lot!

@jannejava
Copy link

jannejava commented Nov 9, 2018

MySQL8 seems to be the default version now. Be aware that Sequel Pro seems to have some problems connecting and does not support MySQL 8. https://gist.github.com/operatino/392614486ce4421063b9dece4dfe6c21

@praveenthrilanka
Copy link

Thank you

@jonsoa
Copy link

jonsoa commented Nov 22, 2018

Thank you guy, it was very helpful!!

@Pareshoct7
Copy link

Pareshoct7 commented Dec 6, 2018

@fabionofre Thanks for the crystal clear solution.

I applied solution from this video.

https://youtu.be/isFl1SGKuKM

Hope this helps, If anyone wants to use a mysql installation file.

but that is not enough. So, I have to follow your answer also @fabionofre

laradock/laradock#1392 (comment)

@dan-u
Copy link

dan-u commented Jan 24, 2019

Helpful, thanks!

@caquillo07
Copy link

caquillo07 commented Feb 11, 2019

None of the above worked for me, if you are still getting the socket error this worked for me:

  1. remove /usr/local/var/mysql/
  2. uninstall mysql
  3. install mysql

Seems like I had 5.7 previously installed, then uninstalled it and my fresh installation was not working properly.

@superlbr
Copy link

superlbr commented May 25, 2019

modify owner of mysql_upgrade_info in /usr/local/var/mysql, to solve the issue of /tmp/mysql.sock'

@rdp
Copy link

rdp commented Jun 23, 2019

You no longer have to install services manually via brew tap homebrew/services FWIW...

@zhouyanlt
Copy link

Thanks!

@joshuabalduff
Copy link

Thanks bro

@joeljpa
Copy link

joeljpa commented Oct 3, 2019

This is what's needed from a coolestguides link above:

Fix the looming 2002 socket error – which is linking where MySQL places the socket and where macOS thinks it should be, MySQL puts it in /tmp and macOS looks for it in /var/mysql the socket is a type of file that allows mysql client/server communication.

sudo mkdir /var/mysql

Then

sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

I second this. After my upgrade from High Sierra to Mojave, symlinking was the one step I had to do to fix my local LAMP projects for running. I broke my head on this for a good full day and quick searching didn't provide what I wanted. My specific case: brew handling apache2, mysql5.7 while php being the stock (php7*)...shipped with OS X. Mysql was running smoothly on its own via CLI, just that my php apps weren't handling mysql.

@irving-caamal
Copy link

thanks, hate brew..

@PrerakMathur20
Copy link

NOTE the -u and -p.....they have no spaces. This worked for me.
sudo mysql -uroot -ppassword

Thank You so much. This really Helped!!

@HunterRei
Copy link

Can someone help me with "mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root-ppassword'@'localhost' (using password: NO)'" cause I can't seem to move forward from here.

@RealEmmettS
Copy link

RealEmmettS commented Jan 19, 2023

If you need help following these instructions on an Apple Silicon Mac, use these modified instructions.

I've also included a few scripts to automate some bothersome everyday tasks. The scripts are executable using the Shortcuts app (Shortcuts was developed by Apple and is currently available on the Mac App Store).

@mlevin77
Copy link

mlevin77 commented Jan 29, 2023 via email

@lain0
Copy link

lain0 commented Sep 11, 2024

How to install [email protected] and [email protected] with brew in 2024:

1 ) Edit local brew folmula files - delete line: deprecate! date: "2023-09-11", because: :unsupported

  1. install mysql-client with only local brew files
HOMEBREW_NO_INSTALL_FROM_API=1  brew install [email protected] [email protected]
# and intall ruby gem mysql2 0.5.4 for mysql 5.7:
gem install mysql2 -v 0.5.4 -- --with-openssl-dir=$(brew --prefix [email protected])  -- --with-mysql-dir=/usr/local/opt/[email protected]/

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