简体   繁体   中英

Connecting Rails 4 with remote MySQL database

I have been working with Rails since two months but until now I haven't use databases.

I would like that my web-app connects to a remote database (MySQL) and extract some data to plot it in Rails using Highcharts.

I have found many tutorials that explains how to connect to an existing database (editing config/database.yml ) but this is in the same server.

I am using Ubuntu 14.04 LTS.

Could anyone explains me which are the steps or how can achieve this connection to the remote database with Rails and how to extract the data from a given database?

You just edit the database.yml file so that it points to the remote database:

  adapter: mysql2
  encoding: utf-8
  pool: 5
  username: "username"
  password: "password"
  host: "hostname"
  port: "port number"
  database: "database name"

After two days asking in forums and people, nobody could help me, however, I found a solution.

  1. IMPORTANT: To connect to an external database you should first create the SSH tunnel!!!!

  2. Configure the database.yml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM