Connect Ruby on Rails to MySQL [closed]

1

I was trying with the ruby on rails framework, but I have had problems with the gem devise. I made it work but only locally with SQLite.

I would like to connect remotely to a database in MySQL, for the creation of the login and a dating system. I leave the code of my database.yml in rails:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3
    
asked by Daniel Treviño 23.06.2017 в 05:58
source

1 answer

1

First you must add the mysql2 gem to your Gemfile file:

gem 'mysql2'

Once you do this, execute the following command:

$ bundle install

And finally, add the configuration of your database in config/database.yml , for example 1 :

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: nombre_de_la_base
  pool: 5
  username: tu_usuario
  password: tu_contraseña

Your database has probably not been created, so execute the following commands:

$ rails db:create
$ rails db:migrate

1 You must specify the configuration also for databases test and production .

    
answered by 23.06.2017 / 07:04
source