Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL flywayMigrate fails due to user permission #793

Closed
wilkincheung opened this issue Jun 27, 2014 · 4 comments
Closed

MySQL flywayMigrate fails due to user permission #793

wilkincheung opened this issue Jun 27, 2014 · 4 comments

Comments

@wilkincheung
Copy link

@wilkincheung wilkincheung commented Jun 27, 2014

Setup: MySQL 5.6 + Gradle + flyway 3.0

When running flywayMigrate, after all db scripts are run successfully, flyway tries to access a new database with UUID. Because the user does not have access to db name=UUID, MySQL denies access, and flywayMigrate fails.

db scripts are run successfully -- after the command is run, I check schema_version table the scripts are defined in that table, and the status flag shows success.

My question: Why would flywayMigrate access database name UUID ? This looks like a bug to me.

:common:flywayMigrate FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':common:flywayMigrate'.

    Error occurred while executing flywayMigrate
    Error setting current schema to ``
    Access denied for user 'myuser'@'%' to database '409b3523-da3d-494b-b063-b2b92518c9be'

@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Jun 29, 2014

The truth is, it doesn't. It only accesses the DB with the URL, user and password you provide. It opens two connections (one for Flyway itself, and one for the migrations), nothing more. What does your config look like? Also what does the debug output look like?

@wilkincheung
Copy link
Author

@wilkincheung wilkincheung commented Jul 2, 2014

gradle debug log is below.

  • project name is renamed myproject per my company policy.
  • MySQL username is myproject (same as project name)

Build machine config

  • gradle 1.12
  • flyway 3.0
  • Mac OSX 10.9.3
  • Java runtime 1.7.0_51

DB machine config

  • MySQL 5.6 / linux

build.gradle (flyway code snippet):
flyway {
driver = 'com.mysql.jdbc.Driver'
url = 'jdbc:mysql://replace.with.actual.hostname/?'
user = 'myproject'
password = ''
schemas = ['myproject']
table = 'schema_history'
}

