尝试运行rake db:create
或rake db:setup
时收到此错误消息:
Couldn't create database for {"adapter"=>"mysql2", "host"=>"localhost", "database"=>"mydb_dev"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"}
Couldn't create database for {"adapter"=>"mysql2", "host"=>"localhost", "database"=>"mydb_test"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"}
我更新了mysql2,mysql --version
返回:
mysql Ver 14.14 Distrib 5.6.16, for osx10.9 (x86_64) using EditLine wrapper
这是我的database.yml:
development:
adapter: mysql2
host: localhost
database: mydb_dev
# 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
host: localhost
database: mydb_test
production:
adapter: mysql2
host: localhost
database: mydb_prod
为什么rake
命令无法创建数据库?
答案 0 :(得分:2)
尝试以下配置:
adapter: mysql
database: my_db #name of your database
hostname: 127.0.0.1
username: root #your username
password: # your password
socket: /tmp/mysql.sock #socket parameter is also important
pool: 5
timeout: 5000
访问此链接时出现类似问题(Error creating Rails DB using rake db:create)
答案 1 :(得分:0)
尝试指定数据库的用户名和密码。
development:
adapter: mysql2
host: localhost
database: mydb_dev
username: root
password:
您可以在Rails Guide
中详细了解如何配置数据库