- 前言
系统采用mysql数据库,技术框架采用基于springboot的springcloud,持久层采用jpa,数据库连接池阿里druid
随着最近系统用户量增加到500万,等各系统用户过来后会超过2000万,这个时候随着用户表数据量的增加,
用户表查询效率 低下。这个时候未雨绸缪,开始准备分库分表的准备,采用分布式数据库中间件,选择了sharding spshare,
这篇文章主要是用到了sharding-jdbc进行分库分表,我们用户人数预计最高2000万,我们采用的是分库单表方案,即6个库,一个单表
- 分库分表
1我选用的是基于springboot的配置规则,本文省略druid的配置
首先需要引入依赖
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<sharding-sphere.version>4.0.0-RC1</sharding-sphere.version>
</properties>
<dependencies>
<!-- sharding-jdbc 基于springboot配置规则-->
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
<version>${sharding-sphere.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-namespace</artifactId>
<version>${sharding-sphere.version}</version>
</dependency>
<!-- sharding-jdbc 基于springboot配置规则-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- mysql驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<!-- alibaba druid-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.16</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.