java代码使用jdbc去创建数据库时,非常慢

Viewed 54

版本2.1.3
使用hikariCP数据库连接池,创建数据库时,不管用CREATE DATABASE还是用CREATE DATABASE IF NOT EXISTS,都会有几分钟的延迟,查询数据和创建表都没有问题,只有创建数据库会卡死。使用navicat创建无问题

public DorisDataStorage(DorisProperties dorisProperties) {
        if (!dorisProperties.enabled()) {
            return;
        }
        ZoneId systemZoneId = ZoneId.systemDefault();
        String zoneIdString = systemZoneId.getId();
        this.hikariDataSource = new HikariDataSource();
        this.hikariDataSource.setJdbcUrl("jdbc:mysql://" + dorisProperties.host() + ":" + dorisProperties.jdbcPort()
                + "/mysql?useUnicode=true&characterEncoding=utf8&useTimezone=true&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone="+zoneIdString);
        this.hikariDataSource.setUsername(dorisProperties.username());
        this.hikariDataSource.setPassword(dorisProperties.password());
        this.hikariDataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        // minimum number of idle connection
        this.hikariDataSource.setMinimumIdle(10);
        // maximum number of connection in the pool
        this.hikariDataSource.setMaximumPoolSize(10);
        // maximum wait milliseconds for get connection from pool
        this.hikariDataSource.setConnectionTimeout(30000);
        createDatabase(dorisProperties.database());
        this.serverAvailable = true;
        if (hikariDataSource.isRunning()) {
            this.serverAvailable = true;
        }
    }

 private void createDatabase(String database) {
        try (Connection connection = hikariDataSource.getConnection()) {
            connection.createStatement().execute(String.format(CREATE_DATABASE_SQL, database));
        } catch (SQLException e) {
            log.error("[warehouse doris]--Error: {}", e.getMessage(), e);
        }
    }

image.png
image.png
image.png

1 Answers

可能是兼容性问题,换druid连接池效果如何。