0

I'm a beginner using the Lynda tutorial for Ruby on Rails, but trying to go through it on c9. I've just installed Rails and mysql, and when I try to run the rails server (rails s -b $IP -p $PORT), it produces errors when I go to https://my_rails_app-username.c9users.io/:

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
stephen
  • 195
  • 9

2 Answers2

1

Looking at config/database.yml

development:
  <<: *default
  database: my_rails_app_development

This needs to be changed to

development:
  adapter: mysql2
  encoding: utf8
  database: c9
  username: <%=ENV['C9_USER']%>
  host: <%=ENV['IP']%>

This gets your c9 username, and hostname (in this case 0.0.0.0) for you and inserts the values so you don't need to go figuring them out yourself. Now, when you restart the server, you get:

Can't connect to MySQL server on '0.0.0.0' (111)

Stop the server. Run: mysql-ctl start And now restart the server (rails s -b $IP -p $PORT)

If this still doesn't work, try: sudo service mysqld start or sudo service mysql start

Credit to: Cloud 9 IDE can't connect to database Mysql can't connect to local server through socket on Amazon EC2 https://docs.c9.io/docs/running-a-rails-app

Community
  • 1
  • 1
stephen
  • 195
  • 9
0

I tried

mysql-ctl restart

on my terminal and it worked.

Ephraim
  • 21
  • 1
  • 3
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). - [From Review](/review/low-quality-posts/11282336) – Igbanam Feb 16 '16 at 09:34
  • 1
    @Yasky How does this not attempt to provide an answer? It might be completely wrong, [but that doesn't mean we should abuse the review queues to delete it.](http://meta.stackoverflow.com/q/287563/1849664) – Undo Feb 17 '16 at 00:01
  • 1
    You could be right Yasky. My answer applies to the following error. Can't connect to MySQL server on '0.0.0.0' (111) – Ephraim Feb 17 '16 at 06:03