Installing MySQL on OS X Mountain Lion

This post was published in 2012 and is kept here for reference. It may contain information that's outdated or inaccurate.

I was having some issues getting MySQL installed on OS X 10.8 Mountain Lion, and then I came across a useful article describing how to do it.

Here’s the important information from the article to install MySQL on OS X 10.8 Mountain Lion using Homebrew:

Install Homebrew

$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

Install MySQL using Homebrew

$ brew install mysql

Add MySQL to your LaunchAgents, so it can launch on startup

$ mkdir -p ~/Library/LaunchAgents
$ cp /usr/local/Cellar/mysql/5.5.27/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Unset TMPDIR (as this isn’t set to /tmp for non-root users) and install the MySQL system tables

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

Set the root password for MySQL

$ /usr/local/Cellar/mysql/5.5.27/bin/mysqladmin -u root password 'YOUR_NEW_PASSWORD'

And lastly, start MySQL

$ mysql.server start

This post is also available in plain text

[Archived comments]

Rob Bennet commented

Thanks for linking to the article. Glad you found it useful!

Pstinghua commented

thanks, but where is my.cnf? How to config remote access

Sergio Moya commented

Thanks!! works!

Juan Daniel Flórez commented

Thanks, I was missing the -w in launchctl that was driving me crazy

angelxmoreno commented

using mysql_install_db –verbose –user=whoami –basedir=”$(brew –prefix mysql)” –datadir=/usr/local/var/mysql –tmpdir=/tmpI get an error: -bash: mysql_install_db: command not found

[Comments]

Want to comment? You can do so via Github.
Comments via Github are currently closed.

[Webmentions]

Want to reply? I've hooked up Webmentions, so give it a go!