› 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
fanyingmao
V2EX  ›  MySQL

mysql 如何给几千万表添加字段

  •  
  •   fanyingmao · Jun 13, 2023 · 2986 views
    This topic created in 1202 days ago, the information mentioned may be changed or developed.
    条数一多,加字段就要好久,有没什么简单方法,还是可以让运维处理。
    9 replies  •  2023-09-17 20:52:08 +08:00
    opengps
        1
    opengps  
       Jun 13, 2023   ❤️ 1
    优先考虑下扩展表之类的方案,单独加一个新的表,用逻辑外键的思路去补充需要额外保存的信息列
    fanyingmao
        2
    fanyingmao  
    OP
       Jun 13, 2023
    @opengps 扩展表的缺点就是就是,数据库要多插一次,还有多了些字段,不过也可以吧。这次估计还要多备几个字段预防后面业务变化了。
    ljsh093
        3
    ljsh093  
       Jun 13, 2023
    预留一个 text 列以 json 形式存取
    JinTianYi456
        4
    JinTianYi456  
       Jun 13, 2023
    @fanyingmao #2 `多备几个字段` 列转行,考虑不?这样基本无字段问题了
    rootx
        5
    rootx  
       Jun 13, 2023
    阿里云的不锁表方案 是新建一个表 然后复制数据 最后再用 binlog 同步一下 最后切换 收费 12 块钱一天
    brader
        6
    brader  
       Jun 13, 2023
    我在生产中实际使用的主要有两种方案:
    方案一:选择在业务低峰期加字段,代价是某些模块接受短暂时间的无法写入。
    方案二:复制一个新表,新表加新字段,然后把旧表数据插入新表,插入完之后,rename 两个表
    OpenSea
        7
    OpenSea  
       Jun 13, 2023
    1.新建 table-copy ,增加字段
    2.rename origin table to old-table
    3.rename table-copy to origin table
    4.insert into origin table select * from old table
    SpMozzi
        8
    SpMozzi  
       Jun 13, 2023   ❤️ 3
    市面上有 2 个开源的工具都可以做到 Online DDL
    1. percona 开源工具 pt-online-schema-change
    2. github 上 gh-ost
    dw2693734d
        9
    dw2693734d  
       Sep 17, 2023
    postgresql 的优越性就在这里体现出来了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2322 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 16:08 · PVG 00:08 · LAX 09:08 · JFK 12:08
    ♥ Do have faith in what you're doing.