Related debug log running "gradle flywayMigrate":
18:42:36.049 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Found resource: db/migration/V20140519_1__script1.sql
18:42:36.049 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Found resource: db/migration/V20140617_1__script2.sql
18:42:36.049 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Found resource: db/migration/V20140623_1__script3.sql
18:42:36.058 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning for classes at 'db/migration' (Implementing: 'org.flywaydb.core.api.migration.jdbc.JdbcMigration')
18:42:36.059 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning URL: file:/opt/buildAgent/work/4ca2640a4c361d20/common/build/resources/main/db/migration
18:42:36.060 [DEBUG] [org.flywaydb.core.internal.util.FeatureDetector] JBoss VFS v2 available: false
18:42:36.061 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.FileSystemClassPathLocationScanner] Scanning starting at classpath root in filesystem: /opt/buildAgent/work/4ca2640a4c361d20/common/build/resources/main/
18:42:36.061 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.FileSystemClassPathLocationScanner] Scanning for resources in path: /opt/buildAgent/work/4ca2640a4c361d20/common/build/resources/main/db/migration (db/migration)
18:42:36.062 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/V20140513_1__init_schema.sql (filename: V20140513_1__init_schema.sql)
18:42:36.062 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/V20140519_1__script1.sql (filename: V20140519_1__script1.sql)
18:42:36.062 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/V20140617_1__script2.sql (filename: V20140617_1__script2.sql)
18:42:36.063 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/V20140623_1__script3.sql (filename: V20140623_1__script3.sql)
18:42:36.064 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning for classes at 'db/migration' (Implementing: 'org.flywaydb.core.api.migration.spring.SpringJdbcMigration')
18:42:36.065 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning URL: file:/opt/buildAgent/work/4ca2640a4c361d20/common/build/resources/main/db/migration
18:42:36.066 [DEBUG] [org.flywaydb.core.internal.util.FeatureDetector] JBoss VFS v2 available: false
18:42:36.066 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.FileSystemClassPathLocationScanner] Scanning starting at classpath root in filesystem: /opt/buildAgent/work/4ca2640a4c361d20/common/build/resources/main/
18:42:36.066 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.FileSystemClassPathLocationScanner] Scanning for resources in path: /opt/buildAgent/work/4ca2640a4c361d20/common/build/resources/main/db/migration (db/migration)
18:42:36.067 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/V20140513_1__init_schema.sql (filename: V20140513_1__init_schema.sql)
18:42:36.068 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/V20140519_1__script1.sql (filename: V20140519_1__script1.sql)
18:42:36.068 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/V20140617_1__script2.sql (filename: V20140617_1__script2.sql)
18:42:36.068 [DEBUG] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/V20140623_1__script3.sql (filename: V20140623_1__script3.sql)
18:42:36.104 [INFO] [org.flywaydb.core.internal.command.DbValidate] Validated 5 migrations (execution time 00:00.076s)
18:42:36.125 [DEBUG] [org.flywaydb.core.internal.command.DbSchemas] Schema myproject already exists. Skipping schema creation.
18:42:36.151 [DEBUG] [org.flywaydb.core.internal.dbsupport.Table] Locking table myproject.schema_history...
18:42:36.153 [DEBUG] [org.flywaydb.core.internal.dbsupport.Table] Lock acquired for table myproject.schema_history
18:42:36.164 [INFO] [org.flywaydb.core.internal.command.DbMigrate] Current version of schema myproject: 20140623.1
18:42:36.167 [INFO] [org.flywaydb.core.internal.command.DbMigrate] Schema myproject is up to date. No migration necessary.
18:42:36.242 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':common:flywayMigrate'
18:42:36.243 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :common:flywayMigrate FAILED
18:42:36.244 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :common:flywayMigrate (Thread[main,5,main]) completed. Took 1.939 secs.
18:42:36.245 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[main,5,main]] finished, busy: 11.762 secs, idle: 0.011 secs
18:42:36.257 [ERROR] [org.gradle.BuildExceptionReporter]
18:42:36.259 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
18:42:36.261 [ERROR] [org.gradle.BuildExceptionReporter]
18:42:36.263 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
18:42:36.263 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':common:flywayMigrate'.
18:42:36.264 [ERROR] [org.gradle.BuildExceptionReporter] > Error occurred while executing flywayMigrate
18:42:36.265 [ERROR] [org.gradle.BuildExceptionReporter] Error setting current schema to 18:42:36.265 [ERROR] [org.gradle.BuildExceptionReporter] Access denied for user 'myproject'@'%' to database '10d917ff-3b78-4e20-8357-5de417171b31' 18:42:36.266 [ERROR] [org.gradle.BuildExceptionReporter] 18:42:36.271 [ERROR] [org.gradle.BuildExceptionReporter] 18:42:36.271 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is: 18:42:36.274 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':common:flywayMigrate'. 18:42:36.274 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69) 18:42:36.275 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46) 18:42:36.275 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35) 18:42:36.275 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64) 18:42:36.276 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) 18:42:36.276 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42) 18:42:36.276 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) 18:42:36.277 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53) 18:42:36.278 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) 18:42:36.279 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:289) 18:42:36.280 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79) 18:42:36.282 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63) 18:42:36.282 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51) 18:42:36.290 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23) 18:42:36.291 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86) 18:42:36.293 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29) 18:42:36.294 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) 18:42:36.295 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23) 18:42:36.295 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67) 18:42:36.297 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32) 18:42:36.298 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) 18:42:36.300 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54) 18:42:36.301 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166) 18:42:36.302 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113) 18:42:36.303 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81) 18:42:36.303 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64) 18:42:36.303 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33) 18:42:36.304 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24) 18:42:36.304 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35) 18:42:36.305 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26) 18:42:36.305 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50) 18:42:36.307 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171) 18:42:36.308 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201) 18:42:36.309 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174) 18:42:36.309 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170) 18:42:36.309 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139) 18:42:36.309 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33) 18:42:36.310 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22) 18:42:36.310 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.Main.doAction(Main.java:46) 18:42:36.310 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45) 18:42:36.310 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.Main.main(Main.java:37) 18:42:36.310 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50) 18:42:36.310 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32) 18:42:36.311 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.GradleMain.main(GradleMain.java:23) 18:42:36.311 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.flywaydb.core.api.FlywayException: Error occurred while executing flywayMigrate 18:42:36.311 [ERROR] [org.gradle.BuildExceptionReporter] Error setting current schema to
18:42:36.312 [ERROR] [org.gradle.BuildExceptionReporter] Access denied for user 'myproject'@'%' to database '10d917ff-3b78-4e20-8357-5de417171b31'
18:42:36.313 [ERROR] [org.gradle.BuildExceptionReporter]
18:42:36.314 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.gradle.task.AbstractFlywayTask.handleException(AbstractFlywayTask.groovy:167)
18:42:36.316 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.gradle.task.AbstractFlywayTask.this$4$handleException(AbstractFlywayTask.groovy)
18:42:36.318 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.gradle.task.AbstractFlywayTask$this$4$handleException.callCurrent(Unknown Source)
18:42:36.319 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.gradle.task.AbstractFlywayTask.runTask(AbstractFlywayTask.groovy:77)
18:42:36.320 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
18:42:36.321 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:219)
18:42:36.321 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212)
18:42:36.324 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201)
18:42:36.326 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:533)
18:42:36.326 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:516)
18:42:36.327 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
18:42:36.328 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
18:42:36.329 [ERROR] [org.gradle.BuildExceptionReporter] ... 43 more
18:42:36.330 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.flywaydb.core.api.FlywayException: Error setting current schema to ``
18:42:36.332 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.core.internal.dbsupport.DbSupport.setCurrentSchema(DbSupport.java:102)
18:42:36.335 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.core.Flyway$1.execute(Flyway.java:867)
18:42:36.337 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.core.Flyway$1.execute(Flyway.java:811)
18:42:36.338 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.core.Flyway.execute(Flyway.java:1171)
18:42:36.339 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.core.Flyway.migrate(Flyway.java:811)
18:42:36.339 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.core.Flyway$migrate.call(Unknown Source)
18:42:36.340 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.gradle.task.FlywayMigrateTask.run(FlywayMigrateTask.groovy:30)
18:42:36.341 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.gradle.task.FlywayMigrateTask$run.callCurrent(Unknown Source)
18:42:36.344 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.gradle.task.AbstractFlywayTask.runTask(AbstractFlywayTask.groovy:75)
18:42:36.345 [ERROR] [org.gradle.BuildExceptionReporter] ... 51 more
18:42:36.345 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'myproject'@'%' to database '10d917ff-3b78-4e20-8357-5de417171b31'
18:42:36.347 [ERROR] [org.gradle.BuildExceptionReporter] at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
18:42:36.347 [ERROR] [org.gradle.BuildExceptionReporter] at com.mysql.jdbc.Util.getInstance(Util.java:384)
18:42:36.348 [ERROR] [org.gradle.BuildExceptionReporter] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
18:42:36.349 [ERROR] [org.gradle.BuildExceptionReporter] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4232)
18:42:36.352 [ERROR] [org.gradle.BuildExceptionReporter] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4164)
18:42:36.352 [ERROR] [org.gradle.BuildExceptionReporter] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
18:42:36.354 [ERROR] [org.gradle.BuildExceptionReporter] at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
18:42:36.356 [ERROR] [org.gradle.BuildExceptionReporter] at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)
18:42:36.357 [ERROR] [org.gradle.BuildExceptionReporter] at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
18:42:36.357 [ERROR] [org.gradle.BuildExceptionReporter] at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1307)
18:42:36.359 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.core.internal.dbsupport.JdbcTemplate.execute(JdbcTemplate.java:219)
18:42:36.359 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.core.internal.dbsupport.mysql.MySQLDbSupport.doSetCurrentSchema(MySQLDbSupport.java:59)
18:42:36.360 [ERROR] [org.gradle.BuildExceptionReporter] at org.flywaydb.core.internal.dbsupport.DbSupport.setCurrentSchema(DbSupport.java:100)
18:42:36.361 [ERROR] [org.gradle.BuildExceptionReporter] ... 59 more
18:42:36.362 [ERROR] [org.gradle.BuildExceptionReporter]
18:42:36.363 [LIFECYCLE] [org.gradle.BuildResultLogger]
18:42:36.365 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED
18:42:36.367 [LIFECYCLE] [org.gradle.BuildResultLogger]
18:42:36.368 [LIFECYCLE] [org.gradle.BuildResultLogger] Total time: 43.388 secs
18:42:36.370 [DEBUG] [org.gradle.api.internal.tasks.compile.daemon.CompilerDaemonManager] Stopping 0 compiler daemon(s).

