Question

When trying to run rake db:create or rake db:setup I'm getting this error message:

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"}

I have updated mysql2 and mysql --version returns:

mysql  Ver 14.14 Distrib 5.6.16, for osx10.9 (x86_64) using  EditLine wrapper

Here's my 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

Why can't the rake command create the database?

Was it helpful?

Solution

Try specifying the username and password for your database.

development:
  adapter: mysql2
  host: localhost
  database: mydb_dev
  username: root
  password:

You can learn more about configuring a database in the Rails Guide

OTHER TIPS

Try These configurations:

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

Visit this link a similar question (Error creating Rails DB using rake db:create)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top