2012-05-14 94 views
2
Access denied for user 'root'@'localhost' (using password: YES) 

我設置了一個新的環境,其中mysql沒有密碼以及我如何得到此錯誤。我在哪裏改變rails應用程序顯示在瀏覽器中拒絕訪問

'root'@'localhost' (using password: YES) 

我的database.yml是展示低於我的數據庫是sample_app

# SQLite version 3.x 
# gem install sqlite3 
# 
# Ensure the SQLite 3 gem is defined in your Gemfile 
# gem 'sqlite3' 
development: 
    adapter: mysql2 
    database: db/development.mysql2 
    pool: 5 
    timeout: 5000 
    database: sample_app 
    username: root 
    socket: /tmp/mysql.sock 

# 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: 
    adapter: mysql2 
    database: db/test.mysql2 
    pool: 5 
    timeout: 5000 
    database: sample_app 
    username: root 
    socket: /tmp/mysql.sock 

production: 
    adapter: mysql2 
    database: db/production.mysql2 
    pool: 5 
    timeout: 5000 
    database: sample_app 
    username: root 
    socket: /var/run/mysqld/mysqld.sock 
+0

您可能感興趣的相關問題:http://serverfault.com/questions/56120/access-denied-for-user-rootlocalhost-using-passwordno – murgatroid99

+0

顯示您的database.yml –

回答

1

你不應該用root連接到使用一個應用程序分貝。使用名稱創建一個新的用戶名/密碼,以識別它正在用於特定的應用程序\任務,然後使用該名稱而不是root。

添加此空密碼password:

production: 
    adapter: mysql2 
    database: db/production.mysql2 
    pool: 5 
    timeout: 5000 
    database: sample_app 
    username: root 
    password: 
    socket: /var/run/mysqld/mysqld.sock 

如果仍然出現拒絕訪問,然後將DB是說,用戶\密碼無效

1

若此,

$ mysql -u root 

帶你到mysql然後這將工作,

production: 
    adapter: mysql2 
    database: db/production.mysql2 
    pool: 5 
    timeout: 5000 
    database: sample_app 
    username: root 
    password: 
    socket: /var/run/mysqld/mysqld.sock 

如果已設置了一些密碼,你的root用戶,然後嘗試

$ mysql -u root -p 
<<It will prompt for a password, key it in>> 

如果需要你到mysql那麼這將工作,

production: 
    adapter: mysql2 
    database: db/production.mysql2 
    pool: 5 
    timeout: 5000 
    database: sample_app 
    username: root 
    password: <<password>> 
    socket: /var/run/mysqld/mysqld.sock 

這個故事的寓意:

首先,嘗試從命令行使用mysql命令登錄到mysql並查看它是否有效。 然後,在database.yml中使用這些憑據並從rails應用程序登錄到mysql。

相關問題