#!/bin/bash
 
write_to_file()
{
    file="loaddata.sql"
 
    if [ ! -f "$file" ] ; then
        touch $file
    else
        rm -rf $file
        touch $file
    fi
	
	# 修改数据库名
    echo 'USE tpch_1t;' >> $file
    echo 'SET FOREIGN_KEY_CHECKS=0;' >> $file
 
    DIR=`pwd`
    for tbl in `ls *.tbl`; do
        table=$(echo "${tbl%.*}")
        echo "LOAD DATA LOCAL INFILE '$DIR/$tbl' INTO TABLE $table" >> $file
        echo "FIELDS TERMINATED BY '|' LINES TERMINATED BY '|\n';" >> $file
    done
    echo 'SET FOREIGN_KEY_CHECKS=1;' >> $file
 }
 
write_to_file