Skip to content

Instantly share code, notes, and snippets.

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

@irvv17
Copy link

irvv17 commented Jun 11, 2020

thanks, hate brew..

@PrerakMathur20
Copy link

PrerakMathur20 commented Mar 27, 2021

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

HunterRei commented May 9, 2021

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.

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