« | »

Install MySQL on Mac OSX using Homebrew

mysqlRecently, while doing some development on my Mac, I realized I didn’t have MySQL installed. I could have loaded up an instance of Ubuntu 12.04 LTS on VirtualBox and used that. However, I thought it would be much more convenient to have it available directly instead in a virtualized environment. Here are the instructions for installing it on a Mac using Homebrew.

This guide assumes Homebrew is installed and properly functioning.

First, ensure that Homebrew is update to date and ready to brew:

Next, install MySQL:

Start MySQL:

Secure your MySQL installation. The main purpose of doing this is to ensure that the configuration of the local environment is set up as close as possible to the production environment.

Run the following two commands to allow MySQL to run under your user account:

Add the following my.cnf file to /etc:

Restart the MySQL server:

3 Responses to Install MySQL on Mac OSX using Homebrew

  1. angela says:

    hi, I am following your directions, but ran into a glitch on step “Run the following two commands to allow MySQL to run under your user account:” on mac mavericks, in terminal, installed via homebrew. Can you be more explicit on the break out of the 2 commands? Everything seems okay up until this. Am I doing this correctly? Any help much appreciated, this is my first time installing without mamp, I’m trying to get better at using terminal…

    here is what I am getting as error in terminal after copy&paste your code:

    Macintosh:~ angie$ unset TMPDIR
    Macintosh:~ angie$ mysql_install_db –verbose –user=whoami \\
    FATAL ERROR: Could not find ./bin/my_print_defaults

    If you compiled from source, you need to run ‘make install’ to
    copy the software into the correct location ready for operation.

    If you are using a binary release, you must either be at the top
    level of the extracted archive, or pass the –basedir option
    pointing to that location.
    Macintosh:~ angie$ –datadir=/usr/local/var/mysql –tmpdir=/tmp
    -bash: –datadir=/usr/local/var/mysql: No such file or directory
    Macintosh:~ angie$

  2. Chris Beck says:

    Thanks so much.

    FWIW, I had to make sure that mysqld wasn’t running in order to run mysql_install_db

    Also, I chose to use launchd to run mysql at startup per the homebrew instructions

    To have launchd start mysql at login:
    ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

  3. Steve S says:

    I’m a noob trying to teach myself some things. I just tried to follow these instructions; here’s the result, copied directly from my Terminal window:

    Steves-MacBook-Pro:/ steves93$ brew install mysql
    ==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mysql-5.6.16.mavericks.bottle.tar.gz
    ######################################################################## 100.0%
    ==> Pouring mysql-5.6.16.mavericks.bottle.tar.gz
    ==> Caveats
    A “/etc/my.cnf” from another install may interfere with a Homebrew-built
    server starting up correctly.

    To connect:
    mysql -uroot

    To have launchd start mysql at login:
    ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
    Then to load mysql now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    Or, if you don’t want/need launchctl, you can just run:
    mysql.server start
    ==> /usr/local/Cellar/mysql/5.6.16/bin/mysql_install_db –verbose –user=steves93 –basedir=/usr/local/Cellar/mysql/5.6.16 –datad
    ==> Summary

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 class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">