Mycat配置文件

Mycat配置文件

    • 主要配置文件
    • 配置文件详解
      • server.xml
      • schema.xml
      • rule.xml

主要配置文件

Mycat的github地址
Mycat配置文件_第1张图片
从这张图中就能知道,mycat的主要配置文件就三个:

  • server.xml: 配置Mycat服务器参数和用户授权。
  • schema.xml:配置逻辑库、表和分片。
  • rule.xml: 是分片规则的配置文件,配置文件修改需要重启Mycat。

配置文件详解

server.xml

这个配置文件中:system中是配置的Mycat的服务器参数,user中配置的是用户、用户权限以及库信息。



<mycat:server xmlns:mycat="http://io.mycat/">
	
	<system>
	<property name="nonePasswordLogin">0property> 
	<property name="useHandshakeV10">1property>
	<property name="useSqlStat">0property>  
	<property name="useGlobleTableCheck">0property>  

		<property name="sequnceHandlerType">2property>
	<property name="subqueryRelationshipCheck">falseproperty> 
       
         
	
	
        
		<property name="processorBufferPoolType">0property>
		
		
		
		
		
		
		
		
		<property name="handleDistributedTransactions">0property>
			
		<property name="useOffHeapForMerge">0property>
		
        <property name="memoryPageSize">64kproperty>
		
		<property name="spillsFileBufferSize">1kproperty>
		<property name="useStreamOutput">0property>
		
		<property name="systemReserveMemorySize">384mproperty>
		
		<property name="useZKSwitch">falseproperty>

		
		

		
		
		
		<property name="strictTxIsolation">falseproperty>
		<property name="useZKSwitch">trueproperty>
	system>
	
	
	
	
	
	
	
	
	
	<user name="root" defaultAccount="true">
		<property name="password">123456property>
		
		<property name="schemas">TESTDBproperty>
		
		
		
	user>
	<user name="user">
		<property name="password">userproperty>
		<property name="schemas">TESTDBproperty>
		
		<property name="readOnly">trueproperty>
	user>
mycat:server>

schema.xml

配置中主要包括:schema:虚拟数据库,dataNode:数据节点,dataHost:实际物理地址



<mycat:schema xmlns:mycat="http://io.mycat/">
	
	<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
		
		
		<table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" />
		
		<table name="company" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" />
		
		<table name="hotnews" primaryKey="ID" autoIncrement="true" dataNode="dn1,dn2,dn3" rule="mod-long" />
		
		<table name="employee" primaryKey="ID" dataNode="dn1,dn2" rule="sharding-by-intfile" />
		
		<table name="customer" primaryKey="ID" dataNode="dn1,dn2" rule="sharding-by-intfile">
			<childTable name="orders" primaryKey="ID" joinKey="customer_id" parentKey="id">
				<childTable name="order_items" joinKey="order_id" parentKey="id" />
			childTable>
			<childTable name="customer_addr" primaryKey="ID" joinKey="customer_id" parentKey="id" />
		table>
		
		<table name="oc_call" primaryKey="ID" dataNode="dn1$0-743" rule="latest-month-calldate" />
	schema>
	
	
	<dataNode name="dn1" dataHost="node1" database="db1" />
	<dataNode name="dn2" dataHost="node2" database="db2" />
	<dataNode name="dn3" dataHost="node2" database="db3" />
	
	<dataHost name="node1" maxCon="1000" minCon="10" balance="0"  writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		
		<heartbeat>select user()heartbeat>
		
		<writeHost host="hostM1" url="localhost:3306" user="root" password="123456">
			
			<readHost host="hostS2" url="192.168.1.200:3306" user="root" password="xxx" />
		writeHost>
		
		<writeHost host="hostS1" url="localhost:3316" user="root" password="123456" />
	dataHost>
	

	
mycat:schema>

rule.xml



<mycat:rule xmlns:mycat="http://io.mycat/">
	<tableRule name="rule1">
		<rule>
			<columns>idcolumns>
			<algorithm>func1algorithm>
		rule>
	tableRule>

	<tableRule name="rule2">
		<rule>
			<columns>user_idcolumns>
			<algorithm>func1algorithm>
		rule>
	tableRule>

	<tableRule name="sharding-by-intfile">
		<rule>
			<columns>sharding_idcolumns>
			<algorithm>hash-intalgorithm>
		rule>
	tableRule>
	<tableRule name="auto-sharding-long">
		<rule>
			<columns>idcolumns>
			<algorithm>rang-longalgorithm>
		rule>
	tableRule>
	<tableRule name="mod-long">
		<rule>
			<columns>idcolumns>
			<algorithm>mod-longalgorithm>
		rule>
	tableRule>
	<tableRule name="sharding-by-murmur">
		<rule>
			<columns>idcolumns>
			<algorithm>murmuralgorithm>
		rule>
	tableRule>
	<tableRule name="crc32slot">
		<rule>
			<columns>idcolumns>
			<algorithm>crc32slotalgorithm>
		rule>
	tableRule>
	<tableRule name="sharding-by-month">
		<rule>
			<columns>create_timecolumns>
			<algorithm>partbymonthalgorithm>
		rule>
	tableRule>
	<tableRule name="latest-month-calldate">
		<rule>
			<columns>calldatecolumns>
			<algorithm>latestMonthalgorithm>
		rule>
	tableRule>
	
	<tableRule name="auto-sharding-rang-mod">
		<rule>
			<columns>idcolumns>
			<algorithm>rang-modalgorithm>
		rule>
	tableRule>
	
	<tableRule name="jch">
		<rule>
			<columns>idcolumns>
			<algorithm>jump-consistent-hashalgorithm>
		rule>
	tableRule>

	<function name="murmur"
		class="io.mycat.route.function.PartitionByMurmurHash">
		<property name="seed">0property>
		<property name="count">2property>
		<property name="virtualBucketTimes">160property>
		
		
	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.txtproperty>
	function>
	<function name="rang-long"
		class="io.mycat.route.function.AutoPartitionByLong">
		<property name="mapFile">autopartition-long.txtproperty>
	function>
	<function name="mod-long" class="io.mycat.route.function.PartitionByMod">
		
		<property name="count">3property>
	function>

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

自学Mycat,有表达不当之处还请指正!!

你可能感兴趣的:(MySql)