1. Create a new table (using the structure of the current table) with the new column(s) included.
  2. execute a INSERT INTO new_table SELECT (column1,..columnN) FROM current_table;
  3. rename the current table
  4. rename the new table using the name of the current table.

1. CREATE TABLE new_table LIKE table;

2. INSERT INTO new_table SELECT * FROM table;

3&4. RENAME TABLE table = old_table, table = new_table;

The usual trick for loading MyISAM table efficiently is to disable keys, load the data and renalbe the keys:

mysql> ALTER TABLE test.load_data DISABLE KEYS;
-- load data
mysql> ALTER TABLE test.load_data ENABLE KEYS;
dropped all indexes -- then added the field and recreate indexes

REF:

http://stackoverflow.com/questions/5677932/optimize-mysql-for-faster-alter-table-add-column

http://dba.stackexchange.com/questions/9746/mysql-fastest-way-to-alter-table-for-innodb

http://dba.stackexchange.com/questions/134269/fastest-way-to-add-new-column-in-mysql

faster alter table add column的更多相关文章

  1. [Hive - LanguageManual] Alter Table/Partition/Column

    Alter Table/Partition/Column Alter Table Rename Table Alter Table Properties Alter Table Comment Add ...

  2. 【待整理】MySQL alter table modify vs alter table add产生state不一样

    MySQL:5.6.35 OS:redhat5.8 今天更新数据库某些表字段,有如下两SQL: ①alter table xx modify xxxx;(表大概是77w) ②alter table s ...

  3. Spark 2.x不支持ALTER TABLE ADD COLUMNS,没关系,我们改进下

    SparkSQL从2.0开始已经不再支持ALTER TABLE table_name ADD COLUMNS (col_name data_type [COMMENT col_comment], .. ...

  4. 自己动手为Spark 2.x添加ALTER TABLE ADD COLUMNS语法支持

    SparkSQL从2.0开始已经不再支持ALTER TABLE table_name ADD COLUMNS (col_name data_type [COMMENT col_comment], .. ...

  5. create index 与 alter table add index 区别

    众所周知,MySQL创建索引有两种语法,即:ALTER TABLE HeadOfState ADD INDEX (LastName, FirstName);CREATE INDEX index_nam ...

  6. alter table add constraint 用法

    1.主键约束: 要对一个列加主键约束的话,这列就必须要满足的条件就是分空 因为主键约束:就是对一个列进行了约束,约束为(非空.不重复) 以下是代码   要对一个列加主键,列名为id,表名为emp 格式 ...

  7. Oracle alter table modify column Syntax example

    http://www.dba-oracle.com/t_alter_table_modify_column_syntax_example.htm For complete tips on Oracle ...

  8. alter table *** add constraint *** 用法---约束

    1.主键约束:要对一个列加主键约束的话,这列就必须要满足的条件就是分空因为主键约束:就是对一个列进行了约束,约束为(非空.不重复)以下是代码   要对一个列加主键,列名为id,表名为emp 格式为:a ...

  9. SQL SERVER删除列,报错."由于一个或多个对象访问此列,ALTER TABLE DROP COLUMN ... 失败"

    队友给我修改数据的语句.总是执行失败.很纳闷. 如下图: 仔细看了下这个列,并没有什么特殊.如下图: 但其确实有个约束: 'DF__HIS_DRUG___ALL_I__04E4BC85' . 为什么有 ...

随机推荐

  1. JavaAnnotation和反射简化开发

    Part I 我并不是在卖弄自己的英语有多少的了不起,只不过对Annotation这一次的解释真的很懊恼,“注解”和“注释”这两个对Annotation的翻译我听着不爽,所以全文都用Annotatio ...

  2. Android课程---视图组件总结

  3. 【转】Linux安装方法一(U盘引导)

    Ubuntu 13.04正式版已经在4月25日发布了,相信很多人和我一样很想安装体验一下,但是现在的Ubuntu 13.04文件已经是794M,但是很难刻录到一张CD中,所以采用U盘启动安装Ubunt ...

  4. asp.net identity 2.2.0 中角色启用和基本使用(七)提示点

    在使用asp.net identity 2.2.0 中,大家可能设计到一些修改和配置 关于Identity的配置,在App_Start文件中的IdentityConfig.cs中,这里几乎有你需要的一 ...

  5. Java简单类(部门、领导、雇员关系)

    class Dept { private int deptno ; private String dname ; private String loc ; private Emp emps [] ; ...

  6. windows下安装 sphinx 数据库全文搜索引擎

    此次演示的环境是:win7系统,64位,php5.4.x,apache sphinx,斯芬克斯(英语不好的同学可以直接读这个音),意狮身人面像 特点:创建索引速度快,3分钟左右能创建100万条记录的索 ...

  7. How to generate ssh key only for github and not conflict with original key

    3 生成SSH公钥 $ ssh-keygen -t rsa -C "your_email@youremail.com"  #ssh-keygen -t dsa -C "y ...

  8. Spring mvc 下Ajax获取JSON对象问题 406错误

    我在学习springmvc过程中(我的项目是配置的后缀是.html),从controller返回对象. 如果我不使用 mvc-annotation-driver,而是手动配置,AnnotationMe ...

  9. MVC 发布

    发布为局域网可用:以IP地址访问 安装IIS 发布 出现的错误: 处理程序"BlockViewHandler"在其模块列表中有一个错误模块"ManagedPipeline ...

  10. RDIFramework.NET ━ .NET快速信息化系统开发框架 V2.8 版本━新增岗位管理-WinForm部分

    RDIFramework.NET ━ .NET快速信息化系统开发框架 V2.8 版本 新增岗位管理-WinForm部分 岗位(职位)管理模块主要是针对组织机构的岗位(职位)进行管理,包括:增加.修改. ...