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

readwrite-splitting-problem #32804

Closed
janlee151 opened this issue Sep 7, 2024 · 4 comments
Closed

readwrite-splitting-problem #32804

janlee151 opened this issue Sep 7, 2024 · 4 comments

Comments

@janlee151
Copy link

janlee151 commented Sep 7, 2024

@terrymanu

springboot project

pom shardingsphere dependency: shardingsphere-jdbc-core-spring-boot-starter version5.2.0
my application.yaml config file as follows:

spring:
  shardingsphere:
    datasource: #配置数据源
      names: master,slave1,slave2
      master:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/master?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
        username: root
        password: ******
        initial-size: 1
        max-active: 20
        max-open-prepared-statements: 20
        max-pool-prepared-statement-per-connection-size: 50
        max-wait: 60000
        min-evictable-idle-time-millis: 300000
        min-idle: 1
        pool-prepared-statements: true
        test-on-borrow: false
        test-on-return: false
        test-while-idle: true
        time-between-eviction-runs-millis: 60000
        validation-query: slect 1 from dual
        keep-alive: true
      slave1:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/slave1?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
        username: root
        password: ******
        initial-size: 1
        max-active: 20
        max-open-prepared-statements: 20
        max-pool-prepared-statement-per-connection-size: 50
        max-wait: 60000
        min-evictable-idle-time-millis: 300000
        min-idle: 1
        pool-prepared-statements: true
        test-on-borrow: false
        test-on-return: false
        test-while-idle: true
        time-between-eviction-runs-millis: 60000
        validation-query: slect 1 from dual
        keep-alive: true
      slave2:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/slave2?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
        username: root
        password: ******
        initial-size: 1
        max-active: 20
        max-open-prepared-statements: 20
        max-pool-prepared-statement-per-connection-size: 50
        max-wait: 60000
        min-evictable-idle-time-millis: 300000
        min-idle: 1
        pool-prepared-statements: true
        test-on-borrow: false
        test-on-return: false
        test-while-idle: true
        time-between-eviction-runs-millis: 60000
        validation-query: slect 1 from dual
        keep-alive: true
    mode:
      type: Standalone
    database:
      name: readwrite_ds
    rules:
      readwrite-splitting:
        data-sources:
          readwrite_ds:
            load-balancer-name: round_robin
            static-strategy:
              read-data-source-names: slave1,slave2
              write-data-source-name: master
        load-balancers:
          round_robin:
            type: ROUND_ROBIN
    props:
      sql-show: true

here is my test case:

//**mybatis-plus**

 @Test
    public void readWriteSplitting() {
         TUser user = new TUser();
         user.setUserName("tom");
         user.setAge(20);
         userService.save(user);
   }

master database table t_user has data:

image
but slave1 and slave2 has no data:
image
master and slave has not sync data,i don't know where is wrong?

@terrymanu
Copy link
Member

The markdown format in your issue is incorrect. To facilitate reading, could you please revise it?

@janlee151
Copy link
Author

@terrymanu hello,help me solve this problem,thank you

@lazyboyl
Copy link

Master-slave data synchronization is achieved through MySQL's master-slave mechanism, and you need to configure the master-slave settings for MySQL yourself.

Copy link

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.

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

No branches or pull requests

3 participants