2014-04-10 25 views
1

所以我試圖爲.yml文件中建議的我的rails生產環境數據庫設置一個環境變量。在我的.bash_profile我導出這樣的:rails database_url轉義mysql2 url passwod

export DATABASE_URL=mysql2://<username>:<password>@localhost/<database> 

我去我的網站,我得到「ActiveRecord::AdapterNotSpecified」的錯誤。

我能想到的唯一的事情就是我的密碼以@符號結尾,這會使得url有@@,並且在密碼結束和主機開始的地方變得困惑。

而且這個程序是在Hostmonster的託管是否有幫助

的database.yml:

default: &default 
    adapter: mysql2 
    encoding: utf8 
    pool: 5 
    username: <username> 
    password: <password> 
    database: <database> 

development: 
    <<: *default 
    database: <database> 

# Warning: The database defined as "test" will be erased and 
# re-generated from your development database when you run "rake". 
# Do not set this db to the same as development or production. 
test: 
    <<: *default 
    database: <database> 

# Avoid production credentials in the repository, 
# instead read the configuration from the environment. 
# 
# Example: 
# mysql2://myuser:[email protected]/somedatabase 
# 
production: 
    url: <%= ENV["DATABASE_URL"] %> 
+0

你的'config/database.yml'文件是什麼樣的? – tadman

+0

database.yml added –

回答

2

您可能需要包括默認的部分,以及:

production: 
    <<: *default 

如果您的密碼有一個@在它,嘗試編碼爲一個URL:

password%40 

這可能是事情。要麼或者選擇一個URL友好的密碼。

請注意,通常最好將database.yml文件專門用於目標服務器上的生產,然後在部署應用程序時將其符號鏈接。

+0

這就是它....現在感覺非常愚蠢。 –