MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
simple2025
0D
V2EX  ›  MySQL

关于 mysql 冷热数据分离的问题,你们是用开源脚本,还是自己撸代码

  •  
  •   simple2025 · Jun 16, 2017 · 5836 views
    This topic created in 3275 days ago, the information mentioned may be changed or developed.
    比如有一个张表,order 表一般查询的是最近 3 个月的记录,但是保留了 1 年的记录。
    现在我想把 order 表中创建时间是 3 个月之后的记录,导入到 old_order 表中。
    我自己想到的办法是撸代码,一条记录一条记录的复制过去,然后删队原始数据 。
    你们一般的做法是什么?
    
    12 replies    2017-06-16 18:03:51 +08:00
    nybux
        1
    nybux  
       Jun 16, 2017   ❤️ 1
    不用一条条吧,直接 where 一个时间条件,用 insert into ... select 就可以了
    U7Q5tLAex2FI0o0g
        2
    U7Q5tLAex2FI0o0g  
       Jun 16, 2017
    1 楼说的对
    simple2025
        3
    simple2025  
    OP
       Jun 16, 2017
    @nybux 但是这个样子会变成手动的对吧,我的想法是变成定时任务那样 ,每天跑一点,省得我每天手动去弄,有可能某天就出错了呢
    nybux
        4
    nybux  
       Jun 16, 2017
    写成脚本,然后由 crontab 去定时调用
    jianzhiyao020
        5
    jianzhiyao020  
       Jun 16, 2017
    可以这样子,
    按照时间分表,
    新表数据量少,
    建索引量少,
    插入、检索速度快。

    冷热可以这样区分。
    2ME
        6
    2ME  
       Jun 16, 2017   ❤️ 1
    同 1 楼 一样可以定时任务 where 条件的时间灵活一点就好了
    yanze0613
        7
    yanze0613  
       Jun 16, 2017   ❤️ 1
    insert into ... select,限制每次读取的行数 然后写进 crontab
    bk201
        8
    bk201  
       Jun 16, 2017   ❤️ 1
    你还不如 3 个月就换一次表名来得快捷
    U7Q5tLAex2FI0o0g
        9
    U7Q5tLAex2FI0o0g  
       Jun 16, 2017
    @bk201 #8 这就是你的错了,要换也是“每天”,不是“每 3 个月”
    snail00
        10
    snail00  
       Jun 16, 2017   ❤️ 1
    写个存储过程, 然后用 mysql 的事件去定时执行, 我现在就在撸这个.
    simple2025
        11
    simple2025  
    OP
       Jun 16, 2017
    @snail00 好吧,写存储过程,我宁愿撸代码
    noNOno
        12
    noNOno  
       Jun 16, 2017
    时间字段上建个聚集索引不行么
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3125 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 56ms · UTC 13:40 · PVG 21:40 · LAX 06:40 · JFK 09:40
    ♥ Do have faith in what you're doing.