Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Connecting Rails App to existing MAMP DB


  • Please log in to reply
6 replies to this topic

#1 Figgy

Figgy

    Passenger

  • Members
  • 7 posts

Posted 04 September 2013 - 06:09 AM

I have a Rails app already created. I have MAMP installed and have created a database using PHPMyAdmin.

I want to connect that database to my Rails app. My database.yml file looks like this:

development:
adapter: mysql2
database: db_name
host: localhost
username: root
password: figgy
socket: /Applications/MAMP/tmp/mysql/mysql.sock
pool: 5
timeout: 5000

I'm using RubyMine. When I run my app, it launches the server at localhost:3000 and loads the welcome page. I don't believe it's connecting to my MAMP Database.

Can someone please let me know what I'm doing wrong. Thank you in advanced.

#2 Rowel

Rowel

    Controller

  • Members
  • 109 posts

Posted 04 September 2013 - 12:24 PM

Why not try opening the Rails console and do a Table.find(:all) on one of your database tables ? (substitute Table with your actual table name) 

 

If Rails isn't connected to your database, you'll get an error. 


  • Jamie likes this

#3 Figgy

Figgy

    Passenger

  • Members
  • 7 posts

Posted 04 September 2013 - 03:00 PM

Ill try that...guess where I am confused is that MAMP connects to localhost:8888 and rails app is on localhost:3000. Don't know if it makes a difference but I figured that since its a different localhost, the rails app wouldn't find the mysql database from MAMP. Am I making sense lol.

#4 Rowel

Rowel

    Controller

  • Members
  • 109 posts

Posted 04 September 2013 - 03:14 PM

:3000 is just the web server port  (not the usual, normal port 80).   When you deploy your Rails app to production, it will be on port 80  (and no need to specify :3000 in your url). 



#5 Figgy

Figgy

    Passenger

  • Members
  • 7 posts

Posted 04 September 2013 - 07:34 PM

Makes sense.

 

But this is the error I'm getting. 

Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)

#6 Rowel

Rowel

    Controller

  • Members
  • 109 posts

Posted 04 September 2013 - 08:44 PM   Best Answer

I googled that for you. 

Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)

Try this. 

http://www.tech-reci...t-tmpmysqlsock/

 

or this

http://stackoverflow...ket-tmp-mysql-s

 

related (need to create a sym link)

http://stackoverflow...local-mysql-osx



#7 Figgy

Figgy

    Passenger

  • Members
  • 7 posts

Posted 04 September 2013 - 10:36 PM

Symlink fixed it!  Bro you are my hero!  Thank you so much!!!!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users