[英]Rails : Heroku CI : Mysql2::Error: Can't connect to MySQL server on '127.0.0.1' (111) for test env
I have deployed a rails app to heroku, using mysql database hosted on a remote server. 我已经使用托管在远程服务器上的mysql数据库将rails应用程序部署到了heroku。 For this I have added the heroku addon 'cleardb' and setup correct ENV Config vars specifying: 为此,我添加了heroku插件'cleardb'并设置了正确的ENV Config vars,指定:
DATABASE_URL = mysql2://user:password@host?reconnect=true
I have also setup Heroku continuous deployment for three branches, (branch -> environment) 我还为三个分支设置了Heroku连续部署(分支->环境)
develop -> devint,
staging -> staging,
master -> production
Continuous deployment works fine, and the database is setup fine too (because when I create a record in rails app, I can see the data in remote mysql host). 连续部署可以正常工作,数据库也可以正常运行(因为当我在rails应用程序中创建记录时,可以在远程mysql主机中看到数据)。
My issue is that when I enable HEROKU CI, the build fails every time with an error saying Mysql2::Error: Can't connect to MySQL server on '127.0.0.1' (111)
我的问题是,当我启用HEROKU CI时,每次构建都会失败,并显示一条错误Mysql2::Error: Can't connect to MySQL server on '127.0.0.1' (111)
Full error here: https://gist.github.com/siddhantbhardwaj/dab7c435815e7729d0f70081449f21ff#file-gistfile1-txt 此处有完整错误: https : //gist.github.com/siddhantbhardwaj/dab7c435815e7729d0f70081449f21ff#file-gistfile1-txt
This occurs when Heroku CI tries to perform rake db:schema:load_if_ruby
for the :test env 当Heroku CI尝试对:test env执行rake db:schema:load_if_ruby
时,会发生这种情况
My database.yml looks like: 我的database.yml看起来像:
default: &default
adapter: mysql2
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: what_course_development
username: user
password: password
socket: /tmp/mysql.sock
test:
<<: *default
database: what_course_test
devint:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
staging:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
production:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
Please review below suggestion for configure your database.yml from DATABASE_URL: 请查看以下有关从DATABASE_URL配置database.yml的建议:
DatabaseUrl.to_active_record_hash('postgres://uuu:xxx@127.0.0.1:1234/abc')
This will provide the below result: 这将提供以下结果:
{:adapter=>"postgres", :host=>"127.0.0.1", :port=>1234, :database=>"abc", :user=>"uuu", :password=>"xxx"}
Please refer seamusabshere database_url for more information. 请参考seamusabshere database_url以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.