zoukankan      html  css  js  c++  java
  • Spring Boot 整合 SardingSphere (单表访问以及分库分表)

    Tips:

    • 其他代码 链接:https://www.cnblogs.com/yi1036943655/p/15700170.html
    • 在实际的项目里,不可能项目只有分库分表的表,肯定是带有不分库分表的表,当我学习SardingSphere的时候,我就在想这东西怎么配置,查阅过各种文章。总结就是在添加个数据源,无需额外配置。把不分库不分表的表,都放到这个数据源里。
    • 写的不一定正确,大佬勿喷,如果有更高效的方法,请指教

    application.properties

    spring.shardingsphere.datasource.names=sharding,sharding0,sharding1
    
    # 第零个数据库
    spring.shardingsphere.datasource.sharding.type=com.zaxxer.hikari.HikariDataSource
    spring.shardingsphere.datasource.sharding.driver-class-name=com.mysql.cj.jdbc.Driver
    spring.shardingsphere.datasource.sharding.jdbc-url=jdbc:mysql://localhost:3306/sharding0?serverTimezone=GMT%2B8&useSSL=false
    spring.shardingsphere.datasource.sharding.username=root
    spring.shardingsphere.datasource.sharding.password=root
    
    # 第一个数据库
    spring.shardingsphere.datasource.sharding0.type=com.zaxxer.hikari.HikariDataSource
    spring.shardingsphere.datasource.sharding0.driver-class-name=com.mysql.cj.jdbc.Driver
    spring.shardingsphere.datasource.sharding0.jdbc-url=jdbc:mysql://localhost:3306/sharding0?serverTimezone=GMT%2B8&useSSL=false
    spring.shardingsphere.datasource.sharding0.username=root
    spring.shardingsphere.datasource.sharding0.password=root
    
    # 第二个数据库
    spring.shardingsphere.datasource.sharding1.type=com.zaxxer.hikari.HikariDataSource
    spring.shardingsphere.datasource.sharding1.driver-class-name=com.mysql.cj.jdbc.Driver
    spring.shardingsphere.datasource.sharding1.jdbc-url=jdbc:mysql://localhost:3306/sharding1?serverTimezone=GMT%2B8&useSSL=false
    spring.shardingsphere.datasource.sharding1.username=root
    spring.shardingsphere.datasource.sharding1.password=root
  • 相关阅读:
    tomcat启动与关闭脚本
    SqlAlchemy ORM
    python之socket
    python异常处理
    python常用模块
    PYTHON之文件操作
    Linux系统Load average负载详细解释
    tomcat报错:This is very likely to create a memory leak问题解决
    springcloud第一步:创建eureka注册服务
    SpringCloud微服务高级
  • 原文地址:https://www.cnblogs.com/yi1036943655/p/15734158.html
Copyright © 2011-2022 走看看