Home > Database > Mysql Tutorial > mysql大数据表改表结构方案_MySQL

mysql大数据表改表结构方案_MySQL

WBOY
Release: 2016-05-27 14:12:21
Original
1348 people have browsed it

bitsCN.com

有一个表有上千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

 

正在测试环境测试,测试数据量大约是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

恭喜主从的没有问题了

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template