Install MySQL on Mountain Lion with Homebrew


I recently upgraded to Mountain Lion and like every good little nerd, I did 7 pass writing of zeros to my harddrive.  In other words, I erased the crap out of it and created a fresh install.  A lot of people complain this is quite annoying as you have to reinstall and re-setup everything on your Mac.  I actually enjoy it because it gives me a clean slate and a chance to de-clutter my machine and do fresh installs and configs of all my software.  If you develop locally, one of the issues you’re going to run into is that you need to get MySQL, PHP, Ruby, Python, etc… and Apache all running again.  Like I said before, one of the nice things about starting fresh is that you can try new things.  One thing I have vowed to do this go around is pull all of my packages and installs down with Homebrew.  So let’s get started.

Update: 2-23-2013
After setting up a new machine today I realized this post uses an old version of MySQL from the Homebrew registry. If you were running into trouble with some of the code snippets it is because the post is making the assumption that Homebrew is pulling down MySQL version 5.5.25a, but currently Homebrew installs 5.6.10 (as of this update). I’ve updated the code snippets below, but be sure to check what version is being pulled down in the future. I also ran into an issue with trying to access localhost from PHP scripts and realized php.ini was the culprit. If you’re using the Homebrew package for MySQL and the default php.ini file (located in /etc/php.ini) then your trying to connect through the default_socket at /var/mysql/mysql.sock which very well might not exist depending on your situation. You can do one of two things, replace all occurrences of


with this instead


or alternatively if you don’t want to mess with the php.ini you could just run a symlink like so

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

You might need to create the /var/mysql directory if it doesn’t exist. Hope that helps someone.

First we need to open up our trusty Terminal app and install Homebrew.  This is pretty darn simple thanks to ruby and git, just run the following command:

