[root@master shell]# cat test_sql.sh
#!/bin/bash
Date=`date +"%Y%m%d"`
#log the alter tableAlter_log=/home/shell/a.log#logthe import data
Import_log=/home/shell/output.log#theoption of the alter tableecho $Date>>$Alter_log
SQL="alter tableMI_Medicare_2018_INCR rename MI_Medicare_2018_INCR_${Date}"
Rename=$(mysql -uroot -p123456 CH_MedicareData -s -e "${SQL}")
Tablename=$(mysql -uroot -p123456 CH_MedicareData -s -e "descMI_Medicare_2018_INCR_${Date}")if [! -n "$Tablename"]; thenecho "the MI_Medicare_2018_INCR_${Date}is not existed" >>$Alter_logelseecho "the nameof the MI_Medicare_2018_INCR_${Date} has been changed" >>$Alter_log
fi
#option ofimport dataif [-d "/home/backup/MI_Medicare_2018_INCR_${Date}.sql"]; then
/usr/local/mysql/bin/mysql -uroot -p123456 CH_MedicareData
echo "the followingis the count of source data" >>$Alter_log/usr/local/mysql/bin/mysql -uroot -p123456 CH_MedicareData -e "select Max(Id),CreateDate fromMI_Medicare_2018"elseecho "thefile is not existed" >>$Alter_log
fi
echo "theoption is the FROM MI_Medicare_2018_INCR toMI_Medicare_2018"/usr/local/mysql/bin/mysql -uroot -p123456 <
tee/home/shell/output.logshow databases;useCH_MedicareData;select Max(Id),CreateDate fromMI_Medicare_2018;INSERT INTOMI_Medicare_2018
(INSName, BillNumber, TenBitBillNumber,HospitalCode,TherapyType,MZEnterDate,MZOutDate, MZDays,ZYEnterDate,
ZYOutDate,ZYDays,DiseaseDescription,BillAmount,OwnAmount, SubOwnAmount,PreAmount,ItemA31, ItemA32,
ItemA33,ItemA34,BBD001,BBD002,BBD003,BBD004,BBD005,BBD006,BBD007,BBD008,BBD009,BBD010,IDCardHashCode,CreateDate)SELECTINSName,BillNumber,TenBitBillNumber,HospitalCode,TherapyType, MZEnterDate, MZOutDate,MZDays,ZYEnterDate,
ZYOutDate,ZYDays,DiseaseDescription,BillAmount,OwnAmount,SubOwnAmount,PreAmount,ItemA31,ItemA32,
ItemA33,ItemA34,BBD001,BBD002,BBD003,BBD004,BBD005,BBD006,BBD007,BBD008,BBD009,BBD010,IDCardHashCode,CreateDateFROMMI_Medicare_2018_INCR;select Max(Id),CreateDate from MI_Medicare_2018 a,MI_Medicare_2018_INCR b where a.ID=b.Id and a.CreateDate>b.CreateDate;
notee
EOFexit