sharding-jdbc 数据库连接池配置(有点小坑),读写分离,分表策略,主键自增
2021/4/20 19:25:17
本文主要是介绍sharding-jdbc 数据库连接池配置(有点小坑),读写分离,分表策略,主键自增,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
- 常规spring boot druid 数据库连接配置
spring: datasource: name: druidDataSource type: com.alibaba.druid.pool.DruidDataSource druid: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/springboot?useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=utf-8 username: root password: 123456 filters: stat,wall,log4j,config max-active: 100 initial-size: 1 max-wait: 60000 min-idle: 1 time-between-eviction-runs-millis: 60000 min-evictable-idle-time-millis: 300000 validation-query: select 'x' test-while-idle: true test-on-borrow: false test-on-return: false pool-prepared-statements: true max-open-prepared-statements: 50 max-pool-prepared-statement-per-connection-size: 20
- sharding-jdbc 数据库连接池 ,直接配置,不需增加父节点druid
spring: #shardingsphere shardingsphere: datasource: #主库 m0: driver-class-name: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource url: jdbc:mysql://192.168.88.22:3306/test?characterEncoding=utf8&serverTimezone=Asia/Shanghai&connectTimeout=15000&socketTimeout=8000&autoReconnect=true&useSSL=false&failOverReadOnly=false username: root password: root maximum-pool-size: 50 pool-name: m0-pool # 从库 s0: driver-class-name: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource url: jdbc:mysql://192.168.88.22:3306/test?characterEncoding=utf8&serverTimezone=Asia/Shanghai&autoReconnect=true&useSSL=false username: root password: root initial-size: 20 max-active: 200 max-wait: 25000 min-evictable-idle-time-millis: 1814400 min-idle: 20 test-on-borrow: true test-on-return: true test-while-idle: true validation-query: SELECT 1 validation-query-timeout: 2000 time-between-eviction-runs-millis: 1814400 time-between-connect-error-millis: 60000 pool-prepared-statements: true max-pool-prepared-statement-per-connection-size: 20 names: m0,s0 props: sql: #打印sql show: true max: connections: size: per: # 开启内存模式 query: 50 sharding: master-slave-rules: # 读写分离 ds0: master-data-source-name: m0 slave-data-source-names[0]: s0 # 从库 # 分表策略 tables: test_account_log: table-strategy: standard: precise-algorithm-class-name: com.test.algorithem.DatePreciseShardingAlgorithm range-algorithm-class-name: com.test.algorithem.DateRangeShardingAlgorithm shardingColumn: create_time # 分表键 actual-data-nodes: ds0.test_account_log_$->{2020..2021}_$->{01..12} #主键策略 key-generator: column: id props: worker: id: 1 type: SNOWFLAKE
这篇关于sharding-jdbc 数据库连接池配置(有点小坑),读写分离,分表策略,主键自增的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-19EntBot.ai: AI Website Chatbot for Product Guides and Development Doc
- 2024-06-17zero-shot-learning-definition-examples-comparison
- 2024-06-06Package Easy(基于 NSIS 的打包exe安装包工具)使用方法-icode9专业技术文章分享
- 2024-06-06基于 casdoor 的 ELK 开源登录认证解决方案: elk-auth-casdoor-icode9专业技术文章分享
- 2024-05-29Elasticsearch慢查询日志配置
- 2024-05-29揭秘华为如此多成功项目的产品关键——Charter模板
- 2024-05-29海外IDC业务拓展的7大挑战
- 2024-05-29InLine Chat功能优化对标Github Copilot,CodeGeeX带来更高效、更直观的编程体验!
- 2024-05-29CodeGeeX 智能编程助手 6 项功能升级,在Visual Studio插件市场霸榜2周!
- 2024-05-29AutoMQ 生态集成 Apache Doris