我正在启动一个新的 rails 3 应用程序,当我运行rake db:create
它时会询问我的 root mysql 密码,然后错误提示:
Mysql2::Error: 用户'arcsite_mysql'@'localhost'拒绝访问数据库'arcsite_mysql_test': CREATE DATABASE
arcsite_mysql_test
DEFAULT CHARACTER SETutf8
COLLATEutf8_unicode_ci
如果我在命令行上登录 mysql 并运行,show databases;
我会看到:
arcsite_mysql_development
如果我跑步,SHOW GRANTS FOR arcsite_mysql@localhost
我会看到:
GRANT ALL PRIVILEGES ON `arcsite_mysql_development`.* TO 'arcsite_mysql'@'localhost' WITH GRANT OPTION
我的数据库.yml:
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: arcsite_mysql_development
pool: 5
username: arcsite_mysql
password: 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.
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: arcsite_mysql_test
pool: 5
username: arcsite_mysql
password: password
host: localhost
因此,出于某种原因,只创建了开发数据库。
版本:
导轨 3.2.13
MySQL:服务器版本:5.6.10 源码分发
mysql2:mysql2-0.3.11
编辑
如果我手动将所有权限授予arcsite_mysql
用户,我可以创建表。但是是否期望 Rails 会为开发而不是为测试环境创建用户和表?当我第一次运行命令时,arcsite_mysql
用户是由 rails 创建的。rake db:create
编辑 2
提到了一些涉及 mysql 用户创建的“众所周知的”过程。