热门标签 | HotTags
当前位置:  开发笔记 > 后端 > 正文

Mycat(6):聊天消息表,按月分表java客户端跨月查询数据_MySQL

本文的原文连接是:http:blogcsdnnetfreewebsysarticledetails47039103未经博主允许不得转载。1,业务需求上次分析聊天业务按照月进行拆。http:blogcsdnnetfreewebsysarticledetails4700

1,业务需求

上次分析聊天业务按照月进行拆。
具体拆分方案已经有了:
\

但是在操作的时候还是有点小问题,但基本上是按照这个设计实现的。
首先是mycat的,mycat正式版本是1.3.0.3-release,但是这个不包括PartitionByMonth这个类,其次PartitionByMonth 这个类的输入参数是日期也不好按月进行分表。
还好这类可以转换月,不用修改代码,也可以将就着用。

打包PartitionByMonth这个类生成一个jar。这个类在1.4-rc包里面有。将新jar放到lib目录下面。

#打包类io.mycat.route.function.PartitionByMonth。
jar -cvf Mycat-server-PartitionByMonth.jar *

PartitionByMonth这个类非常简单,对比下日期然后返回分区的序号。
如果业务复杂不是一个月一个月的分区可以直接写死逻辑然后打包使用,比如按季度分区,半个月一分区,或者在2015-06月以前是一个表以后是按月分区等等。

public class PartitionByMonth  {
    private String sBeginDate;
    private String dateFormat;
    private Calendar beginDate;

