MySQL database division of the points table (MyCAT achieve)

Sub-library sub-table presentation

With the rise of the micro-architecture of this service, we have a complete application from the application of large, cut into many small applications can provide services independently. Each application has its own database.

Cut into two data points:

Vertical segmentation: be segmented according to the service module, different modules of the cutting table into different databases.

 

 

 Level segmentation: The large table in accordance with a certain degree of segmentation rules, in accordance with the line cut into different tables or different libraries.

 

 MyCAT Introduction

Official Website: http://www.mycat.org.cn/

What is MyCAT?

Simply put, MyCAT is:

  • A completely open source, enterprise-oriented application development "big database cluster."
  • Supports transactions, ACID, can replace the enhanced version of Mysql database
  • Enterprise-class database can be viewed as a "Mysql" Clusters, Oracle Clusterware used to replace expensive
  • A memory cache fusion technology, Nosql technology, HDFS large new SQL Server data
  • The new combination of traditional database and distributed data warehouse generation of enterprise-class database product
  • A new database middleware products

MyCAT objectives are: low cost would smooth migration of existing stand-alone databases and applications to the "cloud" side, resolve data bottlenecks in the rapidly growing data storage and scale of business situations.

Key Features of MyCAT

  1. Supports SQL 92 standard
  2. Mysql support clusters, can be used as a Proxy
  3. JDBC connection support ORACLE, DB2, SQL Server, MySQL Server will use it to simulate
  4. Support galera for mysql cluster, percona-cluster or mariadb cluster, high availability cluster data pieces
  5. Automatic failover, high availability
  6. Support separate read and write support Mysql from multiple double main, and a mode from a plurality of master
  7. Support global table, the data to be fragmented plurality of nodes for efficient table associated with the query
  8. Support partitioning strategy based on the unique relationship of ER, enables efficient table associated with the query
  9. Multi-platform support, simple deployment and implementation

MyCAT architecture

 

 

MyCAT core concepts

  1. Schema: specifies the logical database
  2. Table: logic table
  3. DataNode: real storage node
  4. DataHost:真正的数据库主机

Mycat存在的问题

跨库join问题

  • 通过业务分析,将不同库的join查询拆分成多个select
  • 建立全局表(每个库都有一个相同的表)
  • 冗余字段(不符合数据库三范式)
  • E-R分片(将有关系的记录都存储到一个库中)
  • 最多支持跨两张表跨库的join

分布式事务(弱事务)

  • 强一致性事务(同步)
  • 最终一致性事务(异步思想)

分布式主键

  • redis incr命令
  • 数据库(生成主键)
  • UUID
  • snowflake算法

1.1      分片策略

MyCAT支持水平分片与垂直分片:

  • 水平分片:一个表格的数据分割到多个节点上,按照行分隔。
  • 垂直分片:一个数据库中多个表格A,B,C,A存储到节点1上,B存储到节点2上,C存储到节点3上。

 

MyCAT通过定义表的分片规则来实现分片,每个表格可以捆绑一个分片规则,每个分片规则指定一个分片字段并绑定一个函数,来实现动态分片算法。

  1. Schema:逻辑库,与MySQL中的Database(数据库)对应,一个逻辑库中定义了所包括的Table。
  2. Table:表,即物理数据库中存储的某一张表,与传统数据库不同,这里的表格需要声明其所存储的逻辑数据节点DataNode。在此可以指定表的分片规则。
  3. DataNode:MyCAT的逻辑数据节点,是存放table的具体物理节点,也称之为分片节点,通过DataSource来关联到后端某个具体数据库上
  4. DataSource:定义某个物理库的访问地址,用于捆绑到Datanode上

Mycat读写分离

MyCat的读写分离是建立在MySQL主从复制基础之上实现的。

数据库读写分离对于大型系统或者访问量很高的互联网应用来说,是必不可少的一个重要功能。对于MySQL来说,标准的读写分离是主从模式,一个写节点Master后面跟着多个读节点,读节点的数量取决于系统的压力,通常是1-3个读节点的配置

 

 

Mycat读写分离和自动切换机制,需要mysql的主从复制机制配合。

Guess you like

Origin www.cnblogs.com/dzlj/p/12163448.html