Monday, June 27, 2011

Using MySQL as your development database

On my Mac OS X, I'm starting a new project with Rails 3.1, and I'm using MySQL as my development database because when I deploy, MySQL will be the production database, and the two dbs really should match.

Unfortunately, after running
rails new mynewapp -d=mysql
and testing out
rails server
I got this error:
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Of course I hadn't (1) started the MySQL server yet and (2) created my development database. This was new to me since I normally just developed with the sqlite db Rails automatically ships with for development.

After using homebrew to install mysql ("brew install mysql" as Ryan Bigg suggests at http://ryanbigg.com/2011/06/mac-os-x-ruby-rvm-rails-and-you/), I followed the added installation instructions that come with the brew install (viewable through "brew info mysql"
- pretty darn important to finish the mysql install with homebrew), and then ran these commands:

# start the server - something I'm not used to after using sqlite
mysql.server start
# create the db; specify -p if necessary
mysqladmin -u root create mynewapp_development

Then, "rails server" was successful.

(Note: running "mysql.server start" won't be necessary if you follow the instructions from "brew info mysql" and configure the start server on startup)

No comments:

Post a Comment

Please be considerate in what you say.