使用mysql alter命令可能导致数据丢失?

时间:2011-07-15 15:07:35

标签: mysql

虽然我不认为数据丢失是可能的,但我想仔细检查以下查询是否会导致数据丢失。我正在添加索引并增加varchar长度。

ALTER TABLE  `phppos_sales` ADD  `deleted` INT( 1 ) NOT NULL DEFAULT  '0';
ALTER TABLE  `phppos_items` ADD INDEX (  `name` );
ALTER TABLE  `phppos_items` ADD INDEX (  `category` );
ALTER TABLE  `phppos_items` ADD INDEX (  `deleted` );
ALTER TABLE  `phppos_customers` ADD INDEX (  `deleted` );
ALTER TABLE  `phppos_employees` ADD INDEX (  `deleted` );
ALTER TABLE  `phppos_giftcards` ADD INDEX (  `deleted` );
ALTER TABLE  `phppos_item_kits` ADD INDEX (  `name` );
ALTER TABLE  `phppos_people` ADD INDEX (  `first_name` );
ALTER TABLE  `phppos_people` ADD INDEX (  `last_name` );
ALTER TABLE  `phppos_people` ADD INDEX (  `email` );
ALTER TABLE  `phppos_sales` ADD INDEX (  `deleted` );
ALTER TABLE  `phppos_suppliers` ADD INDEX (  `deleted` );
ALTER TABLE  `phppos_receivings` CHANGE  `payment_type`  `payment_type` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL;
ALTER TABLE  `phppos_receivings_items` CHANGE  `description`  `description` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL;
ALTER TABLE  `phppos_receivings_items` CHANGE  `serialnumber`  `serialnumber` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL;
ALTER TABLE  `phppos_sales` CHANGE  `payment_type`  `payment_type` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL;
ALTER TABLE  `phppos_sales_suspended` CHANGE  `payment_type`  `payment_type` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL;
ALTER TABLE  `phppos_giftcards` CHANGE  `giftcard_number`  `giftcard_number` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;
ALTER TABLE  `phppos_sales_items` CHANGE  `description`  `description` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL;
ALTER TABLE  `phppos_sales_items` CHANGE  `serialnumber`  `serialnumber` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL;
ALTER TABLE  `phppos_sales_suspended_items` CHANGE  `description`  `description` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL;
ALTER TABLE  `phppos_sales_suspended_items` CHANGE  `serialnumber`  `serialnumber` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL;
ALTER TABLE  `phppos_sales_suspended_payments` CHANGE  `payment_type`  `payment_type` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL;
ALTER TABLE  `phppos_sales_payments` CHANGE  `payment_type`  `payment_type` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL;

1 个答案:

答案 0 :(得分:1)

在任何情况下,您都应该比较操作之前和之后的数据。

更改前mysqldump --extended-insert=FALSE ... > old.sql,更改后> new.sql,然后diff -u old.sql new.sql | less确认。

需要extended-insert=FALSE部分将每个表格行放在单独的行中,以便更轻松diff