Install MySQL 5.1 Server on OSX Lion

Home / Mac / Install MySQL 5.1 Server on OSX Lion

So I had to get MySQL set up on my OSX Lion MacBook Pro after the recent format and upgrade to Lion. It was easier than i expected but I thought that it was still worth a post anyway.

First off, head over to the MySQL site and download the Mac pre-compiles binary of MySQL Community Server 5.1.x (the latest download says it’s for OSX 10.6 Snow Leopard but it works fine with 10.7 Lion). Download the latest DMG available, this can be found here http://dev.mysql.com/downloads/mysql/5.1.html.

When the download finishes, open the disk image and install the main package file (mysql-5.1.xx-osx10.6-x86_64.pkg), when that finishes double-click on the preferences pane (MYSQL.prefpane file) file to install that into the System Preferences menu. If you would like the database server to start on boot then you also need to install the MySQLStartupItem.pkg file.

Once this is done you can then open System Preferences and under the “Other” heading you will find your new MySQL preferences, from here you can start and stop the server and also enable/disable startup option.

Now if you are going to us mysql from terminal then you will want to add the mysql binaries path to your $PATH shell variable. To do this edit your .bash_profile file and add /usr/local/mysql/bin to the PATH variable. Your file might look like this:

When all the above is done you can start setting up the server. We now need to secure the server by setting some defaults and removing some test stuff, to do this open a terminal and run:

It will ask for your password (because of sudo) and then will ask you some questions about changes it wishes to make. Enter a password for root and then you can accept the defaults for the rest of the questions if you are unsure.

One last thing, if you intend to use MySQL with PHP then you will need to update your php.ini file to change the location that is set for the mysql.sock file. Open php.ini and find and replace /var/mysql/mysql.sock with /tmp/mysql.sock. This is because the MySQL default location for the mysql.sock file is in /tmp

Hope it helps 🙂

Leave a Reply

%d bloggers like this: