Detailed explanation of MySQL-sub-database and sub-table (7)

♥️Author : Xiao Liu at Station C

♥️Personal homepage:  Xiao Liu's homepage 

♥️Efforts may not necessarily pay off, but there will be gains! Come on! Work hard together for a better life!

♥️ Learn the operation and maintenance experience summed up in two years, and a full set of network experiment tutorials for Cisco simulators. Column: Cloud Computing Technology

♥️Xiao Liu private message can ask casually, as long as you know it, you will not be stingy, thank you CSDN for letting you and me meet!

foreword

The last chapter talked about MySQL- Detailed Explanation of Sub-database and Sub-Table (6)

Table of contents

5.3.7 String hash parsing algorithm

1 Introduction

 2). Configuration

 3). Test

5.3.8 Sharding Algorithm by Day

1 Introduction

 2). Configuration

 3). Test

5.3.9 Natural month sharding

1 Introduction

​edit

 2). Configuration

 3). Test

6 MyCat management and monitoring

6.1 Principle of MyCat

6.2 MyCat Management

6.3 MyCat-eye

 6.3.1 Introduction

6.3.2 Installation

6.3.3 Access

 6.3.4 Configuration

 6.3.5 Testing

A. Performance monitoring

 B. Physical Node

 C. SQL Statistics

​edit

 D. SQL table analysis

 E. SQL monitoring

​edit

 F. High frequency SQL


5.3.7 String hash parsing algorithm

1). Introduction

Intercept the substring at the specified position in the string , perform the hash algorithm, and calculate the fragmentation.
 2). Configuration
Logic table configuration in schema.xml :
<!-- 字符串hash解析算法 -->
<table name="tb_strhash" dataNode="dn4,dn5" rule="sharding-by-stringhash" />
Data node configuration in schema.xml :
<dataNode name="dn4" dataHost="dhost1" database="itcast" />
<dataNode name="dn5" dataHost="dhost2" database="itcast" />
Fragmentation rule configuration in rule.xml :
<tableRule name="sharding-by-stringhash">
<rule>
<columns>name</columns>
<algorithm>sharding-by-stringhash</algorithm>
</rule>
</tableRule>
<function name="sharding-by-stringhash"
class="io.mycat.route.function.PartitionByString">
<property name="partitionLength">512</property> <!-- zero-based -->
<property name="partitionCount">2</property>
<property name="hashSlice">0:2</property>
</function>
Fragmentation rule attribute meaning:

 Example explanation:

 3). Test
After the configuration is complete, restart MyCat , and then in the command line of mycat , execute the following SQL to create a table, insert data, and check the data distribution.
 
create table tb_strhash(
name varchar(20) primary key,
content varchar(100)
)engine=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO tb_strhash (name,content) VALUES('T1001', UUID());
INSERT INTO tb_strhash (name,content) VALUES('ROSE', UUID());
INSERT INTO tb_strhash (name,content) VALUES('JERRY', UUID());
INSERT INTO tb_strhash (name,content) VALUES('CRISTINA', UUID());
INSERT INTO tb_strhash (name,content) VALUES('TOMCAT', UUID());

5.3.8 Sharding Algorithm by Day

1). Introduction
Shard according to date and corresponding time period.
 2). Configuration
Logic table configuration in schema.xml :
<!-- 按天分片 -->
<table name="tb_datepart" dataNode="dn4,dn5,dn6" rule="sharding-by-date" />
Data node configuration in schema.xml :
<dataNode name="dn4" dataHost="dhost1" database="itcast" />
<dataNode name="dn5" dataHost="dhost2" database="itcast" />
<dataNode name="dn6" dataHost="dhost3" database="itcast" />
Fragmentation rule configuration in rule.xml :
<tableRule name="sharding-by-date">
<rule>
<columns>create_time</columns>
<algorithm>sharding-by-date</algorithm>
</rule>
</tableRule>
<function name="sharding-by-date"
class="io.mycat.route.function.PartitionByDate">
<property name="dateFormat">yyyy-MM-dd</property>
<property name="sBeginDate">2022-01-01</property>
<property name="sEndDate">2022-01-30</property>
<property name="sPartionDay">10</property>
</function>
<!--
从开始时间开始,每10天为一个分片,到达结束时间之后,会重复开始分片插入
配置表的 dataNode 的分片,必须和分片规则数量一致,例如 2022-01-01 到 2022-12-31 ,每
10天一个分片,一共需要37个分片。
-->
Fragmentation rule attribute meaning:
 3). Test
After the configuration is complete, restart MyCat , and then in the command line of mycat , execute the following SQL to create a table, insert data, and check the data distribution.
create table tb_datepart(
id bigint not null comment 'ID' primary key,
name varchar(100) null comment '姓名',
create_time date null
);
insert into tb_datepart(id,name ,create_time) values(1,'Tom','2022-01-01');
insert into tb_datepart(id,name ,create_time) values(2,'Cat','2022-01-10');
insert into tb_datepart(id,name ,create_time) values(3,'Rose','2022-01-11');
insert into tb_datepart(id,name ,create_time) values(4,'Coco','2022-01-20');
insert into tb_datepart(id,name ,create_time) values(5,'Rose2','2022-01-21');
insert into tb_datepart(id,name ,create_time) values(6,'Coco2','2022-01-30');
insert into tb_datepart(id,name ,create_time) values(7,'Coco3','2022-01-31');

