标签:any cap store sql ini tail 数据库配置 set str
此文转载自:https://blog.csdn.net/ZHAI_KE/article/details/110064468<property name="sequnceHandlerType">1</property>
#所有操作都在一个物理数据库(dn1)上
#创建 MYCAT_SEQUENCE 表
#name sequence 名称
#current_value 当前 value
#increment 增长步长!
#mycat在数据库中一次读取多少个sequence
DROP TABLE IF EXISTS MYCAT_SEQUENCE;
CREATE TABLE MYCAT_SEQUENCE (
`name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT ‘名称‘,
`current_value` int(11) NOT NULL COMMENT ‘当前值‘,
`increment` int(11) NOT NULL DEFAULT 1 COMMENT ‘步长‘,
PRIMARY KEY (`name`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
#插入一条 sequence
INSERT INTO MYCAT_SEQUENCE(name,current_value,increment) VALUES (‘PERSON’,
100000, 100);
#创建相关 function
#获取当前 sequence 的值 (返回当前值,增量)
DROP FUNCTION IF EXISTS mycat_seq_currval;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `mycat_seq_currval`(seq_name VARCHAR(50))
RETURNS VARCHAR(64) charset utf8
DETERMINISTIC
BEGIN
DECLARE retval VARCHAR(64);
SET retval="-999999999,null";
SELECT CONCAT(CAST(current_value AS CHAR),",",CAST(increment AS
CHAR) ) INTO retval
FROM MYCAT_SEQUENCE WHERE NAME = seq_name;
RETURN retval ;
END
;;
DELIMITER ;
#设置 sequence 值
DROP FUNCTION IF EXISTS mycat_seq_setval;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION mycat_seq_setval(seq_name VARCHAR(50),value INTEGER)
RETURNS varchar(64) CHARSET utf8
DETERMINISTIC
BEGIN
UPDATE MYCAT_SEQUENCE
SET current_value = value
WHERE name = seq_name;
RETURN mycat_seq_currval(seq_name);
END ;;
DELIMITER ;
#获取下一个 sequence 值
DROP FUNCTION IF EXISTS `mycat_seq_nextval`;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `mycat_seq_nextval`(seq_name VARCHAR(50))
RETURNS VARCHAR(64)CHARSET utf8
DETERMINISTIC
BEGIN
UPDATE MYCAT_SEQUENCE SET current_value = current_value + increment
WHERE NAME = seq_name;
RETURN mycat_seq_currval(seq_name);
END;;
DELIMITER ;
#sequence stored in datanode
GLOBAL=dn1
COMPANY=dn1
CUSTOMER=dn1
ORDERS=dn1
SYS_USER=dn1
TBL_MEMBER=dn1
<schema name="DB1" checkSQLschema="false" sqlMaxLimit="100">
<table name="sys_user" primaryKey="user_id" autoIncrement="true" dataNode="dn$1-2" rule="rule1" splitTableNames ="true"/>
</schema>
<dataNode name="dn$1-2" dataHost="localhost1" database="db$1-2" />
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="hostM1" url="xxxx:8066" user="mycat" password="xxxxxx">
</writeHost>
</dataHost>
./mycat restart
标签:any cap store sql ini tail 数据库配置 set str
原文地址:https://www.cnblogs.com/phyger/p/14035026.html