Chris Mendez in DevOps, For Developers, Homebrew, MongoDB

Install MongoDB, MySQL, and Postgres on a mac in 4 steps

Step 0 - Install homebrew

Homebrew is a package manger that simplifies all database installs and management on a Mac.

Install Homebrew

Step 1 - Install MySQL

Whenever I'm building a Rails app on Windows Azure or AWS I find myself MySQL

brew install mysql  


# This wil precisely install MySQL version 5.6
brew install mysql56  

Step 2 - Install Postgres

Whenever I'm building a Ruby on Rails app for Heroku or Openshift, Postgres is my DB.

brew install postgres  

Step 3 - Install MongoDB

Whenever I'm building an ExpressJS app, MongoDB is my DB of choice.

brew install mongodb  

Step 4 - Database management

Homebrew is great for downloading and installing packages but even better for managing local databases for development. The interface is also known as Homebrew Services.

Install or manage Homebrew Services



MySQL Errors

If you see this error, it can either mean that there are permission issues or things did not install correctly.
MySQL socket error

Learn to Read the Error Logs

I generally suggest we first look at the error logs and see if we can better understand the problem.

The error log can be found here:

nano /usr/local/var/mysql/[look for your username].err  

Common MySQL Errors

I've seen a lot of errors in my lifetime and when it comes to MySQL, here are a few more common ones.

Last Resort

If you can't make sense of the error log, then one option is to uninstall mysql and re-install everything.

Uninstall MySQL

 brew uninstall mysql

 # Clean things up
 brew cleanup --force

 # Remove any associated files or folders
 launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

 # Remove any plists that might be lingering around
 rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

 # Remove the MySQL folder with recursion and force
 sudo rm -rf /usr/local/var/mysql

Reinstall MySQL

 brew install mysql

 # Check your installation
 ps aux | grep mysql 

 # Initialize the MySQl daemon 
 mysqld --initialize --explicit_defaults_for_timestamp

 # Start the MySQL server (don't use sudo)
 mysql.server start