如何从Rails应用程序连接到远程mysql服务器?

时间:2020-05-26 15:50:46

标签: ruby-on-rails

我正在尝试连接到远程mysql服务器。这是我建立连接的方式:-

default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  host: 13.58.156.50
  port: 3306
  # username: <%= ENV['FOODCLUBE_DATABASE_USER_DEVELOPMENT'] %>
  # password: <%= ENV['FOODCLUBE_DATABASE_PASSWORD_DEVELOPMENT'] %>
  username: root
  password: Admin123#
  socket: /var/run/mysqld/mysqld.sock
  variables:
    sql_mode: "TRADITIONAL"

development:
  <<: *default
  database: timer
  # food_delivery_development

test:
  <<: *default
  database: food_club_test

production:
  <<: *default
  database: food_clube_production
  username: <%= ENV['FOODCLUBE_DATABASE_USER_PRODUCTION'] %>
  password: <%= ENV['FOODCLUBE_DATABASE_PASSWORD_PRODUCTION'] %>

当我尝试从Rails控制台查询查询时,出现以下错误消息:-

Mysql2::Error::ConnectionError: Lost connection to MySQL server at 'reading initial communication packet', system error: 0

我该如何解决?

0 个答案:

没有答案