The no fuss, no muss guide to installing the latest stable version of MySQL DB locally on your Mac running OS X 10.7 or later. (Hat tip to Trey Piepmeier for his excellent tutorial, upon which I improved a few things.)
- I’m assuming you’ve already installed Homebrew.
- If you haven’t already done so, run a quick
brew updatein terminal. This ensures you have the latest brew library of packages before you install anything.
- OK? Good. Now you need to tell brew to install MySQL by entering this command:
brew install mysql
- Enter the following two commands, one after the other (the second one starts up your new, local MySQL server and creates an initial database):
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
- The output from that last command should instruct you to enter three more. Do it!:
mkdir -p ~/Library/LaunchAgents
cp $(brew --prefix mysql)/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
The three commands above do the following, respectively: create a LaunchAgents folder for you if you don’t already have one, copy the mysql.plist file into that launch folder, and then loads that file into a system file so that Mac OS X starts MySQL for you each time you restart your machine. Perfect!
- One final (optional) step is to run the included MySQL root/user config script. It’ll step you through various default username/password/etc options that you might want to configure now that you’ve got MySQL up and running on your machine. To run this automated post-MySQL-install wizard, enter:
$(brew --prefix mysql)/bin/mysql_secure_installation