@wilkincheung
Copy link
Author

@wilkincheung wilkincheung commented Jul 3, 2014

I think I found the root cause, the flyway code has a "weird hack” (quote directly from flyway source code, see below). Essentially, after db migration scripts are run, successful or not, the flyway code checks if default schema is empty (I believe JDBC String contains the default schema). If empty, then create a new database with random UUID string, then drop that database. This action is causing flywayMigrate to fail with error.

Code excerpt from org.flywaydb.core.internal.dbsupport.mysql.MySQLDbSupport in flyway 3.0 library:

@Override
protected void doSetCurrentSchema(Schema schema) throws SQLException {
    if ("".equals(schema.getName())) {
        // Weird hack to switch back to no database selected...
        String newDb = quote(UUID.randomUUID().toString());
        jdbcTemplate.execute("CREATE SCHEMA " + newDb);
        jdbcTemplate.execute("USE " + newDb);
        jdbcTemplate.execute("DROP SCHEMA " + newDb);
    } else {
        jdbcTemplate.execute("USE " + schema);
    }
}

The workaround could be in JDBC connection string add default database name.

@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Sep 19, 2014

Hi Wilkin,

Thanks for investigating this. You must have a connection with no schema selected and indeed be hitting this workaround.

I have now replaced the error with a warning.

As a workaround, you can also make sure your Jdbc url contains a database.

Cheers
Axel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.