[root@localhost tsmis3003-sp1-base-20120924]# vi update.sql 
use test;
drop procedure if exists 3003_base1_20120924_update_table_file;
DELIMITER ;;
CREATE  PROCEDURE `3003_base1_20120924_update_table_file`()
BEGIN
if not exists(select 1 from information_schema.COLUMNS where TABLE_SCHEMA='test' and table_name='SystemConfig' and COLUMN_NAME='TrafficLigh
tFrequency') then
alter table SystemConfig  add column TrafficLightFrequency  tinyint(3) default 2;
end if;
if not exists(select 1 from information_schema.COLUMNS where TABLE_SCHEMA='test' and table_name='BaseConfig' and COLUMN_NAME='DistOfOverSto
pline') then
alter table BaseConfig add column DistOfOverStopline int(10) default 0;
end if;
IF  EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='test' AND table_name='VersionInfo' AND COLUMN_NAME='verDB') then
insert into VersionInfo(verTSMIS,verDB) values('TSMISV3.0.0.3','3.0.0.5');
End IF;
END;;
DELIMITER ;
call  3003_base1_20120924_update_table_file();
DROP   PROCEDURE   IF   EXISTS   `test`.`3003_base1_20120924_update_table_file`;

 

然后写一个升级脚本,只要一句

mysql -u root test<update.sql 

就搞定了,

这样做的好处是可以避免重复升级导致mysql报字段冲突的错误。 

posted on 2012-09-28 17:15  蚂蚁跳楼  阅读(1264)  评论(0编辑  收藏  举报