5.3.9 Natural month sharding

1). Introduction
The usage scenario is to shard by month , and each natural month is a shard.
 2). Configuration
Logic table configuration in schema.xml :
<!-- 按自然月分片 -->
<table name="tb_monthpart" dataNode="dn4,dn5,dn6" rule="sharding-by-month" /> 
Data node configuration in schema.xml :
<dataNode name="dn4" dataHost="dhost1" database="itcast" />
<dataNode name="dn5" dataHost="dhost2" database="itcast" />
<dataNode name="dn6" dataHost="dhost3" database="itcast" />
Fragmentation rule configuration in rule.xml:   
<tableRule name="sharding-by-month">
<rule>
<columns>create_time</columns>
<algorithm>partbymonth</algorithm>
</rule>
</tableRule>
<function name="partbymonth" class="io.mycat.route.function.PartitionByMonth">
<property name="dateFormat">yyyy-MM-dd</property>
<property name="sBeginDate">2022-01-01</property>
<property name="sEndDate">2022-03-31</property>
</function>
<!--
从开始时间开始,一个月为一个分片,到达结束时间之后,会重复开始分片插入
配置表的 dataNode 的分片,必须和分片规则数量一致,例如 2022-01-01 到 2022-12-31 ,一
共需要12个分片。
-->
     
Fragmentation rule attribute meaning:
 3). Test
After the configuration is complete, restart MyCat , and then in the command line of mycat , execute the following SQL to create a table, insert data, and check the data distribution.
create table tb_monthpart(
id bigint not null comment 'ID' primary key,
name varchar(100) null comment '姓名',
create_time date null
);
insert into tb_monthpart(id,name ,create_time) values(1,'Tom','2022-01-01');
insert into tb_monthpart(id,name ,create_time) values(2,'Cat','2022-01-10');
insert into tb_monthpart(id,name ,create_time) values(3,'Rose','2022-01-31');
insert into tb_monthpart(id,name ,create_time) values(4,'Coco','2022-02-20');
insert into tb_monthpart(id,name ,create_time) values(5,'Rose2','2022-02-25');
insert into tb_monthpart(id,name ,create_time) values(6,'Coco2','2022-03-10');
insert into tb_monthpart(id,name ,create_time) values(7,'Coco3','2022-03-31');
insert into tb_monthpart(id,name ,create_time) values(8,'Coco4','2022-04-10');
insert into tb_monthpart(id,name ,create_time) values(9,'Coco5','2022-04-30');

6 MyCat management and monitoring

6.1 Principle of MyCat

 In MyCat , when executing a SQL statement, MyCat needs to perform operations such as SQL parsing, fragmentation analysis, routing analysis, read-write separation analysis, etc., and finally decides to route the current SQL statement to which ( or which one ) node database, after the database executes the data, if there is a returned result, it will return the result to MyCat , and finally need to perform results merging, aggregation processing, sorting processing, paging processing and other operations in MyCat , and finally Return the result to the client.

During the use of MyCat , MyCat officially also provides a management and monitoring platform MyCat-Web ( MyCat-eye ). Mycat-web is the management and monitoring platform for Mycat's visual operation and maintenance, which makes up for the gap in Mycat 's monitoring. Help Mycat share statistical tasks and configuration management tasks. Mycat-web introduces ZooKeeper as a configuration center, which can manage multiple nodes. Mycat-web mainly manages and monitors Mycat 's traffic, connections, active threads, and memory. It has modules such as IP whitelist and email alarm. It can also count SQL and analyze slow SQL and high-frequency SQL . Provide a basis for optimizing SQL .

6.2 MyCat Management

Mycat opens 2 ports by default, which can be modified in server.xml .
8066 data access port, that is, for DML and DDL operations.
9066 database management port, which is the mycat service management control function, used to manage the entire cluster status of mycat
To connect to MyCat 's management console:

mysql -h 192.168.200.210 -p 9066 -uroot -p123456

6.3 MyCat-eye

 6.3.1 Introduction

Mycat-web (Mycat-eye) is a monitoring service for mycat-server , and its function is not limited to the use of mycat-server
use. He monitors Mycat and Mysql through JDBC connection , and monitors the cpu and internal
storage, network, disk.

Mycat-eye needs to rely on zookeeper during operation , so zookeeper needs to be installed first .

6.3.2 Installation

1). zookeeper installation
2). Mycat-web installation

6.3.3 Access

http://192.168.200.210:8082/mycat

 6.3.4 Configuration

1). Turn on the real-time statistics function of MyCat (server.xml)

<property name="useSqlStat">1</property> <!-- 1为开启实时统计、0为关闭 -->
2). Configure the service address on the Mycat monitoring interface

 6.3.5 Testing

After the configuration is complete, we can perform a series of tests of adding, deleting, modifying and checking through MyCat , and then after a period of time, open
The management interface of mycat-eye , view the data information monitored by mycat-eye .

A. Performance monitoring

 B. Physical Node

 C. SQL Statistics

 D. SQL table analysis

 E. SQL monitoring

 F. High frequency SQL

 

♥️Following is the driving force for my creation

♥️Like, is the greatest recognition for me

♥️This is Xiaoliu, I am inspiring to do every article well, thank you everyone

Guess you like

Origin blog.csdn.net/lzl10211345/article/details/131743399