shell脚本执行SQL

1.执行运行SQL命令:

#!/bin/sh
mysql -h10.10.10.10 -uroot -p123456 -e”
USE sunriver;
set sql_safe_updates = 0;
update ods_data_build set data = 804 where BLOCK_CODE=’P035-F01-YT09-03-B001′ and `index1` = “已签约套数”;
commit;
— delete from ods_data_build where block_code in (“P035-F01-YT08-02-B001”) and `index1` = “预售节点实际完成时间”;
— commit;
— insert into ods_data_build values(“P035″,”合肥金港湾”,”P035-F01″,”金港湾全期”,”P035-F01-YT08-02-B001″,”S1栋”,”YT08.YT08-02″,”商业-商业街”,”预售节点实际完成时间”,20201231.0000,1,1,”2021-01-28″,”2021-01-28″);
— commit;

delete from ods_data_build where BLOCK_CODE=”P013-F02-YT07-01-B000031″ and `index1` in (“预售节点实际完成时间”,”开盘节点实际完成时间”);
update ods_data_build set data=15657.8900 where BLOCK_CODE=”P013-F02-YT07-01-B00003″ and `index1`=”总面积”;
update ods_data_build set data=71916800.0000 where BLOCK_CODE=”P013-F02-YT07-01-B00003″ and `index1`=”已开盘未认购金额”;
update ods_data_build set data=6537.89 where BLOCK_CODE=”P013-F02-YT07-01-B00003″ and `index1`=”已开盘未认购面积”;
commit;

ALTER TABLE ods_data_build
CHANGE COLUMN \`index\` \`index1\` VARCHAR(255) NULL DEFAULT NULL ;

ps: 如果字段中有关键字: 需要用 \ 反编译,保证 `字段名`  不会报错

​​​​​​​

2.调用SQL文本

shell脚本:

1

2

3

#!/bin/sh

mysql -h10.253.29.10 -uroot -p密码 -e”source /opt/rh/test.sql”

SQL文件:

use middle_base;

insert into mysqlt values(‘1′,’cs’);

commit;

把SQL文件要上传到shell运行所对应的 服务器上,然后修改下 shell命令最后一个 文件路径

    原文作者:hzp666
    原文地址: https://blog.csdn.net/hzp666/article/details/121794722
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