mycat的使用前提:先配置好mysql8的主从环境
mysql8主从

注意t_user不要使用自增主键
mycat安装使用_数据库
下载mycat1.6.7.6
mycat官网

tar -zxvf Mycat…tar.gz
我们修改conf目录下的server.xml和schame.xml文件

schame.xml

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">

	<!--t_user是逻辑表-->
	<schema name="user" checkSQLschema="false" sqlMaxLimit="100">
		<table name="t_user" primaryKey="id" dataNode="dn1,dn2,dn3" rule="mod-long" />
	</schema>
	
	
	<dataNode name="dn1" dataHost="localhost1" database="user1" />
	<dataNode name="dn2" dataHost="localhost1" database="user2" />
	<dataNode name="dn3" dataHost="localhost1" database="user3" />
	
	<dataHost name="localhost1" 
			  maxCon="1000" 
			  minCon="10" 
			  balance="1"
			  writeType="0" 
			  dbType="mysql" 
			  dbDriver="native" 
			  switchType="1"  
			  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		
		<writeHost host="hostMadmin" url="192.168.131.101:3306" user="root" password="root">
			<readHost host="hostSadmin" url="192.168.131.102:3306" user="root" password="root" />
		</writeHost>
	</dataHost>
</mycat:schema>

server.xml
system标签的内容无需修改

	<!--user user用户可读可写权限-->
	<user name="root" defaultAccount="true">
		<property name="password">root</property>
		<property name="schemas">user</property>
		
		<!-- 表级 DML 权限设置,0110表示增删改查,只有删和改的权限 -->
		<!-- 		
		<privileges check="false">
			<schema name="TESTDB" dml="0110" >
				<table name="tb01" dml="0000"></table>
				<table name="tb02" dml="1111"></table>
			</schema>
		</privileges>		
		 -->
	</user>
	
	<!--user user用户只读权限-->
	<user name="user">
		<property name="password">user</property>
		<property name="schemas">user</property>
		<property name="readOnly">true</property>
	</user>

启动mycat
bin/mycat start

navicat测试
mycat安装使用_mycat_02在新建的mycat连接上
insert into t_user (id,name) VALUES (1, ‘1’)
insert into t_user (id,name) VALUES (2, ‘2’)
insert into t_user (id,name) VALUES (3, ‘3’)
发现user1,user2,user3各有一条数据,证明成功了