mycat分库

mycat分库

1.分别在节点上创建同一个名称的数据库

#在数据节点上分别创建数据库 orders1
CREATE DATABASE orders1;

2.schema.xml配置文件

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
	<schema name="khtdb" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn1">
	   <table name="customer" dataNode="dn2" ></table>
	</schema>
	<dataNode name="dn1" dataHost="host1" database="orders" />
	<dataNode name="dn2" dataHost="host2" database="orders" />
	<dataHost name="host1" maxCon="1000" minCon="10" balance="0"
			  writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
    <writeHost host="hostM1" url="192.168.2.128:3306" user="root"
				   password="kht123">
    </writeHost>
	</dataHost>
	
	<dataHost name="host2" maxCon="1000" minCon="10" balance="0"
			  writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
    <writeHost host="hostM2" url="192.168.2.129:3306" user="root"
				   password="kht123">
    </writeHost>
	</dataHost>
</mycat:schema>

3.重启mycat并进入mycat命令行执行建表语句,查看服务器上四张表的区分

#客户表 rows:20万
CREATE TABLE customer(
id INT AUTO_INCREMENT,
NAME VARCHAR(200),
PRIMARY KEY(id)
);
#订单表 rows:600万
CREATE TABLE orders(
id INT AUTO_INCREMENT,
order_type INT,
customer_id INT,
amount DECIMAL(10,2),
PRIMARY KEY(id)
);
#订单详细表 rows:600万
CREATE TABLE orders_detail(
id INT AUTO_INCREMENT,
detail VARCHAR(2000),
order_id INT,
PRIMARY KEY(id)
);
#订单状态字典表 rows:20
CREATE TABLE dict_order_type(
id INT AUTO_INCREMENT,
order_type VARCHAR(200),
PRIMARY KEY(id)
);

mycat分库

上一篇:本地开发环境配置覆盖远程配置


下一篇:信息系统项目管理师高频考点(第九章)