在database.yml中更正用户名和密码,但不接受密码

时间:2011-12-04 23:28:09

标签: mysql ruby ruby-on-rails-3 osx-lion

在OS X Lion上,我无法找到为什么它不接受我的密码。我可以连接到数据库并从mysql工作台管理它,但rails似乎无法连接。

从mysql站点下载的dmg安装了Mysql。

我尝试过从mysql命令行授予权限:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost'

这是来自rake db:create的跟踪我还尝试了bundle exec rake db:create

Access denied for user 'root'@'localhost' (using password: YES)
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/mysql2-0.3.10/lib/mysql2/client.rb:44:in `connect'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/mysql2-0.3.10/lib/mysql2/client.rb:44:in `initialize'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `n
ew'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `m
ysql2_connection'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.r
b:304:in `new_connection'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.r
b:323:in `checkout_new_connection'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.r
b:265:in `block (2 levels) in checkout'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.r
b:261:in `loop'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.r
b:261:in `block in checkout'
/Users/adamar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.r
b:260:in `checkout'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.r
b:162:in `connection'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.r
b:409:in `retrieve_connection'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specif
ication.rb:107:in `retrieve_connection'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specif
ication.rb:89:in `connection'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:97:in `rescue in rescu
e in create_database'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:84:in `rescue in creat
e_database'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:54:in `create_database
'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:42:in `block (2 levels
) in <top (required)>'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib
/Users/adamar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/bin/rake:19:in `load'
/Users/adamar/.rvm/gems/ruby-1.9.3-p0/bin/rake:19:in `<main>'
Tasks: TOP => db:create

编辑:当我跑步时:mysql -u root -p我明白了:

Adamars-MacBook-Pro:~ adamar$ mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

这就是我的database.yml

test:
  adapter: mysql2
  encoding: utf8
  database: linkdeck_test
  username: root
  password: 
  pool: 5
  host: 127.0.0.1
  port: 3306

development:
  adapter: mysql2
  encoding: utf8
  database: linkdeck_development
  username: root
  password: 
  pool: 5
  host: 127.0.0.1
  port: 3306

production:
  adapter: mysql
  encoding: utf8
  database: linkdeck_production
  username: root
  password: 
  host: 127.0.0.1
  port: 3306

1 个答案:

答案 0 :(得分:2)

这看起来很痛苦,但你确定它是对的吗?您说您正在使用工作台GUI,这与从Rails连接它并不相同,因此无法证明您的配置是正确的。

仔细检查以下内容。首先,请确保您的config/database.yml包含以下内容:

development:
  adapter: mysql2
  database: example_development
  username: root
  password: admin12345

如果是,可以运行mysql -u root -p并提供与config/database.yml中密码相同的密码吗?如果没有,那么你的权限就出了问题。

另外,请确保在安装mysql时,通过通常的brew install mysql或其他类似的包管理方法执行此操作。


更新:您无法看到数据库,这极有说明您有权限问题。确保您已创建用户并允许其访问所有数据库。