周末针对最新的项目需求进行cobar的搭建并针对实际状况做了demo演示
一、需求
1、大数据量,邮件发送记录需要记录,一年可能累计4亿的数据
2、需要按照邮箱进行邮件发送明细的查询以及发送记录的查询
二、问题
1、单库分表分区已经解决不了存储以及查询问题
2、只能进行一致性hash的策略进行数据存储以及查询,放弃了一些便利性查询统计
三、实施方案,数据库采用mysql,使用cobar针对分区库和主库进行整合
整合步骤如图,看不清可以下载附件看
四、相关配置文件以及工具文件如下
1、操作指南:edm-cobar操作指南.txt
1、mysql -h192.168.20.65 -uroot -p1q2w3e -P8066 2、show databases; 3、use edm; 4、show tables; note: 1、cobar server作为代理,安装在20.65上,并且以root/1q2w3e为口令,8066为服务端口提供了数据库代理服务 具体路径/usr/local/cobar*** 2、我们的数据库可以以这个代理服务器为访问端口,按照email这个字符串进行水平的hash路由到各个水平节点上 3、对于不需要水平拆分的表,我们也可以直接通过20.65提供的这个edm服务访问 warning: 1、直接用sqlyog软件访问这个代理数据库可能会报错,因为获取数据问题。不过我们可以直接通过cmd来查询。 2、我们的数据校验,可以通过直接访问各个节点进行数据校验
2、实施策略图片:EDM分布式数据库策略之Cobar.jpeg
3、cobar的相关配置文件:rule.xml,schema.xml,server.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- - Copyright 1999-2012 Alibaba Group. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --> <!DOCTYPE cobar:schema SYSTEM "schema.dtd"> <cobar:schema xmlns:cobar="http://cobar.alibaba.com/"> <!-- schema定义 --> <schema name="edm" dataNode="dnEdm"> <table name="email_info" dataNode="dn_shardx$0-7,dn_shardy$0-7" rule="email_rule" /> <table name="email_info_detail" dataNode="dn_shardx$0-7,dn_shardy$0-7" rule="email_rule" /> </schema> <!-- 数据节点定义,数据节点由数据源和其他一些参数组织而成。--> <dataNode name="dnEdm"> <property name="dataSource"> <dataSourceRef>db_edmx[0]</dataSourceRef> </property> </dataNode> <dataNode name="dn_shardx"> <property name="dataSource"> <dataSourceRef>db_edmx$1-8</dataSourceRef> </property> </dataNode> <dataNode name="dn_shardy"> <property name="dataSource"> <dataSourceRef>db_edmy$0-7</dataSourceRef> </property> </dataNode> <!-- 数据源定义,数据源是一个具体的后端数据连接的表示。--> <dataSource name="db_edmx" type="mysql"> <property name="location"> <!--edm 总库--> <location>192.168.20.182:3306/edm_hd</location> <location>192.168.20.182:3306/edmshard$1-8</location> </property> <property name="user">root</property> <property name="password">your_password</property> <property name="sqlMode">STRICT_TRANS_TABLES</property> </dataSource> <dataSource name="db_edmy" type="mysql"> <property name="location"> <location>192.168.119.158:3306/edmshard$9-16</location> </property> <property name="user">root</property> <property name="password">your_password</property> <property name="sqlMode">STRICT_TRANS_TABLES</property> </dataSource> </cobar:schema>
<!DOCTYPE cobar:rule SYSTEM "rule.dtd"> <cobar:rule xmlns:cobar="http://cobar.alibaba.com/"> <!-- 路由规则定义,定义什么表,什么字段,采用什么路由算法 --> <tableRule name="email_rule"> <rule> <columns>email</columns> <algorithm><![CDATA[ efunc(${email}) ]]></algorithm> </rule> </tableRule> <!-- 路由函数定义 --> <function name="efunc" class="com.alibaba.cobar.route.function.PartitionByString"> <property name="partitionCount">16</property> <property name="partitionLength">64</property> </function> </cobar:rule>
<?xml version="1.0" encoding="UTF-8"?> <!-- - Copyright 1999-2012 Alibaba Group. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --> <!DOCTYPE cobar:server SYSTEM "server.dtd"> <cobar:server xmlns:cobar="http://cobar.alibaba.com/"> <!-- 系统参数定义,服务端口、管理端口,处理器个数、线程池等。 --> <!-- <system> <property name="serverPort">8066</property> <property name="managerPort">9066</property> <property name="initExecutor">16</property> <property name="timerExecutor">4</property> <property name="managerExecutor">4</property> <property name="processors">4</property> <property name="processorHandler">8</property> <property name="processorExecutor">8</property> <property name="clusterHeartbeatUser">_HEARTBEAT_USER_</property> <property name="clusterHeartbeatPass">_HEARTBEAT_PASS_</property> </system> --> <!-- 用户访问定义,用户名、密码、schema等信息。 --> <user name="root"> <property name="password">1q2w3e</property> <property name="schemas">edm</property> </user> <!-- <user name="root"> <property name="password"></property> </user> --> <!-- 集群列表定义,指定集群节点的主机和权重,用于集群间的心跳和客户端负载均衡。 --> <!-- <cluster> <node name="cobar1"> <property name="host">127.0.0.1</property> <property name="weight">1</property> </node> </cluster> --> <!-- 隔离区定义,可以限定某个主机上只允许某个用户登录。 --> <!-- <quarantine> <host name="1.2.3.4"> <property name="user">test</property> </host> </quarantine> --> </cobar:server>
4、测试数据文件:edm_demo.sql
use edm; /**=====================在cobar server的schema(edm)的root账号下,直接清理数据=============================**/ delete from edm_users; delete from email_info; delete from email_info_detail; /**======================在cobar server的schema(edm)的root账号下,直接写入非分区库edm_hd中的edm_users 100条数据============================**/ use edm; insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd0','[email protected]','psw0','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd1','[email protected]','psw1','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd2','[email protected]','psw2','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd3','[email protected]','psw3','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd4','[email protected]','psw4','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd5','[email protected]','psw5','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd6','[email protected]','psw6','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd7','[email protected]','psw7','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd8','[email protected]','psw8','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd9','[email protected]','psw9','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd10','[email protected]','psw10','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd11','[email protected]','psw11','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd12','[email protected]','psw12','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd13','[email protected]','psw13','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd14','[email protected]','psw14','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd15','[email protected]','psw15','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd16','[email protected]','psw16','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd17','[email protected]','psw17','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd18','[email protected]','psw18','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd19','[email protected]','psw19','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd20','[email protected]','psw20','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd21','[email protected]','psw21','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd22','[email protected]','psw22','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd23','[email protected]','psw23','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd24','[email protected]','psw24','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd25','[email protected]','psw25','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd26','[email protected]','psw26','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd27','[email protected]','psw27','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd28','[email protected]','psw28','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd29','[email protected]','psw29','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd30','[email protected]','psw30','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd31','[email protected]','psw31','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd32','[email protected]','psw32','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd33','[email protected]','psw33','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd34','[email protected]','psw34','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd35','[email protected]','psw35','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd36','[email protected]','psw36','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd37','[email protected]','psw37','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd38','[email protected]','psw38','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd39','[email protected]','psw39','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd40','[email protected]','psw40','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd41','[email protected]','psw41','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd42','[email protected]','psw42','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd43','[email protected]','psw43','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd44','[email protected]','psw44','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd45','[email protected]','psw45','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd46','[email protected]','psw46','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd47','[email protected]','psw47','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd48','[email protected]','psw48','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd49','[email protected]','psw49','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd50','[email protected]','psw50','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd51','[email protected]','psw51','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd52','[email protected]','psw52','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd53','[email protected]','psw53','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd54','[email protected]','psw54','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd55','[email protected]','psw55','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd56','[email protected]','psw56','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd57','[email protected]','psw57','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd58','[email protected]','psw58','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd59','[email protected]','psw59','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd60','[email protected]','psw60','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd61','[email protected]','psw61','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd62','[email protected]','psw62','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd63','[email protected]','psw63','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd64','[email protected]','psw64','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd65','[email protected]','psw65','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd66','[email protected]','psw66','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd67','[email protected]','psw67','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd68','[email protected]','psw68','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd69','[email protected]','psw69','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd70','[email protected]','psw70','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd71','[email protected]','psw71','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd72','[email protected]','psw72','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd73','[email protected]','psw73','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd74','[email protected]','psw74','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd75','[email protected]','psw75','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd76','[email protected]','psw76','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd77','[email protected]','psw77','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd78','[email protected]','psw78','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd79','[email protected]','psw79','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd80','[email protected]','psw80','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd81','[email protected]','psw81','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd82','[email protected]','psw82','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd83','[email protected]','psw83','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd84','[email protected]','psw84','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd85','[email protected]','psw85','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd86','[email protected]','psw86','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd87','[email protected]','psw87','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd88','[email protected]','psw88','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd89','[email protected]','psw89','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd90','[email protected]','psw90','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd91','[email protected]','psw91','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd92','[email protected]','psw92','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd93','[email protected]','psw93','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd94','[email protected]','psw94','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd95','[email protected]','psw95','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd96','[email protected]','psw96','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd97','[email protected]','psw97','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd98','[email protected]','psw98','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); insert into edm_users(name,email,password,grouptype,dateline) values ('edm_hd99','[email protected]','psw99','1',UNIX_TIMESTAMP(CURRENT_TIMESTAMP)); /**=====================在cobar server的schema(edm)的root账号下,向水平分区的email_info写入100条数据=============================**/ insert into email_info(email,num,note) values ('[email protected]',0,'aa'); insert into email_info(email,num,note) values ('[email protected]',1,'aa'); insert into email_info(email,num,note) values ('[email protected]',2,'aa'); insert into email_info(email,num,note) values ('[email protected]',3,'aa'); insert into email_info(email,num,note) values ('[email protected]',4,'aa'); insert into email_info(email,num,note) values ('[email protected]',5,'aa'); insert into email_info(email,num,note) values ('[email protected]',6,'aa'); insert into email_info(email,num,note) values ('[email protected]',7,'aa'); insert into email_info(email,num,note) values ('[email protected]',8,'aa'); insert into email_info(email,num,note) values ('[email protected]',9,'aa'); insert into email_info(email,num,note) values ('[email protected]',10,'aa'); insert into email_info(email,num,note) values ('[email protected]',11,'aa'); insert into email_info(email,num,note) values ('[email protected]',12,'aa'); insert into email_info(email,num,note) values ('[email protected]',13,'aa'); insert into email_info(email,num,note) values ('[email protected]',14,'aa'); insert into email_info(email,num,note) values ('[email protected]',15,'aa'); insert into email_info(email,num,note) values ('[email protected]',16,'aa'); insert into email_info(email,num,note) values ('[email protected]',17,'aa'); insert into email_info(email,num,note) values ('[email protected]',18,'aa'); insert into email_info(email,num,note) values ('[email protected]',19,'aa'); insert into email_info(email,num,note) values ('[email protected]',20,'aa'); insert into email_info(email,num,note) values ('[email protected]',21,'aa'); insert into email_info(email,num,note) values ('[email protected]',22,'aa'); insert into email_info(email,num,note) values ('[email protected]',23,'aa'); insert into email_info(email,num,note) values ('[email protected]',24,'aa'); insert into email_info(email,num,note) values ('[email protected]',25,'aa'); insert into email_info(email,num,note) values ('[email protected]',26,'aa'); insert into email_info(email,num,note) values ('[email protected]',27,'aa'); insert into email_info(email,num,note) values ('[email protected]',28,'aa'); insert into email_info(email,num,note) values ('[email protected]',29,'aa'); insert into email_info(email,num,note) values ('[email protected]',30,'aa'); insert into email_info(email,num,note) values ('[email protected]',31,'aa'); insert into email_info(email,num,note) values ('[email protected]',32,'aa'); insert into email_info(email,num,note) values ('[email protected]',33,'aa'); insert into email_info(email,num,note) values ('[email protected]',34,'aa'); insert into email_info(email,num,note) values ('[email protected]',35,'aa'); insert into email_info(email,num,note) values ('[email protected]',36,'aa'); insert into email_info(email,num,note) values ('[email protected]',37,'aa'); insert into email_info(email,num,note) values ('[email protected]',38,'aa'); insert into email_info(email,num,note) values ('[email protected]',39,'aa'); insert into email_info(email,num,note) values ('[email protected]',40,'aa'); insert into email_info(email,num,note) values ('[email protected]',41,'aa'); insert into email_info(email,num,note) values ('[email protected]',42,'aa'); insert into email_info(email,num,note) values ('[email protected]',43,'aa'); insert into email_info(email,num,note) values ('[email protected]',44,'aa'); insert into email_info(email,num,note) values ('[email protected]',45,'aa'); insert into email_info(email,num,note) values ('[email protected]',46,'aa'); insert into email_info(email,num,note) values ('[email protected]',47,'aa'); insert into email_info(email,num,note) values ('[email protected]',48,'aa'); insert into email_info(email,num,note) values ('[email protected]',49,'aa'); insert into email_info(email,num,note) values ('[email protected]',50,'aa'); insert into email_info(email,num,note) values ('[email protected]',51,'aa'); insert into email_info(email,num,note) values ('[email protected]',52,'aa'); insert into email_info(email,num,note) values ('[email protected]',53,'aa'); insert into email_info(email,num,note) values ('[email protected]',54,'aa'); insert into email_info(email,num,note) values ('[email protected]',55,'aa'); insert into email_info(email,num,note) values ('[email protected]',56,'aa'); insert into email_info(email,num,note) values ('[email protected]',57,'aa'); insert into email_info(email,num,note) values ('[email protected]',58,'aa'); insert into email_info(email,num,note) values ('[email protected]',59,'aa'); insert into email_info(email,num,note) values ('[email protected]',60,'aa'); insert into email_info(email,num,note) values ('[email protected]',61,'aa'); insert into email_info(email,num,note) values ('[email protected]',62,'aa'); insert into email_info(email,num,note) values ('[email protected]',63,'aa'); insert into email_info(email,num,note) values ('[email protected]',64,'aa'); insert into email_info(email,num,note) values ('[email protected]',65,'aa'); insert into email_info(email,num,note) values ('[email protected]',66,'aa'); insert into email_info(email,num,note) values ('[email protected]',67,'aa'); insert into email_info(email,num,note) values ('[email protected]',68,'aa'); insert into email_info(email,num,note) values ('[email protected]',69,'aa'); insert into email_info(email,num,note) values ('[email protected]',70,'aa'); insert into email_info(email,num,note) values ('[email protected]',71,'aa'); insert into email_info(email,num,note) values ('[email protected]',72,'aa'); insert into email_info(email,num,note) values ('[email protected]',73,'aa'); insert into email_info(email,num,note) values ('[email protected]',74,'aa'); insert into email_info(email,num,note) values ('[email protected]',75,'aa'); insert into email_info(email,num,note) values ('[email protected]',76,'aa'); insert into email_info(email,num,note) values ('[email protected]',77,'aa'); insert into email_info(email,num,note) values ('[email protected]',78,'aa'); insert into email_info(email,num,note) values ('[email protected]',79,'aa'); insert into email_info(email,num,note) values ('[email protected]',80,'aa'); insert into email_info(email,num,note) values ('[email protected]',81,'aa'); insert into email_info(email,num,note) values ('[email protected]',82,'aa'); insert into email_info(email,num,note) values ('[email protected]',83,'aa'); insert into email_info(email,num,note) values ('[email protected]',84,'aa'); insert into email_info(email,num,note) values ('[email protected]',85,'aa'); insert into email_info(email,num,note) values ('[email protected]',86,'aa'); insert into email_info(email,num,note) values ('[email protected]',87,'aa'); insert into email_info(email,num,note) values ('[email protected]',88,'aa'); insert into email_info(email,num,note) values ('[email protected]',89,'aa'); insert into email_info(email,num,note) values ('[email protected]',90,'aa'); insert into email_info(email,num,note) values ('[email protected]',91,'aa'); insert into email_info(email,num,note) values ('[email protected]',92,'aa'); insert into email_info(email,num,note) values ('[email protected]',93,'aa'); insert into email_info(email,num,note) values ('[email protected]',94,'aa'); insert into email_info(email,num,note) values ('[email protected]',95,'aa'); insert into email_info(email,num,note) values ('[email protected]',96,'aa'); insert into email_info(email,num,note) values ('[email protected]',97,'aa'); insert into email_info(email,num,note) values ('[email protected]',98,'aa'); insert into email_info(email,num,note) values ('[email protected]',99,'aa'); /**====================在cobar server的schema(edm)的root账号下,对水平分区库email_info_detail写入100条数 据==============================**/ insert into email_info_detail(email,num_a,num_b) values ('[email protected]',0,0); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',1,-1); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',2,-2); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',3,-3); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',4,-4); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',5,-5); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',6,-6); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',7,-7); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',8,-8); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',9,-9); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',10,-10); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',11,-11); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',12,-12); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',13,-13); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',14,-14); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',15,-15); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',16,-16); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',17,-17); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',18,-18); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',19,-19); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',20,-20); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',21,-21); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',22,-22); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',23,-23); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',24,-24); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',25,-25); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',26,-26); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',27,-27); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',28,-28); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',29,-29); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',30,-30); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',31,-31); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',32,-32); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',33,-33); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',34,-34); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',35,-35); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',36,-36); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',37,-37); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',38,-38); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',39,-39); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',40,-40); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',41,-41); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',42,-42); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',43,-43); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',44,-44); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',45,-45); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',46,-46); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',47,-47); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',48,-48); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',49,-49); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',50,-50); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',51,-51); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',52,-52); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',53,-53); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',54,-54); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',55,-55); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',56,-56); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',57,-57); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',58,-58); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',59,-59); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',60,-60); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',61,-61); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',62,-62); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',63,-63); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',64,-64); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',65,-65); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',66,-66); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',67,-67); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',68,-68); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',69,-69); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',70,-70); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',71,-71); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',72,-72); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',73,-73); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',74,-74); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',75,-75); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',76,-76); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',77,-77); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',78,-78); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',79,-79); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',80,-80); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',81,-81); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',82,-82); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',83,-83); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',84,-84); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',85,-85); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',86,-86); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',87,-87); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',88,-88); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',89,-89); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',90,-90); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',91,-91); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',92,-92); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',93,-93); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',94,-94); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',95,-95); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',96,-96); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',97,-97); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',98,-98); insert into email_info_detail(email,num_a,num_b) values ('[email protected]',99,-99); /**======================在cobar server的schema(edm)的root账号下,直接修改水平分区表email_info数据============================**/ update email_info ei set ei.num=88888, ei.create_time=now() where ei.email='[email protected]'; update email_info ei set ei.num=88888, ei.create_time=now() where ei.email='[email protected]'; update email_info ei set ei.num=88888, ei.create_time=now() where ei.email='[email protected]'; update email_info ei set ei.num=88888, ei.create_time=now() where ei.email='[email protected]'; update email_info ei set ei.num=88888, ei.create_time=now() where ei.email='[email protected]'; update email_info ei set ei.num=88888, ei.create_time=now() where ei.email='[email protected]'; update email_info ei set ei.num=88888, ei.create_time=now() where ei.email='[email protected]'; update email_info ei set ei.num=88888, ei.create_time=now() where ei.email='[email protected]'; update email_info ei set ei.num=88888, ei.create_time=now() where ei.email='[email protected]'; update email_info ei set ei.num=88888, ei.create_time=now() where ei.email='[email protected]'; update email_info ei set ei.num=88888, ei.create_time=now() where ei.email='[email protected]'; update email_info ei set ei.num=88888, ei.create_time=now() where ei.email='[email protected]'; update email_info ei set ei.num=88888, ei.create_time=now() where ei.email='[email protected]'; update email_info ei set ei.num=88888, ei.create_time=now() where ei.email='[email protected]'; update email_info ei set ei.num=88888, ei.create_time=now() where ei.email='[email protected]'; /**=======================在cobar server的schema(edm)的root账号下,直接修改水平分区表email_info_detail数据===========================**/ update email_info_detail eid set eid.num_a=88888, eid.create_time=now() where eid.email='[email protected]'; update email_info_detail eid set eid.num_a=88888, eid.create_time=now() where eid.email='[email protected]'; update email_info_detail eid set eid.num_a=88888, eid.create_time=now() where eid.email='[email protected]'; update email_info_detail eid set eid.num_a=88888, eid.create_time=now() where eid.email='[email protected]'; update email_info_detail eid set eid.num_a=88888, eid.create_time=now() where eid.email='[email protected]'; update email_info_detail eid set eid.num_a=88888, eid.create_time=now() where eid.email='[email protected]'; update email_info_detail eid set eid.num_a=88888, eid.create_time=now() where eid.email='[email protected]'; update email_info_detail eid set eid.num_a=88888, eid.create_time=now() where eid.email='[email protected]'; update email_info_detail eid set eid.num_a=88888, eid.create_time=now() where eid.email='[email protected]'; update email_info_detail eid set eid.num_a=88888, eid.create_time=now() where eid.email='[email protected]'; update email_info_detail eid set eid.num_a=88888, eid.create_time=now() where eid.email='[email protected]'; update email_info_detail eid set eid.num_a=88888, eid.create_time=now() where eid.email='[email protected]'; update email_info_detail eid set eid.num_a=88888, eid.create_time=now() where eid.email='[email protected]'; update email_info_detail eid set eid.num_a=88888, eid.create_time=now() where eid.email='[email protected]'; update email_info_detail eid set eid.num_a=88888, eid.create_time=now() where eid.email='[email protected]'; /**=====================创建演示分区数据库,注意不要放到一个数据库上=============================**/ create database if not exists `edmshard1`; USE `edmshard1`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/ create database if not exists `edmshard2`; USE `edmshard2`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/ create database if not exists `edmshard3`; USE `edmshard3`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/ create database if not exists `edmshard4`; USE `edmshard4`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/ create database if not exists `edmshard5`; USE `edmshard5`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/ create database if not exists `edmshard6`; USE `edmshard6`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/ create database if not exists `edmshard7`; USE `edmshard7`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/ create database if not exists `edmshard8`; USE `edmshard8`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/ create database if not exists `edmshard9`; USE `edmshard9`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/ create database if not exists `edmshard10`; USE `edmshard10`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/ create database if not exists `edmshard11`; USE `edmshard11`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/ create database if not exists `edmshard12`; USE `edmshard12`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/ create database if not exists `edmshard13`; USE `edmshard13`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/ create database if not exists `edmshard14`; USE `edmshard14`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/ create database if not exists `edmshard15`; USE `edmshard15`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/ create database if not exists `edmshard16`; USE `edmshard16`; DROP TABLE IF EXISTS `email_info`; CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `email_info_detail`; CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /**==================================================**/
5、生成测试sql的java类:GenShardSql.java 你可以自己生成测试数据以及测试库了
package com.gen.sql; public class GenShardSql { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //通过cobar进行数据展示 String a="use edm;"; System.out.println(a); System.out.println("/**==================================================**/"); GenShardSql gss=new GenShardSql(); //清理主库以及分区库 gss.clearDate(); System.out.println("/**==================================================**/"); //给主库增加数据 gss.println_edm_hd(100); System.out.println("/**==================================================**/"); //给分区库增加数据 gss.println_email_info(100); System.out.println("/**==================================================**/"); gss.println_email_info_detail(100); System.out.println("/**==================================================**/"); //修改数据 gss.modifyEmailData(1, 16, 88888); //初始化分区库 gss.initdb(1, 16); } public void clearDate(){ //清理主库 String del="delete from edm_users;"; System.out.println(del); //清理分区库 del="delete from email_info;"; System.out.println(del); //清理分区库 del="delete from email_info_detail;"; System.out.println(del); } public void println_email_info(int num){ String a=""; for(int i=0;i<num;i++){ a="insert into email_info(email,num,note) values (\'hdedm"+i+"@hc360.com\',"+i+",\'aa\');"; System.out.println(a); } } public void println_email_info_detail(int num){ String b=""; for(int i=0;i<num;i++){ b="insert into email_info_detail(email,num_a,num_b) values ('hdedm"+i+"@hc360.com',"+i+","+-i+");"; System.out.println(b); } } public void println_edm_hd(int num){ String a="use edm;"; System.out.println(a); String b=""; for(int i=0;i<num;i++){ b="insert into edm_users(name,email,password,grouptype,dateline) values (\'edm_hd"+i+"\',\'edm_hd"+i+"@hc360.com\',\'psw"+i+"\',\'1\',UNIX_TIMESTAMP(CURRENT_TIMESTAMP));"; System.out.println(b); } } /**初始化分区DB*/ public void initdb(int start,int end){ for(int i=start;i<=end;i++){ String create="create database if not exists `edmshard"+i+"`;"; String use="USE `edmshard"+i+"`;"; String drop1="DROP TABLE IF EXISTS `email_info`;"; String c_t1="CREATE TABLE `email_info` ( `email` varchar(300) CHARACTER SET utf8 DEFAULT NULL, `num` int(10) DEFAULT NULL, `note` varchar(500) CHARACTER SET utf8 DEFAULT NULL,`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; String drop2="DROP TABLE IF EXISTS `email_info_detail`;"; String c_t2="CREATE TABLE `email_info_detail` ( `email` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL, `num_a` int(10) DEFAULT 0, `num_b` int(10) DEFAULT 0, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; System.out.println(create); System.out.println(use); System.out.println(drop1); System.out.println(c_t1); System.out.println(drop2); System.out.println(c_t2); System.out.println("/**==================================================**/"); } } /** * 根据邮箱更改某个分区的数据 * */ public void modifyEmailData(int start,int end,int val){ String ms=""; for(int i=start;i<end;i++){ ms="update email_info ei set ei.num="+val+", ei.create_time=now() where ei.email=\'hdedm"+i+"@hc360.com\';"; System.out.println(ms); } System.out.println("/**==================================================**/"); for(int i=start;i<end;i++){ ms="update email_info_detail eid set eid.num_a="+val+", eid.create_time=now() where eid.email=\'hdedm"+i+"@hc360.com\';"; System.out.println(ms); } System.out.println("/**==================================================**/"); } }