Ramblings on technology with a dash of social commentary
RSS icon Email icon Home icon
  • How to install MySQL 5.5 on Mac OS X 10.7 Lion

    Posted on September 8th, 2011 phpguru 8 comments

    This may not be obvious, but on the new Macs that ship with Lion, you can use the MySQL 5.5 64-bit dmg installer. It works perfectly on Lion, even though the MySQL site (still, at the time of this writing) says Mac OS X 10.6 Snow Leopard. You can use the Preference Pane to stop and start MySQL.

    Now after MySQL 5.5 is running, strangely enough, you cannot simply launch terminal and type mysql -u rootBash will complain that it can’t find mysql. So we have to help it like so:

    1. Use your favorite text editor to edit the file /Users/%yourname%/.bash_profile If this file doesn’t exist you can create it.
    2. Add the following line to your .bash_profile export PATH=$PATH:/usr/local/mysql/bin and save the file. Be careful editing this file exactly as above. You can render terminal unable to find all your programs if you break your $PATH.
    3. Quit and relaunch terminal, or type source ~/.bash_profile and hit return to reload the changes in your profile.
    4. Check your $PATH by typing echo $PATH and pressing return. You should see something like this /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/mysql/bin
    5. Now you should be able to run mysql -u root which means there is no root password by default!
    6. Run this next, at the mysql prompt GRANT ALL ON *.* TO 'root'@'localhost' IDENTIFIED BY 'your_password_here' WITH GRANT OPTION;This is how to secure your root user login.

    Now, for PHP to use this connection I had to tweak my system as shown below:

    1. Run phpinfo() and check out the path PHP is trying to use for mysql.sock. On my new Mac Mini, it was/var/mysql/mysql.sock
    2. From terminal, I did sudo find / -name mysql.sock -print
    3. The critical line of output shows that MySQL 5.5 installs the sock to /private/tmp/mysql.sock
    4. Now we need to create a symlink for PHP to be able to access the mysql.sock. Trouble is if you try it you’ll get an error because /var/mysql doesn’t exist. So next, do sudo mkdir /var/mysql
    5. Finally, do this sudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock

    Did that work for you?

     

    7 responses to “How to install MySQL 5.5 on Mac OS X 10.7 Lion” RSS icon

    • it worked with mysql 5.5.16, and phpMyAdmin 3.4.5. thanks

    • Thanks a lot.
      MySQL 5.5.19 + Lion

    • When I tried step 4, I got the following and still could not connect to mysql:

      echo $PATH
      /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

      When I cat .bash_profile I get:
      export PATH=$PATH:/usr/local/mysql/bin

      What am I missing? thanks…

    • Doh, I closed terminal again and it worked. Not sure what happened. I then got ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

      If anyone has this issue, I received it because MySQL in the system preferences, needs to be turned on. :) Thank you for the tutorial, it seems to work now.

    • Yes it did! I’ve been trying to get PHP to connect to MySQL via PDO for nearly an hour now. Going from one Google search to another, it turns out that my MySQL.sock file was either nonexistent or in the wrong directory. Following your terminal commands close to the end of this article did the trick. Thank you!!!

    • I just verified the same issue exists on a brand new (Mountain) Lion install of Mac OS X 10.7.4

      These two lines are the ticket:

      sudo mkdir /var/mysql
      sudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock

      One other thing I’ve done on my new system is to symlink these:
      sudo /usr/local/mysql/support-files/mysql.server start
      sudo /usr/local/mysql/support-files/mysql.server stop

      like so:
      sudo ln -s /usr/local/mysql/support-files/mysql.server /usr/local/bin/mysql.server

      Thanks to Dan’s Drivelings for that tip.

    • I tried several other suggestions before finding yours – yours actually worked ;) Thank you!


    1 Trackbacks / Pingbacks

    Leave a reply