Skip to content

[Bug] mysql-connector-j驱动新版不兼容 #60634

Closed

Description

@wtjperi2003

Search before asking

  • I had searched in the issues and found no similar issues.

Version

doris version doris-4.0.2-rc02-30d2df0459

What's Wrong?

经过测试,发现mysql-connector-j从9.5.0版本包括9.5.0开始,查询会返回空数据,实际表里是有数据的。低于9.5.0是正常的

What You Expected?

正常返回数据

How to Reproduce?

java项目里,引用:

<dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <version>9.5.0</version>
            <scope>runtime</scope>
        </dependency>

Anything Else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. Ruffianjiang commented on Feb 26, 2026

    @Ruffianjiang

    是不是jdbc的参数useServerPrepStmts=true的问题,设置成false能正常查询到
    3.1.4也是这个问题

  2. morningman commented on Mar 3, 2026

    @morningman
    Contributor

    Thank you for reporting this issue. Special thanks to @Ruffianjiang for the valuable clue regarding useServerPrepStmts=true.

    It appears there is a compatibility issue between Doris and newer versions of mysql-connector-j (9.5.0+) when server-side prepared statements are enabled.

    To help us diagnose the root cause more efficiently, could you please provide complete reproduction steps?

    The dependency information you provided is helpful, but a minimal, reproducible Java code snippet would be highly appreciated. Please include:

    1. The complete JDBC connection URL (including any parameters).
    2. The table creation statement.
    3. The Java code used to insert test data and execute the query that returns empty results.
  3. Ruffianjiang commented on Mar 3, 2026

    @Ruffianjiang

    以下是复现的主要代码 @morningman

    1. mybatis-plus 3.5.9
    2. spring-boot 3.5.11
    3. mysql-connector-j 9.6.0
    4. doris doris-3.1.4-rc02-7f5ba43de6

    表现结果:

    1. 第一、二个url查询正常,第三个查不到数据
    2. Group Commit的性能是一二三,越来越强
    3. 第一个是mysql的默认参数,第三个是doris的默认参数useServerPrepStmts=true,第二个把doris默认参数改为useServerPrepStmts=false&cacheResultSetMetadata=true

    建表

    CREATE TABLE IF NOT EXISTS `t_user` (
        `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
        `username` VARCHAR(64) NOT NULL COMMENT '用户名',
        `password` VARCHAR(128) NOT NULL COMMENT '密码',
        `email` VARCHAR(128) COMMENT '邮箱',
        `phone` VARCHAR(20) COMMENT '手机号',
        `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
        `update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
    ) ENGINE=OLAP
    UNIQUE KEY(`id`)
    DISTRIBUTED BY HASH(`id`) BUCKETS 3
    PROPERTIES (
        "replication_num" = "3"
    );

    初始化sql

    INSERT INTO `t_user` (`username`, `password`, `email`, `phone`, `create_time`, `update_time`) VALUES
    ('zhangsan', 'e10adc3949ba59abbe56e057f20f883e', 'zhangsan@example.com', '13800138001', '2026-03-03 10:00:00', '2026-03-03 10:00:00'),
    ('lisi', 'e10adc3949ba59abbe56e057f20f883e', 'lisi@example.com', '13800138002', '2026-03-03 10:00:00', '2026-03-03 10:00:00'),
    ('wangwu', 'e10adc3949ba59abbe56e057f20f883e', 'wangwu@example.com', '13800138003', '2026-03-03 10:00:00', '2026-03-03 10:00:00'),
    ('zhaoliu', 'e10adc3949ba59abbe56e057f20f883e', 'zhaoliu@example.com', '13800138004', '2026-03-03 10:00:00', '2026-03-03 10:00:00'),
    ('sunqi', 'e10adc3949ba59abbe56e057f20f883e', 'sunqi@example.com', '13800138005', '2026-03-03 10:00:00', '2026-03-03 10:00:00'),
    ('zhouba', 'e10adc3949ba59abbe56e057f20f883e', 'zhouba@example.com', '13800138006', '2026-03-03 10:00:00', '2026-03-03 10:00:00'),
    ('wujiu', 'e10adc3949ba59abbe56e057f20f883e', 'wujiu@example.com', '13800138007', '2026-03-03 10:00:00', '2026-03-03 10:00:00'),
    ('zhengshi', 'e10adc3949ba59abbe56e057f20f883e', 'zhengshi@example.com', '13800138008', '2026-03-03 10:00:00', '2026-03-03 10:00:00'),
    ('admin', 'e10adc3949ba59abbe56e057f20f883e', 'admin@example.com', '13800138009', '2026-03-03 10:00:00', '2026-03-03 10:00:00'),
    ('test', 'e10adc3949ba59abbe56e057f20f883e', 'test@example.com', '13800138010', '2026-03-03 10:00:00', '2026-03-03 10:00:00');

    pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>3.5.11</version>
            <relativePath/>
        </parent>
    
        <groupId>com.xxx</groupId>
        <artifactId>doris-jdbc</artifactId>
        <version>1.0.0</version>
        <name>doris-jdbc</name>
        <description>doris-jdbc</description>
    
        <properties>
            <java.version>21</java.version>
            <mybatis-plus.version>3.5.9</mybatis-plus.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jdbc</artifactId>
            </dependency>
    
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-spring-boot3-starter</artifactId>
                <version>${mybatis-plus.version}</version>
            </dependency>
    
            <dependency>
                <groupId>com.mysql</groupId>
                <artifactId>mysql-connector-j</artifactId>
                <scope>runtime</scope>
            </dependency>
    
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <optional>true</optional>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <excludes>
                            <exclude>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok</artifactId>
                            </exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    </project>

    application.yml

    spring:
      application:
        name: doris-jdbc
      datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
    #    url: jdbc:mysql://xxx:9030/demo?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true&sessionVariables=group_commit=async_mode
    #    url: jdbc:mysql://xxx:9030/demo?useServerPrepStmts=false&cacheResultSetMetadata=true&useLocalSessionState=true&rewriteBatchedStatements=true&cachePrepStmts=true&prepStmtCacheSqlLimit=99999&prepStmtCacheSize=50&sessionVariables=group_commit=async_mode
        url: jdbc:mysql://xxx:9030/demo?useServerPrepStmts=true&useLocalSessionState=true&rewriteBatchedStatements=true&cachePrepStmts=true&prepStmtCacheSqlLimit=99999&prepStmtCacheSize=50&sessionVariables=group_commit=async_mode
        username: root
        password: xxx
    
    server:
      port: 8080
    
    mybatis-plus:
      configuration:
        map-underscore-to-camel-case: true
        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
      global-config:
        db-config:
          id-type: auto
          logic-delete-field: deleted
          logic-delete-value: 1
          logic-not-delete-value: 0
      mapper-locations: classpath:mapper/*.xml

    User

    @Data
    @TableName("t_user")
    public class User {
    
        /**
         * 主键ID
         */
        @TableId(type = IdType.AUTO)
        private Long id;
    
        /**
         * 用户名
         */
        private String username;
    
        /**
         * 密码
         */
        private String password;
    
        /**
         * 邮箱
         */
        private String email;
    
        /**
         * 手机号
         */
        private String phone;
    
        /**
         * 创建时间
         */
        private LocalDateTime createTime;
    
        /**
         * 更新时间
         */
        private LocalDateTime updateTime;
    }

    UserMapper

    @Mapper
    public interface UserMapper extends BaseMapper<User> {}

    UserService

    public interface UserService extends IService<User> {}

    UserServiceImpl

    @Service
    public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {}

    UseServiceQueryTest

    @SpringBootTest
    @Slf4j
    class UseServiceQueryTest {
    
        @Autowired
        private UserService userService;
    
        @Test
        @DisplayName("测试查询用户")
        void testGetUserById() {
            User foundUser = userService.getById(1L);
            assertNotNull(foundUser, "查询到的用户不应该为空");
            log.info("foundUser username: {}", foundUser.getUsername());
            List<User> users = userService.list(new Page<>(1, 10));
            log.info("users size: {}", users.size());
        }
    }
    Image Image
  4. morningman commented on Mar 4, 2026

    @morningman
    Contributor

    Thank you for providing the detailed reproduction steps.

    We have successfully reproduced this issue on our end. We are currently working on a fix and will update this thread once it is resolved.

  5. added a commit that references this issue on Mar 5, 2026
    4d6c2d2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions