public static void dropUnusedTestDatabases() {
        final ConnectionConfig connectionConfig = createConnectionConfig(new CommonDbConfig());
        final ConnectionConfig rootConnectionConfig = createRootConnectionConfig(connectionConfig);

        // Create new db.
        final Properties connectionProps = new Properties();
        connectionProps.put("user", rootConnectionConfig.getUser());
        connectionProps.put("password", rootConnectionConfig.getPassword());

        // Only match dbs with this gradle worker in the name
        final Pattern dbNamePatternThisWorker = Pattern.compile(
                "^test_" + Pattern.quote(getGradleWorker()) + "_.*$");
        LOGGER.info("Dropping databases matching pattern '{}'", dbNamePatternThisWorker);

        final Predicate<String> dbNameMatchPredicate = dbNamePatternThisWorker.asMatchPredicate();

        try (final Connection connection = DriverManager.getConnection(rootConnectionConfig.getUrl(),
                connectionProps)) {
            try (final Statement statement = connection.createStatement()) {
                final ResultSet resultSet = statement.executeQuery("SHOW DATABASES;");
                final List<String> dbNames = new ArrayList<>();
                while (resultSet.next()) {
                    final String dbName = resultSet.getString(1);
                    if (dbNameMatchPredicate.test(dbName)) {
                        dbNames.add(dbName);
                    }
                }

                for (String dbName : dbNames) {
                    LOGGER.info("Dropping test database {}", dbName);
                    statement.executeUpdate("DROP DATABASE " + dbName + ";");
                }
            }
        } catch (final SQLException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
Verify there is a connection to the database on the root account.
stroom-test-common/src/main/java/stroom/test/common/util/db/DbTestUtil.java