简体   繁体   中英

Rails no database name in connection

Trying to run a rails app in prod on Ubuntu 16.04 and installed mysql Ver 14.14 Distrib 5.7.24 , Ruby 2.5.3 , and using the mysql2 gem. It works fine on my Mac 10.13. My Rails app can't seem to read the DB name in Ubuntu.

Can't find the DB name: {:adapter=>"mysql2", :encoding=>"utf8", :database=>nil, :username=>"myUser", :password=>"secret", :host=>"127.0.0.1", :port=>3306}

Then adds 127.0.0.1 as the DB name: {:adapter=>"mysql2", :encoding=>"utf8", :database=>"127.0.0.1", :username=>"myUser", :password=>"secret", :host=>"127.0.0.1", :port=>3306}

My database.yml

production: adapter: mysql2 encoding: utf8 database: mydb username: myUser password: secret host: 127.0.0.1 port: 3306

I've been pulling my hair out as to why I can't connect to the DB in my Ubuntu server. I can log into mysql through the CLI fine with the DB user fine.

I'm also seeing the same issue on an Ubuntu box with Vagrant so thats consistent.

Any help is extremely appreciative at this time.

I have no idea but putting it in this format works. I tried everything else, different DB name, etc to no avail:

production: url: mysql2://user:pass@localhost/myDb

Thank you for your responses.

Your database.yml should look something like this:

development:
  adapter:  mysql2
  encoding: unicode
  pool: 5
  username: mysql_user
  password: your_password
  host:     localhost_or_your_host
  database: db_name

Do change your environment to match your requirements. This will work for your development mode.

  1. Before your Rails application can connect to a MySQL server, you need to install the MySQL adapter. The mysql2 gem provides this functionality. As the Rails user, install the mysql2 gem, like this:
    \ngem install mysql2  \n
  2. If you have config/database.yml file, keep file changes like this:(or create new file)
    \ndevelopment: \n adapter: mysql2 \n encoding: utf8 \n database: my_db_name \n username: root \n password: my_password \n host: 127.0.0.1 \n port: 3306 \n
  3. Create your application's development database using this rake command:
    \nrake db:create \n

Make your changes by following these steps.This will surely work for your development mode.

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