How to Install MySQL on Mac OSX
This should be really straightforward, but I found myself googling around. I wrote a recent post about how to create a web app with the Laravel PHP framework but connecting to the database was tricky.
First step, find out what version of OS X you are running. Click the apple icon in the top right corner of your screen and click “About This Mac”. I got something like this:
Next step, head over to the MySQL downloads page.
So with my computer I am running 10.11 and we want the .dmg file. Download Mac OS X 10.10 (x86, 64-bit), DMG Archive. Then you get to this lame screen:
MySQL is free and open source software (FOSS), you do not need to sign up or create an account. Click “No thanks, just start my download”. I let the download go directly to my “Downloads” folder when prompted, though you could place it anywhere. The download will take some time because it is 350mb, go get a coffee. Once the download is complete. Double click the file and a screen like this will open
Double click it and go through the install process.
When I did it I got an alert box:
Add to path. This went in ~/.zshrc because I am using ZSH. If you are using bash for terminal (the default on OS X) this will be the ~/.bashrc file or ~/.bash_profile. This post explains the difference between the two files.
$ sublime ~/.zshrc
$ source ~/.zshrc
Add the mysql download to your path so that you can use the “mysql” command from the command line.
Then test it out:
$ mysql — version
mysql Ver 14.14 Distrib 5.7.10, for osx10.9 (x86_64) using EditLine wrapper
When trying to login to MySQL on OSX recently I ran into the following error:
$ mysql -u root -p
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
There are a lot of StackOverflow threads and articles about this, many require writing SQL commands, though that was difficult for me without access to the terminal. In order to alleiviate this I found this SO answer that saved me:
$ /usr/local/mysql/bin/mysqladmin -u root -p password
Confirm new password:
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.