coding

Install MySQL on Mac OS X 10.7+

The no fuss, no muss guide to installing the latest stable version of MySQL DB locally on your Mac running OS X 10.7 or later. (Hat tip to Trey Piepmeier for his excellent tutorial, upon which I improved a few things.)

Install MySQL (using Homebrew)

I’ll assume you’ve already installed Homebrew.

Assuming you have your brew command ready to rock, make sure to run a quick brew update, telling brew to fetch the latest packages:

Update brew to ensure you have the latest library of packages (install scripts):
brew update

OK? Good. Now you need to tell brew to install MySQL by entering this command:

brew install mysql

Enter the following two commands, one after the other (the second one starts up your new, local MySQL server and creates an initial database):

unset TMPDIR
mysql_install_db --verbose --user=$(whoami) --basedir=$(brew --prefix mysql) --datadir=/usr/local/var/mysql --tmpdir=/tmp

Launch MySQL Automatically

The output from that last command should instruct you to enter three additional commands. (The ones below might not be exactly what you see in your terminal. Of course, make sure you follow those instructions and not these below, unless they’re identical.):

mkdir -p ~/Library/LaunchAgents
cp $(brew --prefix mysql)/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

The three commands above do the following, respectively: create a LaunchAgents folder for you if you don’t already have one, copy the mysql.plist file into that launch folder, and then loads that file into a system file so that Mac OS X starts MySQL for you each time you restart your machine. Perfect!

Start Configuring MySQL

One final (optional) step is to run the included MySQL root/user config script. It’ll step you through various default username/password/etc options that you might want to configure now that you’ve got MySQL up and running on your machine. To run this automated post-MySQL-install wizard, enter:

$(brew --prefix mysql)/bin/mysql_secure_installation

Or, perhaps you’re interested in Installing and Setting up PostgreSQL on Mac OS X?

Install Homebrew on Mac OS X 10.7+

How to Install Homebrew on Mac OS X (10.7 or later)

This one’s super-quick and easy! If you want to easily install other tools and add-ons in the future, you need Homebrew.

Open a new shell and run the following:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

It’s that simple. Really.

Homebrew Future Tip

Once Homebrew has finished installing, you’ll want to make sure to always run the following before trying to install anything using the brew command:

brew update

Running Brew’s update command instructs it to fetch the latest install recipes from its remote repository. Remember: Before you use Brew to install something, you definitely want to run the brew update command Every single time! That way, you’ll always ensure you’re installing only the latest, stable packages.

That’s it! You’re done.

Want to learn more about Brew on your own? Check out: http://brew.sh/