Can't connect to MySQL - You have an error in your SQL syntax

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Symptoms

Bitbucket Server fails to connect to MySQL database either when installing it or migrating databases. The following appears in the atlassian-bitbucket.log:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 The schema could not be created. com.atlassian.bitbucket.internal.db.DefaultDatabaseManager.createSchema(DefaultDatabaseManager.java:317) com.atlassian.bitbucket.internal.db.DefaultDatabaseManager.prepareDatabase(DefaultDatabaseManager.java:161) com.atlassian.bitbucket.internal.maintenance.SpringMaintenanceTaskFactory.setupTask(SpringMaintenanceTaskFactory.java:145) ... Error creating bean with name 'liquibasePrototype' defined in class path resource [bitbucket-context.xml]: Invocation of init method failed; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set com/atlassian/caviar/db/changelog/r1_0/initial-schema.xml::initial-schema-03::mheemskerk: Reason: liquibase.exception.DatabaseException: Error executing SQL CREATE TABLE `nb-bitbucket`.`cwd_app_dir_mapping` (`id` BIGINT NOT NULL, `application_id` BIGINT NOT NULL, `directory_id` BIGINT NOT NULL, `allow_all` CHARACTER(255) NOT NULL, `list_index` INT NULL, CONSTRAINT `SYS_PK_10077` PRIMARY KEY (`id`), CONSTRAINT `FK_APP_DIR_DIR` FOREIGN KEY (`directory_id`) REFERENCES nb-bitbucket.cwd_directory(id), CONSTRAINT `FK_APP_DIR_APP` FOREIGN KEY (`application_id`) REFERENCES nb-bitbucket.cwd_application(id)): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-bitbucket.cwd_directory(id), CONSTRAINT `FK_APP_DIR_APP` FOREIGN KEY (`application_' at line 1: Caused By: Error executing SQL CREATE TABLE `nb-bitbucket`.`cwd_app_dir_mapping` (`id` BIGINT NOT NULL, `application_id` BIGINT NOT NULL, `directory_id` BIGINT NOT NULL, `allow_all` CHARACTER(255) NOT NULL, `list_index` INT NULL, CONSTRAINT `SYS_PK_10077` PRIMARY KEY (`id`), CONSTRAINT `FK_APP_DIR_DIR` FOREIGN KEY (`directory_id`) REFERENCES nb-bitbucket.cwd_directory(id), CONSTRAINT `FK_APP_DIR_APP` FOREIGN KEY (`application_id`) REFERENCES nb-bitbucket.cwd_application(id)): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-bitbucket.cwd_directory(id), CONSTRAINT `FK_APP_DIR_APP` FOREIGN KEY (`application_' at line 1: Caused By: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-bitbucket.cwd_directory(id), CONSTRAINT `FK_APP_DIR_APP` FOREIGN KEY (`application_' at line 1 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ... Migration failed for change set com/atlassian/caviar/db/changelog/r1_0/initial-schema.xml::initial-schema-03::mheemskerk: Reason: liquibase.exception.DatabaseException: Error executing SQL CREATE TABLE `nb-bitbucket`.`cwd_app_dir_mapping` (`id` BIGINT NOT NULL, `application_id` BIGINT NOT NULL, `directory_id` BIGINT NOT NULL, `allow_all` CHARACTER(255) NOT NULL, `list_index` INT NULL, CONSTRAINT `SYS_PK_10077` PRIMARY KEY (`id`), CONSTRAINT `FK_APP_DIR_DIR` FOREIGN KEY (`directory_id`) REFERENCES nb-bitbucket.cwd_directory(id), CONSTRAINT `FK_APP_DIR_APP` FOREIGN KEY (`application_id`) REFERENCES nb-bitbucket.cwd_application(id)): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-bitbucket.cwd_directory(id), CONSTRAINT `FK_APP_DIR_APP` FOREIGN KEY (`application_' at line 1: Caused By: Error executing SQL CREATE TABLE `nb-bitbucket`.`cwd_app_dir_mapping` (`id` BIGINT NOT NULL, `application_id` BIGINT NOT NULL, `directory_id` BIGINT NOT NULL, `allow_all` CHARACTER(255) NOT NULL, `list_index` INT NULL, CONSTRAINT `SYS_PK_10077` PRIMARY KEY (`id`), CONSTRAINT `FK_APP_DIR_DIR` FOREIGN KEY (`directory_id`) REFERENCES nb-bitbucket.cwd_directory(id), CONSTRAINT `FK_APP_DIR_APP` FOREIGN KEY (`application_id`) REFERENCES nb-bitbucket.cwd_application(id)): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-bitbucket.cwd_directory(id), CONSTRAINT `FK_APP_DIR_APP` FOREIGN KEY (`application_' at line 1: Caused By: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-bitbucket.cwd_directory(id), CONSTRAINT `FK_APP_DIR_APP` FOREIGN KEY (`application_' at line 1 liquibase.changelog.ChangeSet.execute(ChangeSet.java:347) liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:27) liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:58) ... Error executing SQL CREATE TABLE `nb-bitbucket`.`cwd_app_dir_mapping` (`id` BIGINT NOT NULL, `application_id` BIGINT NOT NULL, `directory_id` BIGINT NOT NULL, `allow_all` CHARACTER(255) NOT NULL, `list_index` INT NULL, CONSTRAINT `SYS_PK_10077` PRIMARY KEY (`id`), CONSTRAINT `FK_APP_DIR_DIR` FOREIGN KEY (`directory_id`) REFERENCES nb-bitbucket.cwd_directory(id), CONSTRAINT `FK_APP_DIR_APP` FOREIGN KEY (`application_id`) REFERENCES nb-bitbucket.cwd_application(id)): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-bitbucket.cwd_directory(id), CONSTRAINT `FK_APP_DIR_APP` FOREIGN KEY (`application_' at line 1 liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:62) liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:104) liquibase.database.AbstractDatabase.execute(AbstractDatabase.java:1091) ... You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-bitbucket.cwd_directory(id), CONSTRAINT `FK_APP_DIR_APP` FOREIGN KEY (`application_' at line 1 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ...

Cause

The issue here is that the MySQL documentation indicates that unquoted identifiers can only contain letters, numbers, $ and _. -'s (hyphens) are not supported in unquoted literals. The schema management tool Bitbucket Server uses (Liquibase) generally does a good job of escaping names for us, but sometimes it misses it. Bitbucket Server internally uses underscores in all of our names for this exact reason.

Resolution

A name for the database like nbbitbucket or nb_bitbucket should work.

Just change the database name and reconnect.

Updated on April 8, 2025

Still need help?

The Atlassian Community is here for you.