码迷,mamicode.com
首页 > 其他好文 > 详细

土在在

时间:2016-11-22 11:37:14      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:blog   _for   htm   long   password   count   cap   creat   bash   

<mycat:schema xmlns:mycat="http://org.opencloudb/" >
	<schema name="db_zsxh_bm" checkSQLschema="false" sqlMaxLimit="100">
		<table name="tb_active_record_cluster" autoIncrement="true" primaryKey="id" dataNode="dn1,dn2" rule="rule1"/>
                <table name="tb_active_record_master" autoIncrement="true" primaryKey="id" dataNode="dn1,dn2" rule="rule1"/>
                <table name="tb_success_content" autoIncrement="true" primaryKey="id" dataNode="dn1,dn2" rule="rule1"/>
                <table name="tb_active_manager" autoIncrement="true" primaryKey="id" dataNode="dn1,dn2" rule="rule1"/>
                <table name="tb_activity" autoIncrement="true" primaryKey="id" dataNode="dn1,dn2" rule="rule1"/>
                <table name="tb_admin" autoIncrement="true" primaryKey="id" dataNode="dn1,dn2" rule="rule1"/>
                <table name="tb_bill_record" autoIncrement="true" primaryKey="id" dataNode="dn1,dn2" rule="rule1"/>
                <table name="tb_certification_body" autoIncrement="true" primaryKey="id" dataNode="dn1,dn2" rule="rule1"/>
                <table name="tb_dic" autoIncrement="true" primaryKey="id" dataNode="dn1,dn2" rule="rule1"/>
                <table name="tb_diy_form" autoIncrement="true" primaryKey="id" dataNode="dn1,dn2" rule="rule1"/>
                <table name="tb_log" autoIncrement="true" primaryKey="id" dataNode="dn1,dn2" rule="rule1"/>
                <table name="tb_sub_manager_resource" autoIncrement="true" primaryKey="id" dataNode="dn1,dn2" rule="rule1"/>
                <table name="tb_web_mapping" autoIncrement="true" primaryKey="id" dataNode="dn1,dn2" rule="rule1"/>
                <table name="tb_captcha" autoIncrement="true" primaryKey="id" dataNode="dn1,dn2" rule="rule1"/>
    </schema>

    <dataNode name="dn1" dataHost="localhost1" database="db_zsxh_bm" />
    <dataNode name="dn2" dataHost="localhost2" database="db_zsxh_bm" />

    <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="MySql地址:3306" user="root"  password="123456">
        </writeHost>
    </dataHost>

    <dataHost name="localhost2" maxCon="1000" minCon="10" balance="0"
        writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
        <heartbeat>select user()</heartbeat>
        <writeHost host="hostM1" url="MySql地址:3306" user="root"  password="123456">
        </writeHost>
    </dataHost>

</mycat:schema>

  

$ vim rule.xml

<tableRule name="rule1">
	<rule>
		<columns>id</columns>
		<algorithm>partbylong</algorithm>
	</rule>
</tableRule>
# 分片规则的意思就是,将1024分为2部分,每次存储时会生成一个小于1025的值 ,当这个值小于512时,将会存储在node1 上,大于512将会存在node2上
<function name="partbylong" class="org.opencloudb.route.function.PartitionByLong">
	<property name="partitionCount">2</property>
	<property name="partitionLength">512</property>
</function>

  

#配置对外的连接的数据库的用户名和密码
$ vim server.xml

<user name="zsxh">
	<property name="password">123456</property>
	<property name="schemas">db_zsxh_bm</property>
</user>

  

$ vim sequence_db_conf.properties

ACTIVESLAVE=dn1
ACTIVEMASTER=dn1
SUCCESSCONTENT=dn1
ACTIVEMANAGEER=dn1
ACTIVITY=dn1
ADMIN=dn1
BILLRECORD=dn1
CERTIFI=dn1
DICT=dn1
DIYFORM=dn1
SYSLOG=dn1
SUBMANAGER=dn1
WEBMAPPING=dn1
CAPTCHA=dn1

  

-- 在node1的MariaDB数据库中的db_zsxh_bm数据库中执行以下代码
CREATE TABLE MYCAT_SEQUENCE (
NAME VARCHAR (50) NOT NULL,
current_value INT NOT NULL,
increment INT NOT NULL DEFAULT 100,
remark varchar(200),
PRIMARY KEY (NAME)
) ENGINE = INNODB;

INSERT INTO MYCAT_SEQUENCE(name,current_value,increment,remark) VALUES (‘ACTIVESLAVE‘, 1, 100,‘match:tb_active_record_cluster‘);
INSERT INTO MYCAT_SEQUENCE(name,current_value,increment,remark) VALUES (‘ACTIVEMASTER‘, 1, 100,‘match:tb_active_record_master‘);
INSERT INTO MYCAT_SEQUENCE(name,current_value,increment,remark) VALUES (‘SUCCESSCONTENT‘, 1, 100,‘match:tb_success_content‘);
INSERT INTO MYCAT_SEQUENCE(name,current_value,increment,remark) VALUES (‘ACTIVEMANAGEER‘, 1, 100,‘match:tb_active_manager‘);
INSERT INTO MYCAT_SEQUENCE(name,current_value,increment,remark) VALUES (‘ACTIVITY‘, 1, 100,‘match:tb_activity‘);
INSERT INTO MYCAT_SEQUENCE(name,current_value,increment,remark) VALUES (‘BILLRECORD‘, 1, 100,‘match:tb_bill_record‘);
INSERT INTO MYCAT_SEQUENCE(name,current_value,increment,remark) VALUES (‘CERTIFI‘, 1, 100,‘match:tb_certification_body‘);
INSERT INTO MYCAT_SEQUENCE(name,current_value,increment,remark) VALUES (‘DICT‘, 1, 100,‘match:tb_dic‘);
INSERT INTO MYCAT_SEQUENCE(name,current_value,increment,remark) VALUES (‘DIYFORM‘, 1, 100,‘match:tb_diy_form‘);
INSERT INTO MYCAT_SEQUENCE(name,current_value,increment,remark) VALUES (‘SYSLOG‘, 1, 100,‘match:tb_log‘);
INSERT INTO MYCAT_SEQUENCE(name,current_value,increment,remark) VALUES (‘SUBMANAGER‘, 1, 100,‘match:tb_sub_manager_resource‘);
INSERT INTO MYCAT_SEQUENCE(name,current_value,increment,remark) VALUES (‘WEBMAPPING‘, 1, 100,‘match:tb_web_mapping‘);
INSERT INTO MYCAT_SEQUENCE(name,current_value,increment,remark) VALUES (‘ADMIN‘, 1, 100,‘match:tb_admin‘);
INSERT INTO MYCAT_SEQUENCE(name,current_value,increment,remark) VALUES (‘CAPTCHA‘, 1, 100,‘match:tb_captcha‘);

DROP FUNCTION IF EXISTS `mycat_seq_currval`;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `mycat_seq_currval`(seq_name VARCHAR(50)) RETURNS varchar(64) CHARSET latin1
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 ;

DROP FUNCTION IF EXISTS `mycat_seq_nextval`;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `mycat_seq_nextval`(seq_name VARCHAR(50)) RETURNS varchar(64) CHARSET latin1
DETERMINISTIC
BEGIN
UPDATE MYCAT_SEQUENCE
SET current_value = current_value + increment WHERE name = seq_name;
RETURN mycat_seq_currval(seq_name);
END
;;
DELIMITER ;

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 latin1
DETERMINISTIC
BEGIN
UPDATE MYCAT_SEQUENCE
SET current_value = value
WHERE name = seq_name;
RETURN mycat_seq_currval(seq_name);
END
;;
DELIMITER ;

  

土在在

标签:blog   _for   htm   long   password   count   cap   creat   bash   

原文地址:http://www.cnblogs.com/raphael5200/p/6088245.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!