简体   繁体   English

Rails连接中没有数据库名称

[英]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. 尝试在Ubuntu 16.04上的产品中运行Rails应用程序,并安装mysql Ver 14.14 Distrib 5.7.24 ,Ruby 2.5.3并使用mysql2 gem。 It works fine on my Mac 10.13. 在我的Mac 10.13上它可以正常工作。 My Rails app can't seem to read the DB name in Ubuntu. 我的Rails应用似乎无法在Ubuntu中读取数据库名称。

Can't find the DB name: {:adapter=>"mysql2", :encoding=>"utf8", :database=>nil, :username=>"myUser", :password=>"secret", :host=>"127.0.0.1", :port=>3306} 找不到数据库名称: {: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} 然后添加127.0.0.1作为数据库名称: {:adapter=>"mysql2", :encoding=>"utf8", :database=>"127.0.0.1", :username=>"myUser", :password=>"secret", :host=>"127.0.0.1", :port=>3306}

My database.yml 我的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. 关于为什么无法在Ubuntu服务器上连接数据库的问题,我一直在发hair。 I can log into mysql through the CLI fine with the DB user fine. 我可以通过CLI和数据库用户一起通过mysql登录mysql。

I'm also seeing the same issue on an Ubuntu box with Vagrant so thats consistent. 我还在带有Vagrant的Ubuntu盒子上看到相同的问题,因此很一致。

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: 您的database.yml应该看起来像这样:

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. 在Rails应用程序可以连接到MySQL服务器之前,您需要安装MySQL适配器。 The mysql2 gem provides this functionality. mysql2 gem提供了此功能。 As the Rails user, install the mysql2 gem, like this: 以Rails用户身份,安装mysql2 gem,如下所示:
    \ngem install mysql2 gem安装mysql2 \n
  2. If you have config/database.yml file, keep file changes like this:(or create new file) 如果您有config / database.yml文件,请像这样保留文件更改:(或创建新文件)
    \ndevelopment: 发展:\n adapter: mysql2 适配器:mysql2\n encoding: utf8 编码:utf8\n database: my_db_name 数据库:my_db_name\n username: root 用户名:root\n password: my_password 密码:my_password\n host: 127.0.0.1 主持人:127.0.0.1\n port: 3306 端口:3306\n
  3. Create your application's development database using this rake command: 使用以下rake命令创建应用程序的开发数据库:
    \nrake db:create 耙db:create\n

Make your changes by following these steps.This will surely work for your development mode. 请按照以下步骤进行更改。这肯定适用于您的开发模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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