ruby <(curl -fsSk

This will pull down Homebrew and get it all installed and running for you. It will prompt you to press enter after it shows you what it’s going to do. The great thing about Homebrew and the reason I will be using it is because of it’s modularity. It creates it’s own little “house” of packages and code that keeps everything quite tidy. So now that we have Homebrew, we can extremely simply pull down the newest copy of MySQL by running the following command:

$ brew install mysql

Yep, it’s that easy. Now, out of the box you won’t be up and running MySQL queries quite yet. You need to run a few more commands to get things situated. I like to have the mysql server start on startup and to do so you would run the following commands:

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

You’ll also need to unset the temp directory 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

And lastly you’ll want to reset the root password

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

Now you are ready to start the sql server and run your first query:

$ mysql.server start
$ mysql

Doesn’t get much easier than this. Share your thoughts in the comments on how to get things back into running order after a fresh install.

80 Responses to Install MySQL on Mountain Lion with Homebrew

Jason says: August 16, 2012 at 11:49 pm

Nice article! How would I go about doing this without using Homebrew? Is there an easy way to do it without using Terminal?

Rob says: August 16, 2012 at 11:54 pm

Thanks Jason. If you didn’t want to use Homebrew (though I suggest you do) you could pull down mysql using wget, curl or some other similar method. You could also just hit this page to download it manually and install it yourself, but this would be a tutorial unto itself. Thanks for the interest!

Gregg says: August 24, 2012 at 12:26 am

Thanks for this nice recipe. Everything works fine except that when I try

/usr/local/Cellar/mysql/5.5.25a/bin/mysqladmin -u root password ‘YOUR_NEW_PASSWORD’

mysql returns with

error: ‘Access denied for user ‘root’@'localhost’ (using password: NO)’

Any tips?


Rob Bennet says: August 24, 2012 at 12:55 am

There are multiple reasons this could be happening, the most likely reason is that you have an older version of mysql installed before you did the brew install. There are a few ways to go about fixing this, but this thread on StackOverflow should get you where you need to be. Thanks for reading!

Cailen says: November 24, 2012 at 8:21 pm

This was helpful, thank you Rob.

In response to @Gregg’s particular enquiry, the stdout upon installing the mysql system tables supplies a different path than that which you did, namely:

/usr/local/opt/mysql/bin/mysqladmin -u root password ‘new-password’

I suspect Gregg may not have read all of the output in his commandline while following your directions.


Pablo says: October 10, 2012 at 5:57 pm

Thanks for the great post! If you have time, would you mind explaining what’s going on when running unset TMPDIR and mysql_install_db?

Rick Roberts says: October 18, 2012 at 6:10 pm

Hey, Rob. I’m having trouble getting automysqlbackup working now. Seems directories aren’t where they are expected. Any ideas?

Matt Hauth says: November 4, 2012 at 7:42 pm

FYI Homebrew will change versions. Some newbies like myself might not notice they need to change the mysql version when trying to run the CP as well as setting a new root password.

Hopefully this helps someone. I found the current version by cd /usr/local/Cellar/mysql/


diek says: November 19, 2012 at 2:16 am

Thanks for the post. The most current mysql download from homebrew creates 5.5.27, vice 5.5.25a. Prob what caused the error for Rick above. The folder is 5.5.27.


Jared says: November 30, 2012 at 3:05 pm

Thanks for the post. I am a RedHat admin type working on understanding Mac. I need to get the mysql service to boot upon system start/reboot. I very much like hombrew to manage software installs and I have installed MySQL on the machine and it runs fine. I can get to the MySQL server to start with “launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist” but I need to put “homebrew.mxcl.mysql.plist” somewhere, or I assume I do, so that it will be read and executed upon booting up and that will solve getting it started at boot.

Any help on what I have right, or not right, when it comes to this would be a great help. I have Googled a number of items with no real results for admining a Mac like I would a RedHat, or other INX box. Anyone have any sources of value.

Thanks for taking the time all to post.

Cody says: January 15, 2013 at 11:24 pm

Oh my gosh! Have been scouring the internet trying to get my installation of mysql to work! Finally found yours thanks so much! Super helpful!!!

Steve says: January 25, 2013 at 3:55 am

Thanks a bunch — After trying twice unsuccessfully with the binary install from oracle, I removed everything and started over following your homebrew recipe. The only slight comment I would make (assuming I made the correct choice) is that in the command line where you do:

$ mysql_install_db –verbose –user=`whoami`

I replace the `whoami` with –user=steve (which is the admin user on my machine) … I assume that was the right thing to do, cause I was able to start the server and get into the database.

so a big THANKS!

Troy Murray says: February 24, 2013 at 5:36 pm


the `whoami` actually dynamically determines your user account name and inserts it into the command when you run it. You get the same results just adding your name like you did, but for Rob’s posting it makes sense since the user running it could have any name

Chris says: February 23, 2013 at 2:09 am

Thanks for this.

One thing I found is that Homebrew did not create the folder path: /usr/local/var/mysql when it installed mysql so I had to do that manually.

Mark Learst says: March 4, 2013 at 6:59 am

I had to reinstall OS X (10.8.2) and my dev environment, was going crazy till I found this reply by Chris. Once I added this folder path too “/usr/local/var/mysql” everything was back to normal.

Richard Lai says: February 26, 2013 at 1:46 am


I am having issues with the current version of mysql 5.6.10 with rails and I would like to use an older version of mysql. How do I change it so that it would use the other versions in my folder /usr/local/Cellar/mysql such as 5.5.28?

Rob Bennet says: March 12, 2013 at 10:21 pm

You could just change the symlink in /usr/local/opt
Using Terminal,
cd /usr/local/opt
ln -s -f /usr/local/Cellar/mysql/5.5.28 mysql
I’m just passing a -f option to force the symlink instead of having to delete the sym and then re-create/link it.

Marques says: March 13, 2013 at 2:25 pm

I am getting a blank FATAL ERROR: message after running mysql_install_db –verbose –user=`whoami` –basedir=”$(brew –prefix mysql)” –datadir=/usr/local/var/mysql –tmpdir=/tmp

I am using Mountain Lion and mysql version 5.6.10

Any suggestions?

Marques says: March 13, 2013 at 2:48 pm

Nevermind, I closed my terminal and tried again with ‘sudo’ and it worked fine.

Thanks for the awesome article!

Kyle says: March 14, 2013 at 9:12 pm

Great article, thanks. Though I went through it rather quickly and ended up setting my new root password to YOUR_NEW_PASSWORD :)

Bogdan says: June 6, 2013 at 12:40 pm

Hi, i am having trouble with the: “mysql_install_db –verbose –user=`whoami` –basedir=”$(brew –prefix mysql)” –datadir=/usr/local/var/mysql –tmpdir=/tmp” command. It is not working for me, i am getting this error:

2013-06-06 14:38:22 561 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 35
2013-06-06 14:38:22 561 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2013-06-06 14:38:22 561 [Note] InnoDB: Unable to open the first data file
2013-06-06 14:38:22 7fff7438a180 InnoDB: Operating system error number 35 in a file operation.
InnoDB: Error number 35 means ‘Resource temporarily unavailable’

Please help!

JP Lew says: June 10, 2013 at 4:21 am

I get the same error. While I could be mistaken, I think this step is no longer necessary.

MySQL 5.6.10 installation via Homebrew seems to work fine without having to create these tables. I think the installer does it automatically.

JP says: June 10, 2013 at 11:02 am

