我是初学者使用Ruby on Rails的Lynda教程,但尝试在c9上完成它。我刚刚安装了Rails和mysql,当我尝试运行rails服务器(rails s -b $IP -p $PORT
)时,当我转到https://my_rails_app-username.c9users.io/时会产生错误:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
答案 0 :(得分:1)
查看config / database.yml
development:
<<: *default
database: my_rails_app_development
这需要更改为
development:
adapter: mysql2
encoding: utf8
database: c9
username: <%=ENV['C9_USER']%>
host: <%=ENV['IP']%>
这将为您获取c9用户名和主机名(在本例中为0.0.0.0),并插入值,这样您就不需要自己搞清楚了。现在,当您重新启动服务器时,您会得到:
Can't connect to MySQL server on '0.0.0.0' (111)
停止服务器。运行:mysql-ctl start
现在重新启动服务器(rails s -b $IP -p $PORT
)
如果仍然无效,请尝试:sudo service mysqld start
或sudo service mysql start
信用: 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
答案 1 :(得分:0)
我试过
mysql-ctl restart
在我的终端上,它有效。