0

For my project I am trying to make a connection to a remote database with Rails 4.

I modified the database.yml file and it looks so:

development:
  adapter: mysql2
  reconnect: false
  encoding: utf8
  database: <name_DB>
  username: <user_DB>
  password: <pass_DB>
  host: 127.0.0.1
  port: 3307
  pool: 5

I got this error:

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

-I don't have any model until now.

-gem 'mysql2' already installed

-A connection through SSH works and also with MySQL workbench.

Am I missing something? How can I achieve the connection? Should I modify something else?

karlihnos
  • 415
  • 1
  • 7
  • 22
  • Only two things I can think of - triple check your configuration and check `/etc/hosts.allow` and `/etc/hosts.deny` on your remote server. Of course, check remote server firewall settings as well. – steve klein Jul 01 '15 at 16:00
  • In etc/hosts.deny looks like : # ALL: PARANOID. Is that ok? – karlihnos Jul 02 '15 at 06:40
  • Any line which begins with a '#' is a comment and ignored. If you have checked your configuration, I would look at the answer linked to by @Yury. – steve klein Jul 02 '15 at 11:41

2 Answers2

0

If you need to connect to your DB with the ssh tunnel, it wouldn't work.

You need to make your mysql server accessible for remote connections:

How to allow remote connection to mysql

Community
  • 1
  • 1
Yury Lebedev
  • 3,985
  • 19
  • 26
-1

This is the solution.

Important for the connection to work.

  1. Create SSH with the remote server!! SSH -L 3307:mysql:3306 <server_name> -p6060
  2. Configure your database.yml as posted in the original question.
  3. Done.
karlihnos
  • 415
  • 1
  • 7
  • 22