准备三台服务器,具体的结构如下:
并且,在三台数据库服务器中分表创建一个数据库test。
- <schema name="TEST" checkSQLschema="true" sqlMaxLimit="100">
- <table name="tb_log" dataNode="dn4,dn5,dn6" primaryKey="id" rule="mod-long" />
- </schema>
- <dataNode name="dn4" dataHost="dhost1" database="test" />
- <dataNode name="dn5" dataHost="dhost2" database="test" />
- <dataNode name="dn6" dataHost="dhost3" database="test" />
- <dataHost name="dhost1" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="jdbc" switchType="1" slaveThreshold="100">
- <heartbeat>select user()</heartbeat>
- <writeHost host="master" url="jdbc:mysql://192.168.2.3:3306?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf8" user="root" password="newPwd520@" />
- </dataHost>
- <dataHost name="dhost2" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="jdbc" switchType="1" slaveThreshold="100">
- <heartbeat>select user()</heartbeat>
- <writeHost host="master" url="jdbc:mysql://192.168.2.4:3306?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf8" user="root" password="newPwd520@" />
- </dataHost>
- <dataHost name="dhost3" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="jdbc" switchType="1" slaveThreshold="100">
- <heartbeat>select user()</heartbeat>
- <writeHost host="master" url="jdbc:mysql://192.168.2.5:3306?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf8" user="root" password="newPwd520@" />
- </dataHost>
- <user name="root" defaultAccount="true">
- <property name="password">123456</property>
- <property name="schemas">SHOPPING,TEST</property>
- <!-- 表级 DML 权限设置 -->
- <!--
- <privileges check="true">
- <schema name="DB01" dml="0110" >
- <table name="TB_ORDER" dml="1110"></table>
- </schema>
- </privileges>
- -->
- </user>
- CREATE TABLE tb_log (
- id bigint(20) NOT NULL COMMENT 'ID',
- model_name varchar(200) DEFAULT NULL COMMENT '模块名',
- model_value varchar(200) DEFAULT NULL COMMENT '模块值',
- return_value varchar(200) DEFAULT NULL COMMENT '返回值',
- return_class varchar(200) DEFAULT NULL COMMENT '返回值类型',
- operate_user varchar(20) DEFAULT NULL COMMENT '操作用户',
- operate_time varchar(20) DEFAULT NULL COMMENT '操作时间',
- param_and_value varchar(500) DEFAULT NULL COMMENT '请求参数名及参数值',
- operate_class varchar(200) DEFAULT NULL COMMENT '操作类',
- operate_method varchar(200) DEFAULT NULL COMMENT '操作方法',
- cost_time bigint(20) DEFAULT NULL COMMENT '执行方法耗时, 单位 ms',
- source int(1) DEFAULT NULL COMMENT '来源 : 1 PC , 2 Android , 3 IOS',
- PRIMARY KEY (id)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
- INSERT INTO TB_LOG (id, model_name, model_value, return_value, return_class,
- operate_user, operate_time, param_and_value, operate_class, operate_method,
- cost_time,source)
- VALUES('1','user','insert','success','java.lang.String','10001','2022-01-06
- 18:12:28','{\"age\":\"20\",\"name\":\"Tom\",\"gender\":\"1\"}','cn.itcast.contro
- ller.UserController','insert','10',1);
- INSERT INTO TB_LOG (id, model_name, model_value, return_value, return_class,
- operate_user, operate_time, param_and_value, operate_class, operate_method,
- cost_time,source)
- VALUES('2','user','insert','success','java.lang.String','10001','2022-01-06
- 18:12:27','{\"age\":\"20\",\"name\":\"Tom\",\"gender\":\"1\"}','cn.itcast.contro
- ller.UserController','insert','23',1);
- INSERT INTO TB_LOG (id, model_name, model_value, return_value, return_class,
- operate_user, operate_time, param_and_value, operate_class, operate_method,
- cost_time,source)
- VALUES('3','user','update','success','java.lang.String','10001','2022-01-06
- 18:16:45','{\"age\":\"20\",\"name\":\"Tom\",\"gender\":\"1\"}','cn.itcast.contro
- ller.UserController','update','34',1);
- INSERT INTO TB_LOG (id, model_name, model_value, return_value, return_class,
- operate_user, operate_time, param_and_value, operate_class, operate_method,
- cost_time,source)
- VALUES('4','user','update','success','java.lang.String','10001','2022-01-06
- 18:16:45','{\"age\":\"20\",\"name\":\"Tom\",\"gender\":\"1\"}','cn.itcast.contro
- ller.UserController','update','13',2);
- INSERT INTO TB_LOG (id, model_name, model_value, return_value, return_class,
- operate_user, operate_time, param_and_value, operate_class, operate_method,
- cost_time,source)
- VALUES('5','user','insert','success','java.lang.String','10001','2022-01-06
- 18:30:31','{\"age\":\"200\",\"name\":\"TomCat\",\"gender\":\"0\"}','cn.itcast.co
- ntroller.UserController','insert','29',3);
- INSERT INTO TB_LOG (id, model_name, model_value, return_value, return_class,
- operate_user, operate_time, param_and_value, operate_class, operate_method,
- cost_time,source)
- VALUES('6','user','find','success','java.lang.String','10001','2022-01-06
- 18:30:31','{\"age\":\"200\",\"name\":\"TomCat\",\"gender\":\"0\"}','cn.itcast.co
- ntroller.UserController','find','29',2);