背景:
从DW那边拿到一个9kw行记录的数据库primary_key的csv文件,需要导入到mysql中,然后由业务上通过程序去进行消费及一系列的下游业务逻辑的处理。
目前难点在于如果把这个9kw的大的csv导入到数据库中,如果使用load data这种方式,势必会比较慢,因为load data这是单线程操作。
比较好的思路是先将这个大的csv文件拆分成N个小的csv文件,然后开多个screen去并发往数据库里面导入。
将大的csv拆分为N个小的csv,推荐使用下面的方法:
unzip -p <zipfile> | split -C <size> --additional-suffix=".csv"
类似如下:
# root @ dev-ops in /tmp/aa [21:37:35]
$ cat README.md | split -C 1000 --additional-suffix=".csv"
# root @ dev-ops in /tmp/aa [21:37:40]
$ l
total 20K
-rw-r--r-- 1 root root 3.7K 2021-08-10 21:35 README.md
-rw-r--r-- 1 root root 770 2021-08-10 21:37 xad.csv
-rw-r--r-- 1 root root 965 2021-08-10 21:37 xac.csv
-rw-r--r-- 1 root root 981 2021-08-10 21:37 xab.csv
-rw-r--r-- 1 root root 977 2021-08-10 21:37 xaa.csv
然后开多个screen ,使用 load data infile 方式导入到mysql中。 达到提速的目的。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有