2017-02-28 97 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

相關問題