The good habit is to “like” first, then “watch”

  • Based on Java environment development
  • Main configuration files schema.xml(logical database), rule-xml (sharding rules), server.xml(some systems and users)

Mycat, as a logical database, is dependent on the following real database

Master-slave configuration

  • Potholes and Suggestions: Mysql5.7 is not the same as the previous version, you can create my.ini by yourself on Windows. Here is my reprint

  • Operation Assume that mysql has been installed on the two databases. The configuration is as follows

The server IP account password
The main A AUSER APWD
from B BUSER BPWD

To enter my.ini, you only need to update the following information:

Master library configuration and steps

[mysqld]
#binlog format: statement level,rowlevel,mixed
# three patterns, we can see the difference of https://juejin.cn/post/6844904019815596046
binlog_format=mixed
# identify the server, master and slave must not be the same
server-id   = 1
The interval between clearing binary logs
expire_logs_days = 10
# is the database to be synchronized
binlog-do-db
No need to synchronize the database
binlog-ignore-db = mysql                
binlog-ignore-db = test  

Set the gTID synchronization mode
gtid_executed_compression_period = 1000 # 1000 the default
gtid_mode = on # the default off
enforce_gtid_consistency = on # the default off
Copy the code

1. Connect to the primary database and enter mysql

>mysql -u database user name -p database passwordCopy the code

2. Create an authorized user slave for the slave database. The password is slave and the IP address is B

grant replication slave on *.* to 'slave'@'B' identified by 'slave' ;
Copy the code

3. Refresh the permission information

flush privileges;
Copy the code

4, create database and data table and insert corresponding data, mysql default InnoDB, master library can not change the engine

Slave library configuration and steps

My. Ini file

[mysqld]
#binlog format: statement level,rowlevel,mixed
# The differences between the three modes can be seen:
binlog_format=mixed
# identify the server, master and slave must not be the same
server-id   = 13
The interval between clearing binary logs
expire_logs_days = 10
# is the database to be synchronized
binlog-do-db
Set the gTID synchronization mode
gtid_executed_compression_period = 1000 # 1000 the default
gtid_mode = on # the default off
enforce_gtid_consistency = on # the default off
Copy the code

1, connect to the slave library and enter mysql

>mysql -u database user name -p database passwordCopy the code

2. Copy a database from the master database to the slave database and grant permissions to the slave database

grant all privileges on *.* to 'slave'@The '%' identified by 'slave' with grant option;
Copy the code

3. Refresh the permissions or exit the mysql command line to restart the mysql service

4. Master establishes data synchronization

change master to master_host='A',master_user='slave',master_password='slave',master_auto_position=1;
Copy the code

Important Note: The master_log_file & master_log_pos parameters are used in part of the tutorial. However, once the slave fails, it cannot confirm the broken node, and the data is likely to be inconsistent. Global Transaction ID (GTID) is the global transaction ID (GTID).

Mysql > query secondary database status

mysql>show slave status \G;
Copy the code

Slave_IO_Running: Yes Slave_SQL_Running: Yes

6. Verify the influence of master database update data on slave database

Mycat

Mycat architecture diagram

Introduction of MyCat

Introduce a wool thread, [MyCat official website](http://mycat.io/) so detailed introduction do not look, must listen to me in this excerpt?Copy the code

Environmental installation

Since Mycat is based on Java development, so the JDK environment is installed first, and then to install Mycat, install a lot of tutorials, I will not repeat

The implementation process

1, see the configuration information for clear and simple, not to affect the outcome of comments will be deleted, and the record is only for a main library and one from the library, depots table you just need to add the corresponding configuration, corresponding detailed instructions are included in the configuration file 2 can enter the mysql from the library of the engine to MyISAM, if don’t want to be written from a library function, You can also make mysql a read-only database

Schema. XML configuration information (complete configuration information and explanation are provided at the end of this article): It is used to configure read and write database information and corresponding table information

<? xml version="1.0"? > <! DOCTYPE mycat:schema SYSTEM"schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/"> <! -- Each schema represents a logical database. In this case, name is the database name used by the application side. The corresponding database account password is in server.xml --> <schema name="MycatDemo" checkSQLschema="true" sqlMaxLimit="100"> <! -- Auto sharding by id (long) -- Auto sharding by id (long) The following RDB indicates the real database. Name: indicates the table name in the corresponding RDB. PrimaryKey: indicates the primaryKey of the table in the RDB"article" primaryKey="article_id" autoIncrement="true" dataNode="dn1"
			   rule="mod-long"/> </schema> <! If there are multiple data nodes and multiple hosts, copy a copy of dataNode and dataHost data synchronously, and write the corresponding configuration information name: Name of the node dataHost: host address of the node DATABASE :RDB Database name --> <dataNode name="dn1" dataHost="localhost1" database="demo" />
	
	<dataHost name="localhost1" maxCon="1000" minCon="10" balance="1"
			  writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100"> <! Select user()</heartbeat> <! -- can have multi write hosts --> <writeHost host="hostM1" url="11.11.11.11:3306" user="root"
				   password="root"> <! -- can have multiread hosts -->
			<readHost host="hostS2" url="22.22.22.22:3306" user="root" password="root"/> </writeHost> <! -- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
	</dataHost>
	
</mycat:schema>

Copy the code

Rule-xml configuration information (complete configuration information and explanation at the end of this article): mainly defines some sharding rules and generation rules and so on

In particular, there is a function called mod-long that is referenced in schema. XML, but I only did one database, so I changed the default 3 to 1, or the corresponding number if you have multiple database tables.

<? xml version="1.0" encoding="UTF-8"? > <! -- -- Licensed under the Apache License, Version 2.0 (the"License"); 
	- you may not use this file except inThe compliance with the License. - You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed toin writing, software - 
	distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 
	License forthe specific language governing permissions and - limitations under the License. --> <! DOCTYPE mycat:rule SYSTEM"rule.dtd">
<mycat:rule xmlns:mycat="http://io.mycat/">
	<tableRule name="rule1">
		<rule>
			<columns>id</columns>
			<algorithm>func1</algorithm>
		</rule>
	</tableRule>

	<tableRule name="rule2">
		<rule>
			<columns>user_id</columns>
			<algorithm>func1</algorithm>
		</rule>
	</tableRule>

	<tableRule name="sharding-by-intfile">
		<rule>
			<columns>sharding_id</columns>
			<algorithm>hash-int</algorithm>
		</rule>
	</tableRule>
	<tableRule name="auto-sharding-long">
		<rule>
			<columns>id</columns>
			<algorithm>rang-long</algorithm>
		</rule>
	</tableRule>
	<tableRule name="mod-long">
		<rule>
			<columns>article_id</columns>
			<algorithm>mod-long</algorithm>
		</rule>
	</tableRule>
	<tableRule name="sharding-by-murmur">
		<rule>
			<columns>id</columns>
			<algorithm>murmur</algorithm>
		</rule>
	</tableRule>
	<tableRule name="crc32slot">
		<rule>
			<columns>id</columns>
			<algorithm>crc32slot</algorithm>
		</rule>
	</tableRule>
	<tableRule name="sharding-by-month">
		<rule>
			<columns>create_time</columns>
			<algorithm>partbymonth</algorithm>
		</rule>
	</tableRule>
	<tableRule name="latest-month-calldate">
		<rule>
			<columns>calldate</columns>
			<algorithm>latestMonth</algorithm>
		</rule>
	</tableRule>
	
	<tableRule name="auto-sharding-rang-mod">
		<rule>
			<columns>id</columns>
			<algorithm>rang-mod</algorithm>
		</rule>
	</tableRule>
	
	<tableRule name="jch">
		<rule>
			<columns>id</columns>
			<algorithm>jump-consistent-hash</algorithm>
		</rule>
	</tableRule>

	<function name="murmur"
		class="io.mycat.route.function.PartitionByMurmurHash">
		<property name="seed">0</property><! -- Default is 0 --> <property name="count">1</property><! -- The number of database nodes to be sharded must be specified, otherwise it cannot be sharded --> <property name="virtualBucketTimes">160</property><! An actual database node is mapped to this number of virtual nodes, which is 160 times the number of virtual nodes than the number of physical nodes by default. -- <property name="weightMapFile">weightMapFile</property> The weight of the node, default is 1 for nodes with no specified weight. Enter the value in the format of the properties file. The value is an integer from 0 to count-1, i.e. the node index is the key and the node weight is the value. The ownership weight must be a positive integer, otherwise 1 is substituted --> <! -- <property name="bucketMapPath"> /etc/mycat/bucketmappath </property> Is used to observe the distribution of physical nodes and virtual nodes. If this property is specified, the interface of the virtual node murmurhashThe mapping of values to physical nodes is printed to this file line by line. There is no default value. If not specified, nothing is printed --> </function>

	<function name="crc32slot"
			  class="io.mycat.route.function.PartitionByCRC32PreSlot">
		<property name="count">2</property><! The number of database nodes to be sharded must be specified, otherwise it cannot be shardedfunction>
	<function name="hash-int"
		class="io.mycat.route.function.PartitionByFileMap">
		<property name="mapFile">partition-hash-int.txt</property>
	</function>
	<function name="rang-long"
		class="io.mycat.route.function.AutoPartitionByLong">
		<property name="mapFile">autopartition-long.txt</property>
	</function>
	<function name="mod-long" class="io.mycat.route.function.PartitionByMod"> <! -- how many data nodes --> <property name="count">1</property><! -- There is only one database I changed to 1, default 3 --> </function>

	<function name="func1" class="io.mycat.route.function.PartitionByLong">
		<property name="partitionCount">8</property>
		<property name="partitionLength">128</property>
	</function>
	<function name="latestMonth"
		class="io.mycat.route.function.LatestMonthPartion">
		<property name="splitOneDay">24</property>
	</function>
	<function name="partbymonth"
		class="io.mycat.route.function.PartitionByMonth">
		<property name="dateFormat">yyyy-MM-dd</property>
		<property name="sBeginDate">2015-01-01</property>
	</function>
	
	<function name="rang-mod" class="io.mycat.route.function.PartitionByRangeMod">
        	<property name="mapFile">partition-range-mod.txt</property>
	</function>
	
	<function name="jump-consistent-hash" class="io.mycat.route.function.PartitionByJumpConsistentHash">
		<property name="totalBuckets">3</property>
	</function>
</mycat:rule>

Copy the code

Server.xml configuration information (complete configuration information and explained at the end of this article): Mainly defines SQL service-related parameters, such as account passwords, SQL transactions, and maximum text

<? xml version="1.0" encoding="UTF-8"? > <! Licensed under the Apache License, Version 2.0 (the"License"); 
	- you may not use this file except inThe compliance with the License. - You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed toin writing, software - 
	distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 
	License forthe specific language governing permissions and - limitations under the License. --> <! DOCTYPE mycat:server SYSTEM"server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
	<system>
	<property name="useSqlStat">0</property> <! -- 1: enable real-time statistics, 0: disable --> <property name="useGlobleTableCheck">0</property> <! -- 1 indicates that full overtime consistency check is enabled, 0 indicates that full overtime consistency check is disabled --> <property name="sequnceHandlerType">2</property> <! -- <property name="useCompression">1</property> --> <! --1 to enable mysql compression protocol --> <! -- <property name="fakeMySQLVersion"> 5.6.20 < / property > -- > <! -- Set the emulated MySQL version number --> <! -- <property name="processorBufferChunk">40960</property> --> <! -- <property name="processors">1</property> 
	<property name="processorExecutor">32</property> --> <! - the default istype 0: DirectByteBufferPool | type 1 ByteBufferArena-->
		<property name="processorBufferPoolType">0</property> <! -- Default is 65535 64K maximum text length for SQL parsing --> <property name="maxStringLiteralLength">65535</property>
		<property name="sequnceHandlerType">0</property>
		<property name="backSocketNoDelay">1</property>
		<property name="frontSocketNoDelay">1</property>
		<property name="processorExecutor">16</property>
		
			<property name="serverPort">8066</property> <property name="managerPort">9066</property> 
			<property name="idleTimeout">300000</property> <property name="bindIp"> 0.0.0.0 < / property > < property name ="frontWriteQueueSize">4096</property> <property name="processors">32</property> <! -- Distributed transaction switch. 0 indicates that distributed transactions are not filtered, 1 indicates that distributed transactions are filtered (if only global tables are involved in distributed transactions), 2 indicates that distributed transactions are not filtered, but distributed transaction logs are logged"handleDistributedTransactions">0</property> <! -- off heapfor merge/order/group/limit1 On 0 Off --> <property name="useOffHeapForMerge">1</property> <! -- unit: m --> <property name="memoryPageSize">1m</property> <! -- unit: k --> <property name="spillsFileBufferSize">1k</property>

		<property name="useStreamOutput">0</property> <! -- unit: m --> <property name="systemReserveMemorySize">384m</property> <! -- Whether to use ZooKeeper --> <property name="useZKSwitch">true</property> </system> <! -- Global SQL firewall Settings --> <! -- <firewall> <whitehost> <host host="127.0.0.1" user="mycat"/>
	      <host host="127.0.0.2" user="mycat"/>
	   </whitehost>
       <blacklist check="false"> </blacklist> </firewall> --> <! Database name as defined in schema.xml --> <user name="mycatuser">
		<property name="password">mycatpwd</property>
		<property name="schemas">MycatDemo</property>
		<property name="defaultAccount">true</property> <! -- Table level DML permission Settings --> <! -- <privileges check="false">
			<schema name="TESTDB" dml="0110" >
				<table name="tb01" dml="0000"></table>
				<table name="tb02" dml="1111"></table> </schema> </privileges> --> </user> <! Database name as defined in schema.xml --> <user name="user">
		<property name="password">user</property>
		<property name="schemas">MycatDemo</property>
		<property name="readOnly">true</property>
	</user>

</mycat:server>

Copy the code

Database name: MycatDemo(schema.xml) Account: mycatuser(server.xml) password: mycatpwd(server.xml)

Verifying read/write separation

Enter the mysql command line, enable the SQL log of the primary and secondary databases, and determine which library is used for reading and writing according to the SQL log execution

# check the date

mysql>show variables like '%general%';
Copy the code

# enable log

mysql>SET GLOBAL general_log = 'On';
Copy the code

# specify a log file

mysql>SET GLOBAL general_log_file = '/var/lib/mysql/mysql.log';
Copy the code

Mycat performance monitoring

Mycat performance monitoring WEB management software, there is a need to download the installation

Configuration File Description

XML file description

<? xml version="1.0" encoding="UTF-8"? > <! -- -- Licensed under the Apache License, Version 2.0 (the"License"); 
	- you may not use this file except inThe compliance with the License. - You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed toin writing, software - 
	distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 
	License forthe specific language governing permissions and - limitations under the License. --> <! DOCTYPE mycat:server SYSTEM"server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
	<system>
	<property name="nonePasswordLogin">0</property> <! The default value is 0. If the value is set to 1, you need to specify the default account --> <property name="useHandshakeV10">1</property>
	<property name="useSqlStat">0</property> <! -- 1: enable real-time statistics, 0: disable --> <property name="useGlobleTableCheck">0</property> <! -- 1 indicates that full overtime consistency check is enabled, 0 indicates that full overtime consistency check is disabled --> <property name="sequnceHandlerType">2</property> <! --0 Local file mode 1 Database mode 2 Timestamp mode --> <property name="subqueryRelationshipCheck">false</property> <! -- If the sub-query contains associated query, check whether the associated field contains fragment fields. The defaultfalse-- > <! -- <property name="useCompression">1</property>--> <! --1 to enable mysql compression protocol --> <! -- <property name="fakeMySQLVersion"> 5.6.20 < / property > -- > <! -- Set the emulated MySQL version number --> <! -- <property name="processorBufferChunk">40960</property> --> <! -- <property name="processors">1</property> 
	<property name="processorExecutor">32</property> --> <! - the default istype 0: DirectByteBufferPool | type 1 ByteBufferArena | type 2 NettyBufferPool -->
		<property name="processorBufferPoolType">0</property> <! -- Default is 65535 64K maximum text length for SQL parsing --> <! --<property name="maxStringLiteralLength">65535</property>--> <! --<property name="sequnceHandlerType">0</property>--> <! --<property name="backSocketNoDelay">1</property>--> <! --<property name="frontSocketNoDelay">1</property>--> <! --<property name="processorExecutor">16</property>--> <! -- <property name="serverPort">8066</property> <property name="managerPort">9066</property> 
			<property name="idleTimeout">300000</property> <property name="bindIp"> 0.0.0.0 < / property > < property name ="frontWriteQueueSize">4096</property> <property name="processors">32</property> --> <! -- Distributed transaction switch. 0 indicates that distributed transactions are not filtered, 1 indicates that distributed transactions are filtered (if only global tables are involved in distributed transactions), 2 indicates that distributed transactions are not filtered, but distributed transaction logs are logged"handleDistributedTransactions">0</property> <! -- off heapfor merge/order/group/limit1 On 0 Off --> <property name="useOffHeapForMerge">1</property> <! -- unit: m --> <property name="memoryPageSize">64k</property> <! -- unit: k --> <property name="spillsFileBufferSize">1k</property>

		<property name="useStreamOutput">0</property> <! -- unit: m --> <property name="systemReserveMemorySize">384m</property> <! -- Whether to use ZooKeeper --> <property name="useZKSwitch">false</property> <! -- XA Recovery Log Log path --> <! --<property name="XARecoveryLogBaseDir">./</property>--> <! -- XA Recovery Log --> <! --<property name="XARecoveryLogBaseName">tmlog</property>--> <! - if fortrueIf the isolation level is strictly observed, the connection will not be switched in a transaction when there are only SELECT statements --> <property name="strictTxIsolation">false</property>
		
		<property name="useZKSwitch">true</property> </system> <! -- Global SQL firewall Settings --> <! -- Whitelist can use wildcard % or *--> <! -- For example, <host host="127.0.0. *" user="root"/ > -- > <! -- For example, <host host="127.0. *" user="root"/ > -- > <! -- For example, <host host=127. * "" user="root"/ > -- > <! -- For example, <host host="1 * 7. *" user="root"/ > -- > <! For 127.0.0.1, you can log in as root --> <! -- <firewall> <whitehost> <host host="1 * 7.0.0. *" user="root"/>
	   </whitehost>
       <blacklist check="false"> </blacklist> </firewall> --> <! Mycat --> <user name="mycat" defaultAccount="true"> <! -- Password 123456--> <property name="password">123456</property> <! Mycatdb --> <property name="schemas">mycatdb</property> <! -- Table level DML permission Settings --> <! -- <privileges check="false">
			<schema name="TESTDB" dml="0110" >
				<table name="tb01" dml="0000"></table>
				<table name="tb02" dml="1111"></table>
			</schema>
		</privileges>		
		 -->
	</user>

	<user name="user">
		<property name="password">user</property>
		<property name="schemas">mycatdb</property> <! -- Read-only --> <property name="readOnly">true</property>
	</user>

</mycat:server>

Copy the code

Schema. XML file description

<? xml version="1.0"? > <! DOCTYPE mycat:schema SYSTEM"schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/"> <! -- checkSQLschema This attribute is set by defaultfalseSelect * from db1.testtable from db1.testtabletrueIt gets rid of db1. However, if the db1 name is not the name of the schema, it will not be removed, so it is officially recommended not to use this syntax. And the default setting isfalse. -- > <! -- sqlMaxLimit When the value is set to a value. Each SQL statement executed, if not appendedlimitStatement, MyCat will automatically add the corresponding value. For example, if the value is 100 and you run select * from test_table, the effect is selelct * from test_tablelimit100 ". Note: This property does not take effect if you are running a schema that is not a split-library. --> <schema name="mycatdb" checkSQLschema="false" sqlMaxLimit="100"> <! -- name Specifies the name of the logical table --> <! -- dataNode This attribute defines the dataNode to which the logical table belongs. The value of this attribute must correspond to the value of the name attribute in the dataNode tag. -- > <! -- rule Specifies the name of the rule to be used by the logical table. The name of the rule is defined in rule-xml and must correspond to the value of the name attribute in tableRule --> <! -- ruleRequired Specifies whether the table is bound to sharding rules, if set totrue, but the program will report an error if no specific rule is configured. -- > <! -- primaryKey this logical table corresponds to the primaryKey of the real table, --> <! --typeThis attribute defines the types of logical tables. Currently, there are only two types of logical tables: Global table and Common table. Global table definitiontype= "global", does not define the ordinary table. -- > <! -- autoIncrement Indicates whether the primary key grows automatically. -- > <! -- subTables subTables, which currently do not support joins. -- > <! NeedAddLimit Whether to add automaticallylimit, is enabled by default. Close with caution. -- > <! --rule="mod-long"Specify rule configuration in rule --> <table name="users" primaryKey="id" dataNode="dn1"/>
		<table name="orders" primaryKey="id" dataNode="dn1"/>
		
		
		<table name="product" primaryKey="id" dataNode="dn2"/>
		<table name="news" primaryKey="id" dataNode="dn2"/> </schema> <! -- Name Defines the Name of the data node. This Name must be unique --> <! -- dataHost This property defines which database instance the shard belongs to --> <! -- Database This attribute defines the specific library on which specific Database instance the shard attribute belongs to --> <dataNode name="dn1" dataHost="localhost1" database="sharding1" />
	<dataNode name="dn2" dataHost="localhost2" database="sharding2"/ > <! -- name uniquely identifies the dataHost tag and is used by upper-level tags --> <! -- maxCon Specifies the maximum connection for each read/write instance connection pool. -- > <! -- minCon Specifies the minimum connection for each read/write instance connection pool, initializing the pool size. -- > <! -- balance Load balancing type. Currently, there are four values: 0. The read/write separation mechanism is disabled and all read operations are sent to the currently available writeHost. "1", all of themreadHost and stand by writeHost participate in load balancing of SELECT statements. To put it simply, when there are two modes (M1->S1, M2->S2, and M1 and M2 are in active/standby mode), under normal circumstances, M2,S1, and S2 all participate in load balancing for select statements." 2 ", all read operations are distributed randomly on writeHost and readhost. WriteType 1. WriteType = "0", all write operations are sent to the first configured writeHost. Dnindex. properties.2. WriteType = "1", all write operations are randomly sent to the configured writeHost. Deprecation after 1.5 is not recommended. Default 0 is fine! -- > <! -- dbType Specifies the type of database to connect to in the backend. Currently, binary mysql protocol is supported, as well as other databases using JDBC connections. For example, mongodb, Oracle, and Spark. -- dbDriver Specifies the Driver used to connect to the back-end database. Currently, the available values are native and JDBC. With Native, mysql and Maridb can be used because this value executes the binary mysql protocol. Other types of databases require JDBC driver support. -- > <! -- switchType -1: no automatic switchover. "1" default value, automatic switchover. "2" Determines whether to switch the heartbeat statement based on the master/slave synchronization status of MySQL. Show status like 'wsrep%' --> <! --slaveThreshold: Specifies the maximum number of slave nodes --> <dataHost name="localhost1" 
			  maxCon="1000" 
			  minCon="10" 
			  balance="0"
			  writeType="0" 
			  dbType="mysql" 
			  dbDriver="native" 
			  switchType="1"  
			  slaveThreshold="100"> <heartbeat>select user()</heartbeat> <! --host is used to identify different instances. Generally, writeHost is used with *M1.readFor Host we use S1. -- > <! -- URL Indicates the connection address of the back-end instance. JDBC: JDBC url--> <! --password Password required by the back-end storage instance --> <! --user User name required by the back-end storage instance --> <! --weight weight configured in readhost as the weight of the read node --> <! --usingDecrypt Whether to encrypt passwords. Default is 0. Specific encryption method to see the official document. --> <writeHost host="hostM1" url="47.94.158.155:3306" user="root"
				   password="TJXtjx_19991007">
		</writeHost>
	</dataHost>
	
	
	<dataHost name="localhost2" 
			  maxCon="1000" 
			  minCon="10" 
			  balance="0"
			  writeType="0" 
			  dbType="mysql" 
			  dbDriver="native" 
			  switchType="1"  
			  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<writeHost host="hostM2" url="47.94.158.155:3306" user="root"
				   password="TJXtjx_19991007">
		</writeHost>
	</dataHost>

</mycat:schema>
Copy the code

Rule. XML file description

<? xml version="1.0" encoding="UTF-8"? > <! -- -- Licensed under the Apache License, Version 2.0 (the"License"); 
	- you may not use this file except inThe compliance with the License. - You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed toin writing, software - 
	distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 
	License forthe specific language governing permissions and - limitations under the License. --> <! DOCTYPE mycat:rule SYSTEM"rule.dtd">
<mycat:rule xmlns:mycat="http://io.mycat/">
	<tableRule name="rule1">
		<rule>
			<columns>id</columns>
			<algorithm>func1</algorithm>
		</rule>
	</tableRule>

	<tableRule name="rule2">
		<rule>
			<columns>user_id</columns>
			<algorithm>func1</algorithm>
		</rule>
	</tableRule>

	<tableRule name="sharding-by-intfile">
		<rule>
			<columns>sharding_id</columns>
			<algorithm>hash-int</algorithm>
		</rule>
	</tableRule>
	<tableRule name="auto-sharding-long">
		<rule>
			<columns>id</columns>
			<algorithm>rang-long</algorithm>
		</rule>
	</tableRule>
	<tableRule name="mod-long">
		<rule>
			<columns>id</columns>
			<algorithm>mod-long</algorithm>
		</rule>
	</tableRule>
	<tableRule name="sharding-by-murmur">
		<rule>
			<columns>id</columns>
			<algorithm>murmur</algorithm>
		</rule>
	</tableRule>
	<tableRule name="crc32slot">
		<rule>
			<columns>id</columns>
			<algorithm>crc32slot</algorithm>
		</rule>
	</tableRule>
	<tableRule name="sharding-by-month">
		<rule>
			<columns>create_time</columns>
			<algorithm>partbymonth</algorithm>
		</rule>
	</tableRule>
	<tableRule name="latest-month-calldate">
		<rule>
			<columns>calldate</columns>
			<algorithm>latestMonth</algorithm>
		</rule>
	</tableRule>
	
	<tableRule name="auto-sharding-rang-mod">
		<rule>
			<columns>id</columns>
			<algorithm>rang-mod</algorithm>
		</rule>
	</tableRule>
	
	<tableRule name="jch">
		<rule>
			<columns>id</columns>
			<algorithm>jump-consistent-hash</algorithm>
		</rule>
	</tableRule>

	<function name="murmur"
		class="io.mycat.route.function.PartitionByMurmurHash">
		<property name="seed">0</property><! -- Default is 0 --> <property name="count">2</property><! -- The number of database nodes to be sharded must be specified, otherwise it cannot be sharded --> <property name="virtualBucketTimes">160</property><! An actual database node is mapped to this number of virtual nodes, which is 160 times the number of virtual nodes than the number of physical nodes by default. -- <property name="weightMapFile">weightMapFile</property> The weight of the node, default is 1 for nodes with no specified weight. Enter the value in the format of the properties file. The value is an integer from 0 to count-1, i.e. the node index is the key and the node weight is the value. The ownership weight must be a positive integer, otherwise 1 is substituted --> <! -- <property name="bucketMapPath"> /etc/mycat/bucketmappath </property> Is used to observe the distribution of physical nodes and virtual nodes. If this property is specified, the interface of the virtual node murmurhashThe mapping of values to physical nodes is printed to this file line by line. There is no default value. If not specified, nothing is printed --> </function>

	<function name="crc32slot"
			  class="io.mycat.route.function.PartitionByCRC32PreSlot">
	</function>
	<function name="hash-int"
		class="io.mycat.route.function.PartitionByFileMap">
		<property name="mapFile">partition-hash-int.txt</property>
	</function>
	<function name="rang-long"
		class="io.mycat.route.function.AutoPartitionByLong">
		<property name="mapFile">autopartition-long.txt</property>
	</function>
	<function name="mod-long" class="io.mycat.route.function.PartitionByMod"> <! -- how many data nodes --> <property name="count">3</property>
	</function>

	<function name="func1" class="io.mycat.route.function.PartitionByLong">
		<property name="partitionCount">8</property>
		<property name="partitionLength">128</property>
	</function>
	<function name="latestMonth"
		class="io.mycat.route.function.LatestMonthPartion">
		<property name="splitOneDay">24</property>
	</function>
	<function name="partbymonth"
		class="io.mycat.route.function.PartitionByMonth">
		<property name="dateFormat">yyyy-MM-dd</property>
		<property name="sBeginDate">2015-01-01</property>
	</function>
	
	<function name="rang-mod" class="io.mycat.route.function.PartitionByRangeMod">
        	<property name="mapFile">partition-range-mod.txt</property>
	</function>
	
	<function name="jump-consistent-hash" class="io.mycat.route.function.PartitionByJumpConsistentHash">
		<property name="totalBuckets">3</property>
	</function>
</mycat:rule>

Copy the code