Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rake db:create - Mysql2::Error: Unknown database

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.

like image 351
harshs08 Avatar asked Oct 30 '22 10:10

harshs08


1 Answers

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

unbundled_rake db:create
like image 175
Vasfed Avatar answered Nov 09 '22 14:11

Vasfed