在使用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










