惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 大侠(cer)

阿里巴巴又抄袭创业公司产品,这次已被告上法庭(一) 手机app传统邀请码安装与免邀请码安装区别,如何选择呢? 好用的一些开源系统 一个搞笑的招聘启事 java和android及IOS对接RSA加密经验 android开发中监控android软件网络请求的软件Charles使用入门 android IOC框架学习记录 java分布式事务 android开发时使用游标时一定要关闭 今天发现ConcurrentHashMap的key是不区分大小写的 js方法isNaN使用时注意,“1.”这样子的东西他也会认为是数字 - 大侠(cer) 使用nginx+lua实现web项目的灰度发布 nginx增加lua支持 两台机器使用rsync同步数据(手工执行命令同步)(使用推的方式) 在ubuntu使用基于l2tp的VPN设置(支持硬件key的哦) - 大侠(cer) ubuntu服务器配制jmagick环境 windows中架设基于Apache的svn服务器 amoeba学习 CentOS安装thrift
mysql大数据表改表结构方案
大侠(cer) · 2014-02-11 · via 博客园 - 大侠(cer)

有一个表有上千W数据, 用什么方法给这个表加一个字段最快?
1. alert
2. 建一个表和第一个表一样,只是多了要加的字段,然后用多个INSERT INTO SELECT语句limit写入
3. 就是导出多个文件,然后用loadfile
4. 其它?

试过2.5KW数据, alert要156m。
INSERT INTO SELECT 100W要5m46s

两个工具选择:

http://www.percona.com/software/percona-toolkit

http://www.percona.com/doc/percona-toolkit/2.2/pt-online-schema-change.html

第二个工具是比较好的选择,可以线上改表结构,试试再给报告给大家

正在使用第二个工具,也就是"Facebook 针对 MySQL 开源 Online Schema Change 代码" 

参考文档:

http://blog.chinaunix.net/uid-53720-id-3371360.html

http://blog.csdn.net/dbanote/article/details/18261377

参数中文说明:

http://www.cnblogs.com/zhoujinyi/p/3491059.html

正在测试环境测试,测试数据量大约是2500W左右,随后有测试报告,没什么问题就上生产环境了

 pt-online-schema-change --alter "ADD category tinyint(4) NOT NULL DEFAULT '0'" D=库名,t=表名 -uroot -p密码 --dry-run

 如果你的库有主从结构,执行上面的语句遇到如下问题:

Cannot connect to D=calsync,h=从库的IP,p=...,u=root
No slaves found. See --recursion-method if host localhost.localdomain has slaves.
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.

请在从库上建一个root帐号且密码和上面的密码一样,且主库机可以访问

如果出现如下内容:

Found 1 slaves:
localhost.localdomain
Will check slave lag on:
localhost.localdomain

恭喜主从的没有问题了

测试数据如下:

数据量:3.1KW行记录

执行时间:

情况比较曲折,多次出现锁死退出的情况,最后停机且去掉一个索引,用时4个小时完成

mysql 5.1之前版本改表字段名,和建索引都要建临时表,会很慢

 mysql 5.1修改表字段名会重建临时表来做事情,建索引不会建临时表

mysql 5.6修改表字段名也不会临时表