Setting up MySQL 5.6 on OSX Mountain Lion

Installing MySQL database server on a Mac with OSX Mountain Lion is relatively easy, if you follow these steps:

1. Download MySQL

Best option is to directly download a .dmg image file directly from mysql.com. The MySQL Downloads page has a list of all the different versions available. In my case, I chose MySQL 5.6.11 (latest one available) MySQL 5.6.11 on DMG format for OSX 10.7 x86 64bit.

Screen Shot 2013-05-21 at 7.23.50 PM

Screen Shot 2013-05-21 at 7.11.58 PM

Extract and install.

2. Configure the server

Without going into configuration details and database tunning, the main two things are setting up a password for the root user and creating a database to use. Additionally, you may want to create a separate user for your app(s).

First we might need to create aliases for the MySQL binaries:

$ sudo ln -s "/usr/local/mysql-5.6.11-osx10.7-x86_64/bin/mysqladmin" /usr/bin/mysqladmin
$ sudo ln -s "/usr/local/mysql-5.6.11-osx10.7-x86_64/bin/mysql" /usr/bin/mysql

Then we can proceed with the configuration:

$ mysqladmin -u root password 'rootpassword'
$ mysql -u root -prootpassword -e "create database database_name character set utf8 collate utf8_general_ci;"
$ mysql -u root -prootpassword -e "grant all privileges on database_name.* to username@localhost identified by 'userpassword';"

Note: Using the password on the command line like above can be insecure.

3. Install your favorite MySQL client (optional)

In my case, I really like Sequel Pro. Let’s install it and connect to our new local MySQL server via socket.

Screen Shot 2013-05-21 at 7.35.08 PM
Screen Shot 2013-05-21 at 7.34.38 PM
Screen Shot 2013-05-21 at 7.35.33 PM 

That is it!