    public void init() {
        try {
            beginDate = Calendar.getInstance();
            beginDate.setTime(new SimpleDateFormat(dateFormat)
                    .parse(sBeginDate));
        } catch (ParseException e) {
            throw new java.lang.IllegalArgumentException(e);
        }
    }
//通过时间计算返回分区号 0-n
    public Integer calculate(String columnValue) {
        try {
            Calendar curTime = Calendar.getInstance();
            curTime.setTime(new SimpleDateFormat(dateFormat).parse(columnValue));
            return (curTime.get(Calendar.YEAR) - beginDate.get(Calendar.YEAR))
                    * 12 + curTime.get(Calendar.MONTH)
                    - beginDate.get(Calendar.MONTH);

        } catch (ParseException e) {
            throw new java.lang.IllegalArgumentException(e);
        }
    }

2,mycat 配置

首先创建数据库,默认分4个表,所有创建4个数据库,同理可以直接创建好一年的12个表,这里只是举例子。

CREATE DATABASE msg_201501 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE msg_201502 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE msg_201503 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE msg_201504 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

在这4个数据库中创建表,表做10个分区(具体分区数可根据业务量划定,每个月的mysql分区可以不一样),按照gid做分区。

CREATE TABLE `msg` (
  `id` bigint(20) NOT NULL,
  `gid` bigint(20) DEFAULT NULL COMMENT '群id,mysql分区字段',
  `content` varchar(4000),
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `create_month` int(6) DEFAULT NULL COMMENT '按月分表字段,如201501,不能为空。',
  PRIMARY KEY (`id`,`gid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
PARTITION BY KEY(`gid`) 
PARTITIONS 10;

配置mycat 的rule.xml,这里用到了一个小技巧。month的格式化是




    

     
                create_month
                sharding-by-month 
        
        
                yyyyMM 
                201501
        

schema.xml配置:





        
            
        

        
        

        

        
                select 1
        
        
        

server.xml配置:




        
                druidparser
        
        
                msg
                msg
        

3,mysql 客户端测试

如果mycat启动正常,查看logs/wrapper.log没有异常,且数据库连接已经创建。

# mysql -umsg -pmsg -P8066 -h 127.0.0.1
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.8-mycat-1.3 MyCat Server (OpenCloundDB)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use msg;
mysql> 
mysql> insert into msg(`id`,`gid`,`content`,`create_time`,`create_month`) values(1,1,'java',now(),201501);
Query OK, 1 row affected (0.00 sec)

mysql> insert into msg(`id`,`gid`,`content`,`create_time`,`create_month`) values(2,1,'oracle',now(),201501);
Query OK, 1 row affected (0.01 sec)

mysql> insert into msg(`id`,`gid`,`content`,`create_time`,`create_month`) values(1,2,'ibm',now(),201501);
Query OK, 1 row affected (0.00 sec)

mysql> insert into msg(`id`,`gid`,`content`,`create_time`,`create_month`) values(2,2,'mysql',now(),201501);
Query OK, 1 row affected (0.00 sec)

mysql> 
mysql> insert into msg(`id`,`gid`,`content`,`create_time`,`create_month`) values(1,1,'zhangsan',now(),201502);
Query OK, 1 row affected (0.00 sec)

mysql> insert into msg(`id`,`gid`,`content`,`create_time`,`create_month`) values(1,1,'lisi',now(),201503);
Query OK, 1 row affected (0.01 sec)

mysql> insert into msg(`id`,`gid`,`content`,`create_time`,`create_month`) values(1,1,'wangwu',now(),201504);
Query OK, 1 row affected (0.00 sec)

mysql> select * from msg where gid = 1 and create_mOnth= 201501;
+----+-----+---------+---------------------+--------------+
| id | gid | content | create_time         | create_month |
+----+-----+---------+---------------------+--------------+
|  1 |   1 | java    | 2015-07-24 13:21:41 |       201501 |
|  2 |   1 | oracle  | 2015-07-24 13:21:41 |       201501 |
+----+-----+---------+---------------------+--------------+
2 rows in set (0.19 sec)

mysql> select * from msg where gid = 1 and create_mOnth= 201502;
+----+-----+----------+---------------------+--------------+
| id | gid | content  | create_time         | create_month |
+----+-----+----------+---------------------+--------------+
|  1 |   1 | zhangsan | 2015-07-24 13:21:42 |       201502 |
+----+-----+----------+---------------------+--------------+
1 row in set (0.00 sec)

mysql> select * from msg where gid = 1 and create_mOnth= 201503;
+----+-----+---------+---------------------+--------------+
| id | gid | content | create_time         | create_month |
+----+-----+---------+---------------------+--------------+
|  1 |   1 | lisi    | 2015-07-24 13:21:42 |       201503 |
+----+-----+---------+---------------------+--------------+
1 row in set (0.01 sec)

mysql> select * from msg where gid = 1 and create_mOnth= 201504;
+----+-----+---------+---------------------+--------------+
| id | gid | content | create_time         | create_month |
+----+-----+---------+---------------------+--------------+
|  1 |   1 | wangwu  | 2015-07-24 13:21:43 |       201504 |
+----+-----+---------+---------------------+--------------+
1 row in set (0.13 sec)

mysql> select * from msg where gid = 2 and create_mOnth= 201501;
+----+-----+---------+---------------------+--------------+
| id | gid | content | create_time         | create_month |
+----+-----+---------+---------------------+--------------+
|  1 |   2 | ibm     | 2015-07-24 13:21:41 |       201501 |
|  2 |   2 | mysql   | 2015-07-24 13:21:41 |       201501 |
+----+-----+---------+---------------------+--------------+
2 rows in set (0.01 sec)

4,java客户端调用测试


import java.sql.*;
import java.sql.Date;
import java.util.*;

public class MycatTest {

    private static Connection cOnnect= null;
    private static Statement statement = null;
    private static PreparedStatement preparedStatement = null;
    private static ResultSet resultSet = null;

    public static void init() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            cOnnect= DriverManager
                    .getConnection("jdbc:mysql://192.168.100.1:8066/msg", "msg", "msg");
            statement = connect.createStatement();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void close() {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
        } catch (Exception e) {
        }
        try {
            if (statement != null) {
                statement.close();
            }
        } catch (Exception e) {
        }
        try {
            if (connect != null) {
                connect.close();
            }
        } catch (Exception e) {
        }
    }

    public static void testInsert() {

        //实际当中i为gid的自增id。跨按月分区自增。
        for (int i = 1; i <100; i++) {
            try {
                //特意设置28循环周期。
                int j = (i / 28) + 1;
                preparedStatement = connect
                        .prepareStatement("insert into msg(`id`,`gid`,`content`,`create_time`,`create_month`) values(?,?,?,?,?)");
                //录入参数。
                preparedStatement.setInt(1, i);
                preparedStatement.setInt(2, 99);
                preparedStatement.setString(3, "test content " + i);
                //插入j时间
                preparedStatement.setDate(4, new java.sql.Date(2015, j - 1, i));
                //设置按月分区。
                preparedStatement.setInt(5, 201500 + j);
                preparedStatement.executeUpdate();

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    static class Msg {
        private int id;
        private int gid;
        private String content;
        private java.util.Date createTime;
        private int createMonth;

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public int getGid() {
            return gid;
        }

        public void setGid(int gid) {
            this.gid = gid;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.cOntent= content;
        }

        public java.util.Date getCreateTime() {
            return createTime;
        }

        public void setCreateTime(java.util.Date createTime) {
            this.createTime = createTime;
        }

        public int getCreateMonth() {
            return createMonth;
        }

        public void setCreateMonth(int createMonth) {
            this.createMOnth= createMonth;
        }

        @Override
        public String toString() {
            return "Msg{" +
                    "id=" + id +
                    ", gid=" + gid +
                    ", cOntent=&#39;" + content + &#39;\&#39;&#39; +
                    ", createTime=" + createTime +
                    ", createMOnth=" + createMonth +
                    &#39;}&#39;;
        }
    }

    public static List selectByGidMonth(int gid, int month, int id, int limit) {
        List list = new ArrayList();
        try {
            //如果id == 0就是按照id倒叙查询。
            if (id == 0) {
                String sql = "select `id`,`gid`,`content`,`create_time`,`create_month` from msg where gid = ? and create_mOnth= ? order by id desc limit ? ";
                preparedStatement = connect
                        .prepareStatement(sql);
                preparedStatement.setInt(1, gid);
                preparedStatement.setInt(2, month);
                preparedStatement.setInt(3, limit);
            } else {//
                String sql = "select `id`,`gid`,`content`,`create_time`,`create_month` from msg where gid = ? and create_mOnth= ? and id  1,且当月没有查询到数据,查询前一个月的数据,直到id = 1 为止。
            if (lastId > 1 && list.size() = 201501) {
                //剩余数据
                int remainSize = limit - list.size();
                //使用递归进行查询。month-1 是简单操作,实际应该用Date返回前一个月。
                List remainList = selectByGidMonth(gid, month - 1, lastId, remainSize);
                list.addAll(remainList);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    private static void testSelect() {
        //假设分页是20 条记录。
        int page = 20;
        int lastId = 0;

        List list = selectByGidMonth(99, 201504, lastId, page);

        for (Msg msg : list) {
            System.out.println(msg);
            lastId = msg.getId();
        }

        System.out.println("###########################");
        list = selectByGidMonth(99, 201503, lastId, page);

        for (Msg msg : list) {
            System.out.println(msg);
            lastId = msg.getId();
        }

        System.out.println("###########################");
        list = selectByGidMonth(99, 201503, lastId, page);

        for (Msg msg : list) {
            System.out.println(msg);
            lastId = msg.getId();
        }

        System.out.println("###########################");
        list = selectByGidMonth(99, 201502, lastId, page);

        for (Msg msg : list) {
            System.out.println(msg);
            lastId = msg.getId();
        }

        System.out.println("###########################");
        list = selectByGidMonth(99, 201501, lastId, page);

        for (Msg msg : list) {
            System.out.println(msg);
            lastId = msg.getId();
        }


    }

    public static void main(String[] args) {

        init();
        //testInsert();
        testSelect();
        close();
    }

}

java客户端调用说明,首先msg表的id是按照gid连续自增的,如果id > 1,且当月没有查询到数据,查询前一个月的数据,直到id = 1 为止。

            if (lastId > 1 && list.size() = 201501) {
//剩余数据
                int remainSize = limit - list.size();
                //使用递归进行查询。month-1 是简单操作,实际应该用Date返回前一个月。
                List remainList = selectByGidMonth(gid, month - 1, lastId, remainSize);
                list.addAll(remainList);
            }

使用递归函数往前一个月一个月查询数据,直到查询到id = 1 为止。查询结果如下,每次显示20条数据,插入的100 条 % 28 分别插入4个月数据。
查询结果可以跨月查询:

Msg{id=99, gid=99, cOntent=&#39;test content 99&#39;, createTime=3915-07-08, createMOnth=201504}
Msg{id=98, gid=99, cOntent=&#39;test content 98&#39;, createTime=3915-07-07, createMOnth=201504}
Msg{id=97, gid=99, cOntent=&#39;test content 97&#39;, createTime=3915-07-06, createMOnth=201504}
Msg{id=96, gid=99, cOntent=&#39;test content 96&#39;, createTime=3915-07-05, createMOnth=201504}
Msg{id=95, gid=99, cOntent=&#39;test content 95&#39;, createTime=3915-07-04, createMOnth=201504}
Msg{id=94, gid=99, cOntent=&#39;test content 94&#39;, createTime=3915-07-03, createMOnth=201504}
Msg{id=93, gid=99, cOntent=&#39;test content 93&#39;, createTime=3915-07-02, createMOnth=201504}
Msg{id=92, gid=99, cOntent=&#39;test content 92&#39;, createTime=3915-07-01, createMOnth=201504}
Msg{id=91, gid=99, cOntent=&#39;test content 91&#39;, createTime=3915-06-30, createMOnth=201504}
Msg{id=90, gid=99, cOntent=&#39;test content 90&#39;, createTime=3915-06-29, createMOnth=201504}
Msg{id=89, gid=99, cOntent=&#39;test content 89&#39;, createTime=3915-06-28, createMOnth=201504}
Msg{id=88, gid=99, cOntent=&#39;test content 88&#39;, createTime=3915-06-27, createMOnth=201504}
Msg{id=87, gid=99, cOntent=&#39;test content 87&#39;, createTime=3915-06-26, createMOnth=201504}
Msg{id=86, gid=99, cOntent=&#39;test content 86&#39;, createTime=3915-06-25, createMOnth=201504}
Msg{id=85, gid=99, cOntent=&#39;test content 85&#39;, createTime=3915-06-24, createMOnth=201504}
Msg{id=84, gid=99, cOntent=&#39;test content 84&#39;, createTime=3915-06-23, createMOnth=201504}
Msg{id=83, gid=99, cOntent=&#39;test content 83&#39;, createTime=3915-05-22, createMOnth=201503}
Msg{id=82, gid=99, cOntent=&#39;test content 82&#39;, createTime=3915-05-21, createMOnth=201503}
Msg{id=81, gid=99, cOntent=&#39;test content 81&#39;, createTime=3915-05-20, createMOnth=201503}
Msg{id=80, gid=99, cOntent=&#39;test content 80&#39;, createTime=3915-05-19, createMOnth=201503}
###########################
Msg{id=79, gid=99, cOntent=&#39;test content 79&#39;, createTime=3915-05-18, createMOnth=201503}
Msg{id=78, gid=99, cOntent=&#39;test content 78&#39;, createTime=3915-05-17, createMOnth=201503}
Msg{id=77, gid=99, cOntent=&#39;test content 77&#39;, createTime=3915-05-16, createMOnth=201503}
Msg{id=76, gid=99, cOntent=&#39;test content 76&#39;, createTime=3915-05-15, createMOnth=201503}
Msg{id=75, gid=99, cOntent=&#39;test content 75&#39;, createTime=3915-05-14, createMOnth=201503}
Msg{id=74, gid=99, cOntent=&#39;test content 74&#39;, createTime=3915-05-13, createMOnth=201503}
Msg{id=73, gid=99, cOntent=&#39;test content 73&#39;, createTime=3915-05-12, createMOnth=201503}
Msg{id=72, gid=99, cOntent=&#39;test content 72&#39;, createTime=3915-05-11, createMOnth=201503}
Msg{id=71, gid=99, cOntent=&#39;test content 71&#39;, createTime=3915-05-10, createMOnth=201503}
Msg{id=70, gid=99, cOntent=&#39;test content 70&#39;, createTime=3915-05-09, createMOnth=201503}
Msg{id=69, gid=99, cOntent=&#39;test content 69&#39;, createTime=3915-05-08, createMOnth=201503}
Msg{id=68, gid=99, cOntent=&#39;test content 68&#39;, createTime=3915-05-07, createMOnth=201503}
Msg{id=67, gid=99, cOntent=&#39;test content 67&#39;, createTime=3915-05-06, createMOnth=201503}
Msg{id=66, gid=99, cOntent=&#39;test content 66&#39;, createTime=3915-05-05, createMOnth=201503}
Msg{id=65, gid=99, cOntent=&#39;test content 65&#39;, createTime=3915-05-04, createMOnth=201503}
Msg{id=64, gid=99, cOntent=&#39;test content 64&#39;, createTime=3915-05-03, createMOnth=201503}
Msg{id=63, gid=99, cOntent=&#39;test content 63&#39;, createTime=3915-05-02, createMOnth=201503}
Msg{id=62, gid=99, cOntent=&#39;test content 62&#39;, createTime=3915-05-01, createMOnth=201503}
Msg{id=61, gid=99, cOntent=&#39;test content 61&#39;, createTime=3915-04-30, createMOnth=201503}
Msg{id=60, gid=99, cOntent=&#39;test content 60&#39;, createTime=3915-04-29, createMOnth=201503}
###########################
Msg{id=59, gid=99, cOntent=&#39;test content 59&#39;, createTime=3915-04-28, createMOnth=201503}
Msg{id=58, gid=99, cOntent=&#39;test content 58&#39;, createTime=3915-04-27, createMOnth=201503}
Msg{id=57, gid=99, cOntent=&#39;test content 57&#39;, createTime=3915-04-26, createMOnth=201503}
Msg{id=56, gid=99, cOntent=&#39;test content 56&#39;, createTime=3915-04-25, createMOnth=201503}
Msg{id=55, gid=99, cOntent=&#39;test content 55&#39;, createTime=3915-03-27, createMOnth=201502}
Msg{id=54, gid=99, cOntent=&#39;test content 54&#39;, createTime=3915-03-26, createMOnth=201502}
Msg{id=53, gid=99, cOntent=&#39;test content 53&#39;, createTime=3915-03-25, createMOnth=201502}
Msg{id=52, gid=99, cOntent=&#39;test content 52&#39;, createTime=3915-03-24, createMOnth=201502}
Msg{id=51, gid=99, cOntent=&#39;test content 51&#39;, createTime=3915-03-23, createMOnth=201502}
Msg{id=50, gid=99, cOntent=&#39;test content 50&#39;, createTime=3915-03-22, createMOnth=201502}
Msg{id=49, gid=99, cOntent=&#39;test content 49&#39;, createTime=3915-03-21, createMOnth=201502}
Msg{id=48, gid=99, cOntent=&#39;test content 48&#39;, createTime=3915-03-20, createMOnth=201502}
Msg{id=47, gid=99, cOntent=&#39;test content 47&#39;, createTime=3915-03-19, createMOnth=201502}
Msg{id=46, gid=99, cOntent=&#39;test content 46&#39;, createTime=3915-03-18, createMOnth=201502}
Msg{id=45, gid=99, cOntent=&#39;test content 45&#39;, createTime=3915-03-17, createMOnth=201502}
Msg{id=44, gid=99, cOntent=&#39;test content 44&#39;, createTime=3915-03-16, createMOnth=201502}
Msg{id=43, gid=99, cOntent=&#39;test content 43&#39;, createTime=3915-03-15, createMOnth=201502}
Msg{id=42, gid=99, cOntent=&#39;test content 42&#39;, createTime=3915-03-14, createMOnth=201502}
Msg{id=41, gid=99, cOntent=&#39;test content 41&#39;, createTime=3915-03-13, createMOnth=201502}
Msg{id=40, gid=99, cOntent=&#39;test content 40&#39;, createTime=3915-03-12, createMOnth=201502}
###########################
Msg{id=39, gid=99, cOntent=&#39;test content 39&#39;, createTime=3915-03-11, createMOnth=201502}
Msg{id=38, gid=99, cOntent=&#39;test content 38&#39;, createTime=3915-03-10, createMOnth=201502}
Msg{id=37, gid=99, cOntent=&#39;test content 37&#39;, createTime=3915-03-09, createMOnth=201502}
Msg{id=36, gid=99, cOntent=&#39;test content 36&#39;, createTime=3915-03-08, createMOnth=201502}
Msg{id=35, gid=99, cOntent=&#39;test content 35&#39;, createTime=3915-03-07, createMOnth=201502}
Msg{id=34, gid=99, cOntent=&#39;test content 34&#39;, createTime=3915-03-06, createMOnth=201502}
Msg{id=33, gid=99, cOntent=&#39;test content 33&#39;, createTime=3915-03-05, createMOnth=201502}
Msg{id=32, gid=99, cOntent=&#39;test content 32&#39;, createTime=3915-03-04, createMOnth=201502}
Msg{id=31, gid=99, cOntent=&#39;test content 31&#39;, createTime=3915-03-03, createMOnth=201502}
Msg{id=30, gid=99, cOntent=&#39;test content 30&#39;, createTime=3915-03-02, createMOnth=201502}
Msg{id=29, gid=99, cOntent=&#39;test content 29&#39;, createTime=3915-03-01, createMOnth=201502}
Msg{id=28, gid=99, cOntent=&#39;test content 28&#39;, createTime=3915-02-28, createMOnth=201502}
Msg{id=27, gid=99, cOntent=&#39;test content 27&#39;, createTime=3915-01-27, createMOnth=201501}
Msg{id=26, gid=99, cOntent=&#39;test content 26&#39;, createTime=3915-01-26, createMOnth=201501}
Msg{id=25, gid=99, cOntent=&#39;test content 25&#39;, createTime=3915-01-25, createMOnth=201501}
Msg{id=24, gid=99, cOntent=&#39;test content 24&#39;, createTime=3915-01-24, createMOnth=201501}
Msg{id=23, gid=99, cOntent=&#39;test content 23&#39;, createTime=3915-01-23, createMOnth=201501}
Msg{id=22, gid=99, cOntent=&#39;test content 22&#39;, createTime=3915-01-22, createMOnth=201501}
Msg{id=21, gid=99, cOntent=&#39;test content 21&#39;, createTime=3915-01-21, createMOnth=201501}
Msg{id=20, gid=99, cOntent=&#39;test content 20&#39;, createTime=3915-01-20, createMOnth=201501}
###########################
Msg{id=19, gid=99, cOntent=&#39;test content 19&#39;, createTime=3915-01-19, createMOnth=201501}
Msg{id=18, gid=99, cOntent=&#39;test content 18&#39;, createTime=3915-01-18, createMOnth=201501}
Msg{id=17, gid=99, cOntent=&#39;test content 17&#39;, createTime=3915-01-17, createMOnth=201501}
Msg{id=16, gid=99, cOntent=&#39;test content 16&#39;, createTime=3915-01-16, createMOnth=201501}
Msg{id=15, gid=99, cOntent=&#39;test content 15&#39;, createTime=3915-01-15, createMOnth=201501}
Msg{id=14, gid=99, cOntent=&#39;test content 14&#39;, createTime=3915-01-14, createMOnth=201501}
Msg{id=13, gid=99, cOntent=&#39;test content 13&#39;, createTime=3915-01-13, createMOnth=201501}
Msg{id=12, gid=99, cOntent=&#39;test content 12&#39;, createTime=3915-01-12, createMOnth=201501}
Msg{id=11, gid=99, cOntent=&#39;test content 11&#39;, createTime=3915-01-11, createMOnth=201501}
Msg{id=10, gid=99, cOntent=&#39;test content 10&#39;, createTime=3915-01-10, createMOnth=201501}
Msg{id=9, gid=99, cOntent=&#39;test content 9&#39;, createTime=3915-01-09, createMOnth=201501}
Msg{id=8, gid=99, cOntent=&#39;test content 8&#39;, createTime=3915-01-08, createMOnth=201501}
Msg{id=7, gid=99, cOntent=&#39;test content 7&#39;, createTime=3915-01-07, createMOnth=201501}
Msg{id=6, gid=99, cOntent=&#39;test content 6&#39;, createTime=3915-01-06, createMOnth=201501}
Msg{id=5, gid=99, cOntent=&#39;test content 5&#39;, createTime=3915-01-05, createMOnth=201501}
Msg{id=4, gid=99, cOntent=&#39;test content 4&#39;, createTime=3915-01-04, createMOnth=201501}
Msg{id=3, gid=99, cOntent=&#39;test content 3&#39;, createTime=3915-01-03, createMOnth=201501}
Msg{id=2, gid=99, cOntent=&#39;test content 2&#39;, createTime=3915-01-02, createMOnth=201501}
Msg{id=1, gid=99, cOntent=&#39;test content 1&#39;, createTime=3915-01-01, createMOnth=201501}

5,总结

mycat可以支持按月插入数据,但是查询起来要自己做好分月查询方案。
由于用户插入的数据有可能分散在多个月的数据表中,查询的时候需倒序一个月一个月的查询。
数据的存储可以按照年,500G数据放到一个磁盘,一年增加一个磁盘,新数据都写到新磁盘上面,保证数据随着时间增长只需要新增加数据库和磁盘即可,不需要进行数据迁移。


推荐阅读
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 推荐一个ASP的内容管理框架(ASP Nuke)的优势和适用场景
    本文推荐了一个ASP的内容管理框架ASP Nuke,并介绍了其主要功能和特点。ASP Nuke支持文章新闻管理、投票、论坛等主要内容,并可以自定义模块。最新版本为0.8,虽然目前仍处于Alpha状态,但作者表示会继续更新完善。文章还分析了使用ASP的原因,包括ASP相对较小、易于部署和较简单等优势,适用于建立门户、网站的组织和小公司等场景。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 本文介绍了如何在MySQL中将零值替换为先前的非零值的方法,包括使用内联查询和更新查询。同时还提供了选择正确值的方法。 ... [详细]
  • 在数据分析工作中,我们通常会遇到这样的问题,一个业务部门由若干业务组构成,需要筛选出每个业务组里业绩前N名的业务员。这其实是一个分组排序的 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • Oracle Database 10g许可授予信息及高级功能详解
    本文介绍了Oracle Database 10g许可授予信息及其中的高级功能,包括数据库优化数据包、SQL访问指导、SQL优化指导、SQL优化集和重组对象。同时提供了详细说明,指导用户在Oracle Database 10g中如何使用这些功能。 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 本文详细介绍了MysqlDump和mysqldump进行全库备份的相关知识,包括备份命令的使用方法、my.cnf配置文件的设置、binlog日志的位置指定、增量恢复的方式以及适用于innodb引擎和myisam引擎的备份方法。对于需要进行数据库备份的用户来说,本文提供了一些有价值的参考内容。 ... [详细]
  • 本文由编程笔记小编整理,介绍了PHP中的MySQL函数库及其常用函数,包括mysql_connect、mysql_error、mysql_select_db、mysql_query、mysql_affected_row、mysql_close等。希望对读者有一定的参考价值。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文介绍了通过mysql命令查看mysql的安装路径的方法,提供了相应的sql语句,并希望对读者有参考价值。 ... [详细]
  • 一、Hadoop来历Hadoop的思想来源于Google在做搜索引擎的时候出现一个很大的问题就是这么多网页我如何才能以最快的速度来搜索到,由于这个问题Google发明 ... [详细]
  • 本文详细介绍了SQL日志收缩的方法,包括截断日志和删除不需要的旧日志记录。通过备份日志和使用DBCC SHRINKFILE命令可以实现日志的收缩。同时,还介绍了截断日志的原理和注意事项,包括不能截断事务日志的活动部分和MinLSN的确定方法。通过本文的方法,可以有效减小逻辑日志的大小,提高数据库的性能。 ... [详细]
  • PHP设置MySQL字符集的方法及使用mysqli_set_charset函数
    本文介绍了PHP设置MySQL字符集的方法,详细介绍了使用mysqli_set_charset函数来规定与数据库服务器进行数据传送时要使用的字符集。通过示例代码演示了如何设置默认客户端字符集。 ... [详细]
author-avatar
瞄瞄摩卡李流
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有