Home >Database >Mysql Tutorial >高性能MySql进化论:提速Alter Table

高性能MySql进化论:提速Alter Table

WBOY
WBOYOriginal
2016-06-07 15:15:441259browse

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 在使用ALTER COLUMN mysql flush status; mysql alter table dictionary - alter column mean set default'DEFAULT2'; Query OK, 0 rowsaffected (0.03 sec) Records: 0 Duplicates: 0 Warnings: 0

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

 

  在使用ALTER COLUMN

  mysql> flush status;

  mysql> alter table dictionary

  -> alter column mean set default'DEFAULT2';

  Query OK, 0 rowsaffected (0.03 sec)

  Records: 0  Duplicates: 0 Warnings: 0

  mysql> SHOW STATUSWHERE Variable_name LIKE 'Handler%'

  -> OR Variable_name LIKE 'Created%';

  +----------------------------+-------+

  | Variable_name              | Value |

  +----------------------------+-------+

  |Handler_read_rnd_next      | 0     |

  |Handler_savepoint_rollback | 0     |

  | Handler_update             | 0     |

  | Handler_write              | 0     |

  2    修改frm文件

  通过修改frm文件的方式来提高修改表结构效率的步骤大概如下

  1.       备份相关的数据库文件

  2.       创建一张和旧表完全相同的表结构

  mysql>create table dictionary_new like dictionary;

  3.       执行FLUSH TABLES WITH READ LOCK. 所有的表都被关闭

  mysql> alter table dictionary_new

  -> modify column mean varchar(30)default 'DEFAULR#';

  mysql> flush table with read lock;

  5.       把dictionary_new.frm文件重名为dictionary.frm

  6.       执行UNLOCK TABLES

  mysql> unlock tables;

  mysql> insert into dictionary(word) values('Random');

  mysql> select * from dictionarywhere word='Random';

  从下面的结果可以看出,默认值已经被改掉,且不涉及到内容的改变

  +--------+--------+----------+

  | id     | word  | mean     |

  +--------+--------+----------+

  | 110004 |Random | DEFAULR# |

  +--------+--------+----------+

  7.        Drop dictionary_new

  [1] [2] 

高性能MySql进化论:提速Alter Table

Statement:
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