'ER_BAD_DB_ERROR on connecting to database using Sequelize

I have a project that utilizes the npm packages mysql, Sequelize and redis.

The following goes well:

app.use(express.session({
  store: new RedisStore({
    host: 'localhost',
    port: 6379,
    db:   2,
    pass: 'RedisPASS'
  }),
  secret: 'secret' // changed this value of course
}));

And then:

Sequelize.connection = new Sequelize('test_ddb',
  'root', 'root', { logging: false });

Which throws the following error:

Error: ER_BAD_DB_ERROR: Unknown database 'test_ddb'

I tried a couple of things, first I thought Sequelize is not connecting to MAMP's mysql but the my system's mysql, but I had all the symlinks already setup. Like so:

/var/mysql/mysql.sock -> /Applications/MAMP/tmp/mysql/mysql.sock

I even changed it here:

/usr/local/mysql/bin/mysql -> /Applications/MAMP/Library/bin/mysql

The mysql command in the terminal also utilizes the MAMP database.



Solution 1:[1]

Are you sure MySQL is running? Can you connect to it with the MySQL command line client?

Solution 2:[2]

Can you try the idiomatic way of initializing Sequelize:

var sequelize = new Sequelize('test_ddb', 'root', 'root')

Solution 3:[3]

This error is caused usually if there is no database in the first place.

CREATE DATABASE in mysql before you run Sequelize.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dan Kohn
Solution 2 Dan Kohn
Solution 3 Drew