Mysql: ER_BAD_DB_ERROR: Unknown database 'x'

Created on 13 Mar 2016  路  9Comments  路  Source: mysqljs/mysql

I getting this error when running DROP DATABASE IF EXISTS x query. It shouldn't give me error when database doesn't exists only warning.

question

Most helpful comment

Thanks! So the error is coming back from your MySQL and this module is just passing it through. There doesn't seem to be anything wrong with this module, I'm sorry.

The reason you are having that error is because you specified database: 'x' in your createConnection, but your MySQL server is saying there is no such database as that, and so you can't establish the connection to the database you wanted, thus the error.

All 9 comments

Hi @Almis90, sorry I didn't get back right away. I see you closed this issue, though. Are you still having the issue or has it been resolved? The errors this module returns like that are simply coming from your MySQL server.

I closed this because I though the error is not related to my query because CREATE DATABASE IF NOT EXISTS x CHARACTER SET utf8 COLLATE utf8_general_ci (I didn't have database x) also gives the same error. After creating the database manually the drop and create query works. Not sure what is the issue.

Can you add debug: true to your createConnection, run your script that has this issue, and paste the output here?

<-- HandshakeInitializationPacket
HandshakeInitializationPacket {
  protocolVersion: 10,
  serverVersion: '5.6.27-log',
  threadId: 28,
  scrambleBuff1: <Buffer 7a 24 40 56 70 4f 7b 40>,
  filler1: <Buffer 00>,
  serverCapabilities1: 63487,
  serverLanguage: 33,
  serverStatus: 2,
  serverCapabilities2: 32895,
  scrambleLength: 21,
  filler2: <Buffer 00 00 00 00 00 00 00 00 00 00>,
  scrambleBuff2: <Buffer 6a 75 31 2e 33 54 2d 25 6e 21 54 64>,
  filler3: <Buffer 00>,
  pluginData: 'mysql_native_password',
  protocol41: true }

--> ClientAuthenticationPacket
ClientAuthenticationPacket {
  clientFlags: 455631,
  maxPacketSize: 0,
  charsetNumber: 33,
  filler: undefined,
  user: 'root',
  scrambleBuff: <Buffer 31 ee b9 06 a6 21 44 ec 9c 57 30 70 88 8b e2 9e 6e 40 80 14>,
  database: 'x',
  protocol41: true }

<-- ErrorPacket
ErrorPacket {
  fieldCount: 255,
  errno: 1049,
  sqlStateMarker: '#',
  sqlState: '42000',
  message: 'Unknown database \'x\'' }

Thanks! So the error is coming back from your MySQL and this module is just passing it through. There doesn't seem to be anything wrong with this module, I'm sorry.

The reason you are having that error is because you specified database: 'x' in your createConnection, but your MySQL server is saying there is no such database as that, and so you can't establish the connection to the database you wanted, thus the error.

When I run this manually on mysql workbench I getting 14:55:27 DROP DATABASE IF EXISTS x 0 row(s) affected, 1 warning(s): 1008 Can't drop database 'x'; database doesn't exist 0.000 sec I don't get the above error.

Well, you're probably not telling it to open the initial connect to databsse 'x'. The issue is that you have the database option in your createConnection set to a non-existent database. Just remove the database option if you don't want to initially connect to a specific database.

Like I said, the error you're seeing is coming directly from your MySQL server. This module is simply a protocol client, and will pass through whatever errors your MySQL server gives, so there is nothing we can change. If you need help with the MySQL itself, you may want to use the MySQL forms, rather than this issue tracker.

Thank you, after removing database from options everything is fine.

i did like this, but something wrong , it still run, not stop, i can't type anything . although it connected

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tbaustin picture tbaustin  路  3Comments

abou7mied picture abou7mied  路  4Comments

ajpyoung picture ajpyoung  路  4Comments

DmitryEfimenko picture DmitryEfimenko  路  4Comments

Axxxx0n picture Axxxx0n  路  3Comments