2017-02-28 100 views
0

在我的Rails应用程序我有这样的配置数据库的MySQL:拒绝访问用户

adapter: mysql2 
    host: ***** 
    username: ***** 
    password: <%= ENV['MYSQL_PW'] %> 
    database: ***** 
    encoding: utf8 
    timeout: 5000 
    pool: 5 

它在服务器正常使用。但是最近出现了一个错误,我试图访问轨控制台,但我得到这个错误

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

你100%确定的环境变量“MYSQL_PW”的设置是否正确?你可以仔细检查它在终端的价值吗? – RichardAE

+0

尝试粘贴密码而不是<%= ENV ['MYSQL_PW']%>并查看它是否有效 –

+0

@RichardAE如何在终端中检查其值?我在终端尝试了ENV ['MYSQL_PW']'和'ENV,但是它没有找到命令。 – asdlfkjlkj

回答

0

不要忘了,当你运行你的命令来指定RAILS_ENV。

默认情况下,rails假定环境是开发,但正如我在这里看到的,您希望在生产环境中运行这些环境。

根本就

RAILS_ENV=production rake db:migrate 
RAILS_ENV=production rails c 
# or alternatively 
rails c -e production 

http://guides.rubyonrails.org/command_line.html

0

尝试以下操作:

  1. 编辑database.yml密码是一个字符串,而不是ENV变量,找出问题所在。
  2. 要测试环境变量,登录与rails c和输入ENV['YourVariable']轨道控制台,看它是否被设置
  3. 你可以,如果你有Unix的系统解决了采购你的.bash_profile文件这个问题(的Linux/Ubuntu的/ MAC)在终端输入source ~/.bash_profile
  4. 如果有导轨4时,你应该运行下面的命令终端spring stop
  5. 在database.yml的则应该包括ENV变量使用以下语法,怎么一回事,因为YML需要.erb语法。 <%= ENV['YOUR VARIABLE'] %> Failing to access environment variables within `database.yml` file
  6. 的环境变量是区分大小写

我有这个问题,我能解决这个问题,但我一直有他们。出于这个原因,我读了多次讨论: Rails 4.1 environment variables not reloading

很抱歉,如果我没能帮助更多的

法布里奇奥Bertoglio

相关问题