当前位置:网站首页>批量执行SQL文件
批量执行SQL文件
2022-06-26 08:21:00 【风碎峰】
一.功能
匹配处理数据库的命令,可用于批量数据迁移和导入。
二.操作步骤
step1.生成需要执行的SQL文件
生成需要执行的sql文件(每行一个sql命令)。示例如下:
delete from lbs_poi where poiid=1000052855 limit 1;
delete from lbs_poi where poiid=1000052856 limit 1;
delete from lbs_poi where poiid=1000052857 limit 1;
delete from lbs_poi where poiid=1000052858 limit 1;
delete from lbs_poi where poiid=1000052859 limit 1;
step2.将原始sql文件按照固定行数拆分
jar包存放位置:10.74.28.129 /data1/bingqing/shAndJar/splitFile.jar splitFile.jar
上面目录是笔者操作的机器,处于公司内网中,如果没有连接内网,请参考者先进入内网。
执行jar包查看jar调用说明:
/data1/bingqing/shAndJar # java -jar splitFile.jar
split file with fixed lineNum
paras: inputFilePath encode fileLineNum
sample: java -jar splitFile.jar poiToDeleteSql.sql utf8 1000
根据说明,将目标sql文件拆分成多个子文件。
step3.人工监控执行有停顿的脚本
shell脚本存放位置:10.74.28.129 /data1/bingqing/shAndJar/sleepSql.sh
脚本内容:
/data1/bingqing/shAndJar # cat sleepSql.sh
#!/bin/sh
echo '------------------------' >> deletelog.txt
current=`date "+%Y-%m-%d %H:%M:%S"`
#echo $current
echo $current >> deletelog.txt
#mysql -uLBQ -pPSBPkJaHX6aTeWEOds -hm4000i.randa.grid.sina.com.cn --default-character-set=utf8 -P4000 LBQ < poiToDeleteSqlAll2.sql
for i in {3001..10000};
do
#echo $i
echo $i >> deletelog.txt
mysql -uLBQ -pPSBPkJaHX6aTeWEOds -hm5000i.randa.grid.sina.com.cn --default-character-set=utf8 -P4000 LBQ < poiToDeleteSqlAll${i}.sql
current=`date "+%Y-%m-%d %H:%M:%S"`
#echo $current
echo $current >> deletelog.txt
sleep 3s
done
echo 'over!' >> deletelog.txt
注:
1.mysql -uLBQ -pPSBPkJaHX6aTeWEOds -hm4000i.randa.grid.sina.com.cn --default-character-set=utf8 -P4000 LBQ < poiToDeleteSqlAll${i}.sql
这是数据库的连接串儿,参数解析如下:
-uLBQ 指定用户名(有时候也习惯采用数据库们或者部门名称)
-pPSBPkJaHX6aTeWEOds 密码
-hm4000i.randa.grid.sina.com.cn 连接对象或者连接目标,这个参数包含了主机名,端口,目标库的模式是主库还是从库,与jdbc中的MySQL连接配置异曲同工。其中hm表名连接的是主库,如果是hs则为从库;4000为端口号;后缀为主机名称(内网有配置,直接使用域名)
--default-character-set=utf8 指定编码格式,防止操作过程产生乱码问题
-P4000 指定端口
LBQ 指定数据库
边栏推荐
- How to debug plug-ins using vs Code
- Discrete device ~ resistance capacitance
- Use a switch to control the lighting and extinguishing of LEP lamp
- 2020-10-20
- Uni app is similar to Taobao in selecting multiple specifications of commodities (inventory judgment)
- Apple motherboard decoding chip, lightning Apple motherboard decoding I.C
- Getting started with idea
- Wifi-802.11 2.4G band 5g band channel frequency allocation table
- Idea uses regular expressions for global substitution
- HEVC学习之码流分析
猜你喜欢
X-VLM多模态模型解读
Example of offset voltage of operational amplifier
MySQL practice: 4 Operation of data
Uploading pictures with FileReader object
Rewrite string() method in go language
Automatic backup of MySQL database in the early morning with Linux
Read excel table and render with FileReader object
Real machine debugging of uniapp custom base
Pychart connects to Damon database
Chapter 4 (functions and preprocessing)
随机推荐
Blue Bridge Cup 3 sequence summation
Interpretation of x-vlm multimodal model
SOC wireless charging scheme
SOC的多核启动流程详解
Mapping '/var/mobile/Library/Caches/com.apple.keyboards/images/tmp.gcyBAl37' failed: 'Invalid argume
Vs2019-mfc setting edit control and static text font size
Uniapp scrolling load (one page, multiple lists)
Pic 10B parsing
Microcontroller from entry to advanced
Baoyan postgraduate entrance examination interview - operating system
optee中支持的时间函数
Area of Blue Bridge Cup 2 circle
drf的相关知识
How to debug plug-ins using vs Code
2020-10-29
Timer code guide in optee
Interview JS and browser
Win11 open folder Caton solution summary
Flume learning notes
Learning signal integrity from scratch (SIPI) -- 3 challenges faced by Si and Si based design methods