Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure Sharding JDBC subtable

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to configure Sharding JDBC subtables". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Sub-table configuration

Since the single database is divided into tables, only one data source can be configured.

# configure data source spring.shardingsphere.datasource.names=test0#test0spring.shardingsphere.datasource.test0.type=com.zaxxer.hikari.HikariDataSourcespring.shardingsphere.datasource.test0.driver-class-name=com.mysql.cj.jdbc.Driverspring.shardingsphere.datasource.test0.jdbcUrl=jdbc:mysql://127.0.0.1:3306/test0spring.shardingsphere.datasource.test0.username=devadminspring.shardingsphere.datasource.test0.password=

Set binding table

# setting binding table spring.shardingsphere.sharding.binding-tables [0] = health_record,health_task

Set the policy of sub-table

Here the table is divided according to the parity of record_id. Divided into health_record0,health_record1 and health_task0,health_task1

# health_recordspring.shardingsphere.sharding.tables.health_record.actual-data-nodes=test0.health_record$- > {0.. 1} spring.shardingsphere.sharding.tables.health_record.table-strategy.inline.algorithm-expression=health_record$- > {record_id% 2} spring.shardingsphere.sharding.tables.health_record.table-strategy.inline.sharding-column=record_idspring.shardingsphere.sharding.tables.health_record.key-generator.column=record_idspring.shardingsphere.sharding.tables.health_record.key-generator. Type=SNOWFLAKE# health_taskspring.shardingsphere.sharding.tables.health_task.actual-data-nodes=test0.health_task$- > {0.. 1} spring.shardingsphere.sharding.tables.health_task.table-strategy.inline.algorithm-expression=health_task$- > {record_id 2} spring.shardingsphere.sharding.tables.health_task.table-strategy.inline.sharding-column=record_idspring.shardingsphere.sharding.tables.health_task.key-generator.column=task_idspring.shardingsphere.sharding.tables.health_task.key-generator.type=SNOWFLAKE

Complete configuration

Server.port=8080# print sqlspring.shardingsphere.props.sql.show=true# configuration data source spring.shardingsphere.datasource.names=test0#test0spring.shardingsphere.datasource.test0.type=com.zaxxer.hikari.HikariDataSourcespring.shardingsphere.datasource.test0.driver-class-name=com.mysql.cj.jdbc.Driverspring.shardingsphere.datasource.test0.jdbcUrl=jdbc:mysql://127.0.0.1:3306/test0spring.shardingsphere.datasource.test0.username=devadminspring.shardingsphere.datasource.test0.password=# settings binding table spring.shardingsphere.sharding.binding-tables [0] = health_record Health_task# health_recordspring.shardingsphere.sharding.tables.health_record.actual-data-nodes=test0.health_record$- > {0.. 1} spring.shardingsphere.sharding.tables.health_record.table-strategy.inline.algorithm-expression=health_record$- > {record_id 2} spring.shardingsphere.sharding.tables.health_record.table-strategy.inline.sharding-column=record_idspring.shardingsphere.sharding.tables.health_record.key-generator.column=record_idspring.shardingsphere.sharding.tables.health_record.key -generator.type=SNOWFLAKE# health_taskspring.shardingsphere.sharding.tables.health_task.actual-data-nodes=test0.health_task$- > {0.. 1} spring.shardingsphere.sharding.tables.health_task.table-strategy.inline.algorithm-expression=health_task$- > {record_id% 2} spring.shardingsphere.sharding.tables.health_task.table-strategy.inline.sharding-column=record_idspring.shardingsphere.sharding.tables.health_task.key-generator.column=task_idspring.shardingsphere.sharding.tables.health_task.key-generator.type=SNOWFLAKE database is as follows

The health_level data are as follows

The user data are as follows

Health_record0,health_record1

In health_record0, record_id is even and health_record1 is odd.

Health_task0,health_task1

In health_task0, record_id is even and health_task1 is odd.

This is the end of the content of "how to configure the Sharding JDBC subtable". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report