/ MYSQL, RAILS

Rails Connect to Remote Database in Development

In Rails Connect to Remote Database on localhost, task can be achieved by editing database.yml file in your Rails application. Make changes to host, username, password and database in your database yaml file to connect to remote database.

What is database.yml?

You might want to see the Article on what is database.yml file contains and what is meaning of each and every parameter present in the database.yml file

Where is database.yml?

Location: config/database.yml

Development Database Configuration:

development:
   adapter: mysql2
   encoding: utf8
   reconnect: false
   database: semantic_development
   pool: 5
   username: ruby
   password: ruby2in4rails
   host: localhost

Your development environment for Rails Application might be containing database.yml file containing this type of connection parameters

What to Edit ?

development:
   adapter: mysql2 # replace with remote db type if different
   encoding: utf8 # modify if it is different
   reconnect: false
   database: semantic_staging # remote database name
   pool: 5
   username: username # username for remote database
   password: password  # password for remote database
   host: some-remote-db.domain.com # this will be host where database is installed

After you edit this settings in database.yml, when you run your development environment by rails console command, then your Rails Application will connect to the remote database from the connection parameters that you have provided in database.yml file.

If you face any issue while trying to connecting to remote database on your localhost, then let us know through comments.

References

For more information on Rails configurations, you can refer Configuring Rails Apps

akshay

Akshay Mohite

Hi there! I am a Ruby on Rails & ReactJS Enthusiast, building some cool products at DTree Labs.

Read More
Buy me a coffee