Install MySQL 5.5 on Mac OS X 10.7 Lion

This may not be obvious, you can use the MySQL 5.5 64-bit dmg installer. It works perfectly on Lion.

Now after MySQL 5.5 is running, strangely enough, you cannot simply launch terminal and typemysql -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_profileIf this file doesn’t exist you can create it.
  2. Add the following line to your .bash_profileexport PATH=$PATH:/usr/local/mysql/binand 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 typesource ~/.bash_profleand hit return to reload the changes in your profile.
  4. Check your $PATH by typingecho $PATHand 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 runmysql -u rootwhich means there is no root password by default!
  6. Run this next, at the mysql promptGRANT 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 didsudo 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, dosudo mkdir /var/mysql
  5. Finally, do thissudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock
Install MySQL 5.5 on Mac OS X 10.7 Lion