在我的rails应用程序中,我有数据库的配置
adapter: mysql2
host: *****
username: *****
password: <%= ENV['MYSQL_PW'] %>
database: *****
encoding: utf8
timeout: 5000
pool: 5
它在服务器中运行良好。但最近有一个错误,我试图访问rails控制台,但我收到此错误
Access denied for user '****' (using password: NO) (Mysql2::Error).
我也试图运行迁移,我再次遇到同样的错误。我不明白这里有什么问题。我怎么解决这个问题?
另外,我如何检查在unix环境变量中是否设置了ENV['MYSQL_PW']
?
这是我的日志
$ rake db:migrate
DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files` to clarify its role (it merely enables serving everything in the `public` folder and is unrelated to the asset pipeline). The `serve_static_assets` alias will be removed in Rails 5.0. Please migrate your configuration files accordingly. (called from block in <top (required)> at )
DEPRECATION WARNING: You did not specify a `log_level` in `production.rb`. Currently, the default value for `log_level` is `:info` for the production environment and `:debug` in all other environments. In Rails 5 the default value will be unified to `:debug` across all environments. To preserve the current setting, add the following line to your `production.rb`:
config.log_level = :info
. (called from block in tsort_each )
rake aborted!
Mysql2::Error: Access denied for user '****' (using password: NO)
答案 0 :(得分:0)
在运行命令时,不要忘记指定RAILS_ENV。
默认情况下,rails假定环境是开发环境,但正如我在此处所见,您希望在生产环境中运行这些环境。
简单地做
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rails c
# or alternatively
rails c -e production
答案 1 :(得分:0)
尝试以下方法:
database.yml
密码编辑为字符串而不是ENV变量,以识别问题。rails c
登录rails控制台并输入ENV['YourVariable']
以查看是否已设置source ~/.bash_profile
spring stop
<%= ENV['YOUR VARIABLE'] %>
Failing to access environment variables within `database.yml` file 我有这个问题,我能够解决它,但我一直有它们。出于这个原因,我读了几个讨论: Rails 4.1 environment variables not reloading
很抱歉,如果我无法提供更多帮助
Fabrizio Bertoglio