【问题标题】:MySQL with Rails driving me with local install带有 Rails 的 MySQL 驱动我进行本地安装
【发布时间】: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


    【解决方案1】:

    也许您的密码在 database.yml 中有一些特殊字符未正确转义。您是否尝试将它们更改为更简单?

    【讨论】:

    • 好的,这里还有其他内容。更改数据库不起作用,但我确实注意到一些非常奇怪的东西,而 rake db:migrate 给出错误 Mysql2::Error: Access denied for user 'sharetribe'@'localhost' (using password: NO) RAILS_ENV=test rake db:migrate 实际上给出我的耙子流产了! Mysql2::Error: Access denied for user 'root'@'localhost' (using password: YES) 它绝对没有使用 database.yml 文件信息。
    • 所以除了database.yml这个项目还包括database.example.yml,看起来Rails删除它并没有那么挑剔,rake开始运行。我现在有一个新错误,但那是另一回事了。
    猜你喜欢
    • 2020-04-25
    • 1970-01-01
    • 1970-01-01
    • 2018-04-16
    • 2013-08-22
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多