This tutorial is about installing MySQL on a Mac OS X Mountain Lion using Homebrew package manager. I had a bit of struggle finding solutions about some of the issues I encountered installing it on my Mac so I am posting it here for my future reference and to help someone whom might encounter the same issues as I had.
What we need
1. Mac OS X machine. Current OS X version: Mountain Lion 10.8.3
2. Homebrew package manager
Install Homebrew on your Mac
1. Open up the terminal. You can find it under /Applications/Utilities/Terminal.app.
2. Type the command below:
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
3. After the installation is finished, you must install Git. To do this, type the command below:
$ brew install git
4. After installing git, update Homebrew by typing
$ brew update
Install MySQL on your Mac using Homebrew
1. Install MySQL by typing the command below:
$ brew install mysql
2. Homebrew will download MySQL and install it on your machine automatically.
3. To auto start MySQL upon booting your Mac, type in the commands below.
$ mkdir -p ~/Library/LaunchAgents $ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents $ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
4. Start your MySQL Server by typing the following command:
$ mysql.server start
You now have MySQL installed and running on your machine. In case you get any error when starting your MySQL Server i.e. ERROR! The server quit without updating PID file, you may refer to the steps below.
If you get any error when starting MySQL, you should open Finder and go to (Command + Shift + G) /usr/local/var/mysql and open the file name ending in .err (e.g. Your-Machine-Name.local.err) in your preferred text editor. It will contain the details about the error encountered by MySQL when starting. As for me, I encountered an error saying, “ERROR! The server quit without updating PID file”. I have found out that this is a permission error on the folder /usr/local/var/mysql. Here is how to fix it:
1. Open the Terminal again and type the commands below:
$ sudo chmod -R 755 /usr/local/var/mysql $ rm -Rf /usr/local/var/mysql/Your-Machine-Name.local.err
2. After doing this, you can type “mysql.server start” again to start MySQL again.
Securing your MySQL installation
It is always recommended to secure your MySQL installation. To do this, type the following on your Terminal:
$ mysql_secure_installation Set root password? [Y/n] Y Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y
With that, you can now use MySQL on your Mac. I would recommend Sequel Pro for Admin GUI.
Uninstall MySQL using Homebrew
To uninstall MySQL on your Mac using Homebrew, execute the following commands on the Terminal:
$ brew remove mysql $ brew cleanup $ launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist $ rm -Rf ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Copyright & Legal Trademark Notices
MySQL and the MySQL Logo are registered trademarks of Oracle Corporation
Mac OS X Mountain Lion are registered trademarks of Apple Inc.
All other trademarks are the property of their respective owners. All rights reserved.