8

I am trying to create a database using rake db:create task.

When I am running the command bundle exec rake db:create to create the database and load the schema, I get the following error:

rake aborted!
Mysql2::Error: Unknown database 'xxx_development'

My database.yml:

development:
  adapter: mysql2
  host: localhost
  reconnect: true
  username: user
  password: password
  pool: 50
  database: xxx_development

I checked that mysql server is running and I am able to connect to it using the password/username I have in the database.yml

I also understand that I can go ahead and create the database in mysql and then run the bundle exec rake db:create but isn't the rake task db:create also creates a database in case it doesn't exists?

The rails version is 3.2.22. and mysql2 version is 2.9.13.

Any pointers will be highly appreciated.

5 Answers 5

1

If you are using ohmyzsh with bundler plugin which makes rake run by default with bundle exec, you can use

unbundled_rake db:create
Sign up to request clarification or add additional context in comments.

Comments

1

Ran into a similar issue on Rails 5 and the following steps helped me fix it:

Spring stop

./bin/rails db:create

Comments

0

I have two ideas.

  1. Check the User permissions
  2. When I run rake tasks, I don't use bundle exec (i.e just rake db:create)

Hope this is helpful

1 Comment

I have all the permissions for the mysql user but same error.
0

Try rake db:create RAILS_ENV=development hope this will work

2 Comments

@Undo thanks for the link. I see your point and have to apologise, I clearly misunderstood the concept. Will keep that in mind. Thanks again for pointing that out to me.
No problem @RenéVogt :)
0

For some reason rails db:create failed but my workaround was

to create dbs directly in mysql

sudo mysql
create database myapp_development;
create database myapp_test;

After that run as normal

rake db:migrate db:seed

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.