【发布时间】:2016-02-18 20:35:41
【问题描述】:
rails 4.2.5 中的某处是否有设置使其尝试在没有密码的情况下登录以测试和开发数据库。
我面临的问题是我无法运行 rake db:migrate、rake db:create 等命令。我总是在不使用密码时出错。不是密码错误,只是rails没有使用提供的密码。见下文。
rake aborted!
Mysql2::Error: Access denied for user 'sharetribe'@'localhost' (using password: NO)
当我检查 database.yml 密码实际上是正确的。我还通过使用相同的用户和密码从控制台运行登录到数据库来测试这一点。我还尝试删除数据库并再次创建它。这是我的database.yml
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: mysql2
database: sharetribe_development
encoding: utf8
username: sharetribe
password: ***********
host: localhost
# 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.
# The example has user root for tests to work with Travis CI
test: &test
adapter: mysql2
database: sharetribe_test
encoding: utf8
username: root
password: **********
host: localhost
staging:
adapter: mysql2
database: sharetribe_staging
encoding: utf8
username: sharetribe
password: *********
host: localhost
production:
adapter: mysql2
database: sharetribe_production
encoding: utf8
username: sharetribe
password: ***********
host: localhost
# socket: /var/run/mysqld/mysqld.sock
cucumber:
<<: *test
这里是mysql命令行输出。
mysql> SHOW DATABASES;
+------------------------+
| Database |
+------------------------+
| information_schema |
| mysql |
| performance_schema |
| sharetribe_development |
| sharetribe_production |
| sharetribe_test |
| sys |
+------------------------+
7 rows in set (0.01 sec)
mysql> SHOW GRANTS FOR 'sharetribe'@'localhost';
+--------------------------------------------------------------------------------+
| Grants for sharetribe@localhost |
+--------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'sharetribe'@'localhost' |
| GRANT ALL PRIVILEGES ON `sharetribe_development`.* TO 'sharetribe'@'localhost' |
| GRANT ALL PRIVILEGES ON `sharetribe_test`.* TO 'sharetribe'@'localhost' |
| GRANT ALL PRIVILEGES ON `sharetribe_production`.* TO 'sharetribe'@'localhost' |
+--------------------------------------------------------------------------------+
4 rows in set (0.01 sec)
【问题讨论】:
标签: mysql ruby-on-rails ruby-on-rails-4