12 September 2009 ~ 22 Comments

Installing MySQL on Snow Leopard

Early on at Cisco, I realized that it’s really beneficial to write down (step by step) what I’ve done when I install something new. It forces me to think about what I’m doing, it provides me with a guide in case I mess up and have to start over, and other people can benefit from it later.

With that in mind, I’ve decided to document my installation of MySQL on Snow Leopard (OS X 10.6). Hopefully, someone will get some use out of it, but if not, at least I’ll have documentation of what I did.

The PATH Variable

MySQL has a bunch of useful executables that aren’t in PATH by default. I could symlink to them, but I think that’s less maintainable than just appending to PATH.

  1. Open the Terminal
  2. Open up the .bash_profile file in your home directory. This is a bash script that runs every time you start the Terminal, so the PATH variable will be extended properly every time. If you have TextMate and its UNIX command line tools installed, do it like this:
    mate ~/.bash_profile

    Otherwise, do it like this:

    /Applications/TextEdit.app/Contents/MacOS/TextEdit ~/.bash_profile &

    If you use the second one, make sure to add the ampersand at the end.

  3. We want to add MySQL’s bin folder to PATH. MySQL’s going to be installed at /usr/local/mysql, so let’s add /usr/local/mysql/bin to PATH. Add the following line to .bash_profile:
    export PATH="/usr/local/mysql/bin:/usr/local/sbin:$PATH"

    This replaces PATH with two new locations and the old value of path (so essentially, appending the two new locations to the beginning of PATH). You’ll notice that, in addition to /usr/local/mysql/bin (which I mentioned earlier), I also added /usr/local/sbin. OS X doesn’t include this in PATH by default, but I think it should, so I added it. I have no defense for that position, but this is as much a guide for myself as it is a guide for other people, so I don’t need to defend it :)

  4. Save the updated .bash_profile and close it.
  5. Quit and reopen Terminal so that .bash_profile will be rerun (you could also run it explicitly, but I prefer quitting and reopening).
  6. Run the following command:
    echo $PATH

    You should see /usr/local/mysql/bin and /usr/local/sbin in there now.

  7. Edit: Restart your computer. My installation worked without doing this, but Jon (in the comments) said he needed to do this before it worked, so you might as well.

Downloading + Installing

I might try compiling and installing from source at some point, but I don’t see any reason to when there are official OS X binaries available. Worst case scenario, it messes with a bunch of my settings, and I’ll uninstall and then do it from source.

  1. Go to http://dev.mysql.com/downloads/mysql/5.1.html#downloads
  2. Scroll down to the Mac OS X section (near the bottom). Download the version labeled “Mac OS X 10.5 (x86_64)”. It’s very important that you download the 64-bit version. The 32-bit one will give you preference pane problems (I call them PPPs whenever I talk about them, though this is the first time I ever have). Eventually, there’ll probably be a Mac OS X 10.6 version, but for now, this works perfectly.
  3. Open the .dmg, then run mysql-x.x.xx-osx10.5-x86_64.pkg. Continue through all the screens without changing anything, until it finishes.
  4. Optional: install the preference pane by running MySQL.prefPane.
  5. Optional: make MySQL start up along with OS X by running MySQLStartupItem.pkg. I didn’t do this (I often use my computer for things other than development, and I don’t want to bog it down unnecessarily), so I can’t provide any instruction or vouch for how well it works on Snow Leopard.
  6. You should now be able to start MySQL by going into the MySQL preference pane and clicking “Start MySQL Server”. If it doesn’t work, leave me a comment, and I’ll try to help you.

