汇聚多个SQL文件成一个SQL文件

目的

汇聚多个SQL文件到一个SQL文件,导入数据库

背景

工作需要从mysql数据库迁移数据到类mysql数据库中,迁移数据只能用执行语句。
通过datagrip 导出mysql插入数据,导出数据是按照每张表用一个sql文件进行存放,需要进行insert 语句汇总。
方便数据的迁移。

使用

demo.sh 内容如下

#!/usr/bin/env bash

fromPath=$1
destFile=~/out.sql

function SQLFileToDest() {
    cat $1 | while read line
    do
      # shellcheck disable=SC1073
      echo $line
      if [[ $line == INSERT* ]]; then
          echo $line >> $destFile
      fi

    done
}

function scanPath() {
    cd $fromPath
    for file in `find  $PWD `
    do
      if [ "${file##*.}"x = "sql"x ] ;then
        SQLFileToDest $file
        fi

      done

}

scanPath fromPath

执行

## shellin为sql文件列表存放的路径, 生成的数据存放在~/out.sql
./demo.sh ~/shellin
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值