woops, correction. You do need to run that command. The reason it’s giving you that error is because you have another mysqld process running.
Find those mysqld processes using top or Activity Monitor, then kill them.

Jacob Morris says: June 21, 2013 at 7:21 am

I get the following error while trying to run: mysql_install_db –verbose –user=`whoami` –basedir=”$(brew –prefix mysql)” –datadir=/usr/local/var/mysql –tmpdir=/tmp

Terminal returns:
2013-06-21 09:20:50 43364 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 35
2013-06-21 09:20:50 43364 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.

Any suggestions?

Bryan Estrito says: August 10, 2013 at 6:09 pm

unload your launchctl first because it starts already the mysqld

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

then repeat the mysql_install_db command

Ashton says: October 9, 2013 at 9:16 pm

The mysql version changes, so the command given to copy the plist won’t work verbatim…

Something like this would be more flexible

cp /usr/local/Cellar/mysql/5.6.*/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/

DevByStarlight says: October 30, 2013 at 6:01 pm

Suggestion for your installation process.

Optionally Execute “mysql_secure_installation”

Particularly if the the mysql install will be used in a production environment … or quasi-production “in house” environment.

Side note: The symlink mentioned in procedures … OSX may tend to wipe the /tmp dir contents on a system reboot.

Cheap Moncler Outlet Online Sale UK says: November 16, 2013 at 2:17 am

It depends on the act|service|duty|customary duty|office} rule and model. If you are in a creative tract of land like advertising, you can make straight up in jeans and tees. However, if you are an act|service|duty|customary duty|office} clerk or a attorney-at-law, you have to have on positive|in due form|according to established form|formal} women dresses for tasting issue.

iphone screen repair maryland says: November 18, 2013 at 6:09 am

You’re in point of truth beautiful web site owner. Your website reloading velocity is definitely amazing. It sounds as if you are doing every exclusive secret. Additionally, This belongings usually are masterpiece. you will have completed a wonderful action within this subject!

Sonu says: March 15, 2014 at 9:30 am

Thanks for your publish. My spsuoe and i have generally seen that most people are desirous to lose weight because they wish to look slim in addition to looking attractive. However, they do not constantly realize that there are more benefits for you to losing weight as well. Doctors say that over weight people are afflicted with a variety of conditions that can be instantly attributed to their own excess weight. The good news is that people who\’re overweight plus suffering from diverse diseases can reduce the severity of the illnesses by way of losing weight. It is easy to see a continuous but noticeable improvement in health as soon as even a slight amount of losing weight is reached.One thing I\’d like to reply to is that weightloss system fast can be achieved by the appropriate diet and exercise. Ones size not just affects the look, but also the complete quality of life. Self-esteem, despression symptoms, health risks, and also physical abilities are afflicted in an increase in weight. It is possible to do everything right whilst still having a gain. If this happens, a problem may be the offender. While a lot food rather than enough physical exercise are usually guilty, common health conditions and widespread prescriptions may greatly help to increase size. Thanks for your post right here.I realized more new things on this weight-loss issue. 1 issue is a good nutrition is tremendously vital if dieting. A tremendous reduction in fast foods, sugary foodstuff, fried foods, sugary foods, beef, and whitened flour products could possibly be necessary. Retaining wastes parasites, and harmful toxins may prevent targets for losing fat. While specified drugs momentarily solve the problem, the horrible side effects aren\’t worth it, and in addition they never give more than a short lived solution. It is a known undeniable fact that 95% of celebrity diets fail. Thank you for sharing your notions on this blog site.Thanks for the recommendations shared in your blog. Yet another thing I would like to mention is that weight reduction is not all about going on a dietary fad and trying to lose as much weight as possible in a few days. The most effective way to shed weight is by consuming it slowly and gradually and using some basic guidelines which can make it easier to make the most through your attempt to lose fat. You may learn and be following some of these tips, but reinforcing know-how never does any damage.I believe avoiding highly processed foods will be the first step to be able to lose weight. They can taste excellent, but processed foods currently have very little vitamins and minerals, making you take more only to have enough energy to get throughout the day. In case you are constantly consuming these foods, changing to cereals and other complex carbohydrates will let you have more energy while consuming less. Thanks a lot : ) for your blog post.

Pankaj says: March 15, 2014 at 10:16 am

Great goods from you, man. R-khair Blog Archive 14 e2€“ Foreach Array Loops I’ve understand your stuff poerivus to and you’re just extremely excellent. I actually like what you’ve acquired here, really like what you’re saying and the way in which you say it. You make it enjoyable and you still take care of to keep it wise. I can’t wait to read much more from you. This is actually a tremendous R-khair Blog Archive 14 e2€“ Foreach Array Loops informations.