22 Responses to “Installing MySQL on Snow Leopard”

  1. calebhc 19 October 2009 at 11:07 am Permalink

    Thanks! This really helped!

  2. wsmith 22 October 2009 at 6:34 am Permalink

    I also found this very helpful, quick and simple.

  3. Pete 27 October 2009 at 6:12 am Permalink

    For some reason, I’m still having PPP. I installed the 64 bit version because the prefs panel item was “grayed” out and not accessible. I still have the same problem with the 64 bit one. If you have any idea what causes this let me know. If not, I’ll keep digging and trying.

  4. Jake Boxer 27 October 2009 at 6:34 am Permalink

    Pete: I shouldn’t make up acronyms on the fly anymore. I had to re-read my post to understand what you meant :)

    Anyways, just as a sanity check, are you on Snow Leopard or just regular Leopard? A few people have emailed me with problems, only to realize that they were on regular Leopard (32-bit).

  5. douglasbrown 5 November 2009 at 12:41 pm Permalink

    Jake, Did you have a previous 32bit version of mySQL installed before you added the 64 bit version?

  6. Jake Boxer 5 November 2009 at 12:50 pm Permalink

    douglasbrown: I don’t think so. I followed these steps almost immediately after installing Snow Leopard.

    If Snow Leopard comes with its own 32-bit version of MySQL installed, then yes, but that would seem a little silly to me.

  7. VN 10 December 2009 at 10:47 am Permalink

    Thanks for the writeup. it worked perfectly.

  8. Jake Boxer 10 December 2009 at 10:49 am Permalink

    VN: No problem, glad I could help.

  9. Burtron 31 December 2009 at 6:29 am Permalink

    Worked perfect. Thanks so much for posting this as it made my life easier. I am coming over from M$ Windows to Mac OS X (and loving it) after 20 years of software development (DOS, Windows, Linux).

  10. Jake Boxer 31 December 2009 at 10:11 am Permalink

    No problem Burton. I made the move myself a couple years ago. Glad this made things easier for you!

  11. hamid 9 January 2010 at 10:54 pm Permalink

    Hi, I followed your instructions and it didnt give me any error… but dont know where is the mysql folder is. I installed it on default path..

    cheers,

  12. Jake Boxer 10 January 2010 at 4:05 pm Permalink

    hamid:

    When you say “the mysql folder”, are you talking about the location it was installed in? Or are you asking where to go to start/stop it from running?

    The folder where MySQL is installed (by default) is /usr/local/mysql. From within there, the executables are in bin.

    To actually run MySQL after doing this installation (assuming you followed the preference pane installation instructions), go to the Apple menu, click “System Preferences…”, and click the MySQL button on the bottom row. From there, you can start/stop the server, and choose whether or not the server should start when your computer starts.

    Is this what you’re asking? Or is it something else?

  13. nayif 17 January 2010 at 1:55 am Permalink

    as i upgrade from 10.5 to 10.6 , i found that i use .profile instead of .bash_profile. i think the first one is the default IMO.

    thanks for your simple how to.

  14. hatorade 19 January 2010 at 2:56 am Permalink

    I did all of this, but when I went to run it I got the following:

    ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

    any idea?

  15. Leo Dirac 1 February 2010 at 11:25 pm Permalink

    Awesome. This fixed my problem perfectly. Thanks!

  16. Jon Carroll 9 February 2010 at 9:56 am Permalink

    If you are still having trouble running the installer (hanging at preparing) be sure to reboot after taking all the steps under “The PATH Variable”. It still wouldn’t install for me but after a reboot it worked. Thanks for the info.

  17. Jake Boxer 9 February 2010 at 2:00 pm Permalink

    Jon: Thanks for the info! I’ll add it to the set of instructions.

  18. bluemantis 11 February 2010 at 4:45 am Permalink

    So I have the latest mySQL (64-bit) installed on Snow Leopard. Now how do i begin creating a database? I downloaded myPHP but can’t seem to find where to start. I am a designer by trade and want to move into getting my sites more dynamic. Can I do all this with a GUI rather than going through terminal and typing code?

  19. Jake Boxer 11 February 2010 at 8:33 am Permalink

    bluemantis: Yep, but it’ll cost you.

    I’ve experimented a bit with a program called Querious: http://www.araelium.com/querious/

    I really really like it. As a developer, I’m perfectly comfortable on the command line and with phpMyAdmin, but for a designer, Querious might be much preferable.

    Either way though, I would definitely recommend picking up a book on MySQL. Using it is going to be a constant struggle if you don’t have a basic understanding of the code involved, so while it may be an annoying initial investment, you will save yourself huge headaches (and a lot of time) in the long run.

  20. bluemantis 11 February 2010 at 8:11 pm Permalink

    I bought a book on it (a bit cryptic, if you asked me)–The Definitive Guide to MySQL 5 by Michael Kofler, from apress. Is it any good? Lastly, Would it make any sense for a non-developer (such a I) to delve into this? Or is that overextending oneself?

  21. Jake Boxer 11 February 2010 at 10:05 pm Permalink

    bluemantis: Honestly, I’m not sure what you’ll be able to do with a database without a bit of programming knowledge as well. With a basic amount of each, you could do some cool stuff, but with just MySQL, I’m not sure if you’d be able to do anything.


Leave a Reply