November 09, 2011
Using a MAMP Database with Ruby on Rails

One of the first hurdles that I came across after making the move to Ruby (and Rails) from PHP was utilizing some of my previously created MySQL databases in MAMP. I have always been a fan of MAMP as a PHP developer because it was extremely easy to setup a project and get coding. It was not as simple with Rails, however!

I soon realized it was not as easy as setting the host parameter to localhost and letting the language do all of the magic. The solution is to pass the absolute path of the MySQL socket inside the MAMP directory to the socket option in the app_path/config/database.yml file.

development: 
    adapter:    mysql2
    database:   development_database_name 
    username:   root
    password:   root
    socket:     /Applications/MAMP/tmp/mysql/mysql.sock

The path of the socket should be the same if you accepted the default installation path when installing MAMP.

Copyright © 2022 Allan Kiezel – Long Island Web Designer & App Developer. All rights reserved.