Moreno says: March 15, 2014 at 2:49 pm

I have really learend new things via your weblog R-khair Blog Archive 14 e2€“ Foreach Array Loops. One other thing I’d prefer to say is the fact newer computer system operating systems tend to allow much more memory to use, but they also demand more memory simply to work. If people’s computer can not handle much more memory and also the newest software program requires that memory increase, it could be the time to buy a new Computer.

Cristian says: March 15, 2014 at 3:17 pm

My partner and i quite enjoy evyitehrng you submit right here. Highly unusual and also brilliant. 1 concern though. I’m running Firefox together with Debian and also pieces of one’s up-to-date web design parts certainly are a tiny wonky. My partner and i notice it’s not just a regular create. But it’s an issue to be able to hold in the mind. My partner and i wish which it will probably aid and also keep the finest top quality creating.

Ronny says: March 15, 2014 at 5:29 pm

I’m glad for commenting to enlbae you to keep in mind on the beneficial discovery my cousins girl developed going through your web site. She learned a great deal of pieces, which include the achievements like to have a marvelous teaching nature to possess certain people smoothly comprehend selected tortuous issues. You truly exceeded her expectations. I appreciate you for displaying these productive, trusted, revealing plus cool recommendations on your topic to Lizeth.

Open says: March 15, 2014 at 9:47 pm

I’m glad for commenting to enlbae you to keep in mind on the beneficial discovery my cousins girl developed going through your web site. She learned a great deal of pieces, which include the achievements like to have a marvelous teaching nature to possess certain people smoothly comprehend selected tortuous issues. You truly exceeded her expectations. I appreciate you for displaying these productive, trusted, revealing plus cool recommendations on your topic to Lizeth.

Jonatan says: March 16, 2014 at 2:21 am

I just really enjoy what we shuold post right here. Particularly new not to mention wise. A single concern though. I’m running Firefox with the help of Debian not to mention components with the existing layout products would be a bit wonky. I just know it’s not really popular developed. But it’s something towards hold in the mind. I just wish that going barefoot will probably guidance not to mention keep the best good penning.

Damir says: March 16, 2014 at 2:27 am

Thanks for the tips you have contributed here. Something imtorpant I would like to mention is that laptop memory demands generally rise along with other advances in the engineering. For instance, if new generations of cpus are brought to the market, there’s usually a matching increase in the size demands of both the personal computer memory plus hard drive space. This is because the software operated by these processors will inevitably boost in power to make use of the new engineering.

Jalal says: March 17, 2014 at 4:59 am

Definitely believe that which you sttaed.Your favorite justification appeared to be on the web the easiest thing to be aware of.I say to you, I certainly get irked while people consider worries that they just don’t know about.You managed to hit the nail upon the top as well as defined out the whole thing without having side effect , people could take a signal.Will likely be back to get more. ThanksBest Regards Lisa

Beat says: May 22, 2014 at 10:08 pm

Really decent blog post. We silmpy located ones own site and even wished to help you declare which will We have seriously appreciated examining ones own web site and even discussions. However I’ll end up signing up ones own rss feed and even As i expect to help you read through ones own web site all over again.

Ralph says: May 22, 2014 at 10:57 pm

Really decent blog post. We silpmy located ones own site and even wished to help you declare which will We have seriously appreciated examining ones own web site and even discussions. However I’ll end up signing up ones own rss feed and even As i expect to help you read through ones own web site all over again.

PaOla says: May 23, 2014 at 12:20 am

Thanks for your post. I also believe that loptap computers have grown to be more and more popular right now, and now are often the only kind of computer utilized in a household. Simply because at the same time that they are becoming more and more affordable, their working power is growing to the point where they’re as effective as personal computers from just a few in years past.

Imelda says: July 3, 2014 at 3:15 am

I see a lot of interesting content on your blog.
You have to spend a lot of time writing, i know how to save you a lot of
work, there is a tool that creates unique, SEO friendly articles in couple of seconds, just type in google
- laranita’s free content source

seo services durham says: July 28, 2014 at 12:06 am

These types of links may provide high impact for businesses because customers do click on these links.
Nowadays, the available search engine optinization has some modest SEO tactics in the market.
But, at the end of thee day the search engines are making changes to better the experience of the consumer.

Reply says: August 6, 2014 at 5:25 am

In general, men will avoid dealing with emotional attachment whenever possible.

We can rule this one out since he said you aren’t the same person he fell in love with.
Then, I want you to take this opportunity to work on yourself and do all of those
things that you’ve been putting off that would make you happy.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>