[英]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.
这将适用于您的开发模式。
\ngem install mysql2gem安装mysql2 \n
\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
\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.