Bug #95564 createDatabaseIfNotExist is not working for databases with hyphen in name
Submitted: 29 May 2019 14:16 Modified: 11 Jun 2019 10:17
Reporter: M O Email Updates:
Status: Verified Impact on me:
Category:Connector / J Severity:S3 (Non-critical)
Version:8.0.14, 8.0.16 OS:Microsoft Windows
Assigned to: CPU Architecture:x86

[29 May 2019 14:16] M O
When I try to connect to a non-existing database with hyphen in the name, the create query failed because the name is not quoted.

How to repeat:
Connect to a non-existing database with hyphen in name and createDatabaseIfNotExist set to true. Example: jdbc:mysql://localhost:3306/my-db?createDatabaseIfNotExist=true

Suggested fix:
In NativeProtocol.java on row 543:

sendCommand(this.commandBuilder.buildComQuery(getSharedSendPacket(), "CREATE DATABASE IF NOT EXISTS " + database), false, 0);

Variable database should be quoted.
[11 Jun 2019 10:17] MySQL Verification Team

Thank you for the report.