Install MySQL on OS X 10.8 Mountain Lion

To install mysql the first thing that we need to do is download mysql installer on the mysql website. In that web site we can see several versions of mysql. We will use Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive. When we open the mysql-5.5.27-osx10.6-x86_64.dmg file, we will find 3 package installers.

Install all the three packages with the following order :

  1. mysql-5.5.27-osx10.6-x86_64.pkg
  2. MySQLStartupItem.pkg
  3. MySQL.prefPane

To start/stop MySQL we can use GUI tool from System Preferences > MySQL

We can also start/stop MySQL via terminal

# start mysql
sudo /usr/local/mysql/support-files/mysql.server start
# stop mysql
sudo /usr/local/mysql/support-files/mysql.server stop
# get mysql version
sudo /usr/local/mysql/bin/mysql -v

In order to use MySQL command without have to specify MySQL installation full path, we need to add MySQL installation directory to shell path.

# bash profile
cd ~
vi .bash_profile
export PATH="/usr/local/mysql/bin:$PATH"

Then reload the new PATH

source ~/.bash_profile
# test get mysql version
mysql -v
# set mysql password
cd ~
/usr/local/mysql/bin/mysqladmin -u root password 'yourpassword'