mysql将csv格式的文件导入

#!/bin/bash
source ~/.bashrc
db='bfb_db_finance'
#tables=('t_rate_configure')
tables=('t_rate_configure' 't_cnt_for_cal_fee' 't_bank_rate_modify_log' 't_reserve_bank_account' 't_reserve_bank_account_channel' 't_reserve_bank_account_channel_
details' 't_reserve_bank_account_channel_files' 't_reserve_bank_account_channel_log' 't_outercheck_summary' 't_holiday_dates')
export_dir=~/tmp/script/data
echo 'start to export from fndb online...'
fndb_mine -e "create database if not exists bfb_db_finance;"
for tab in ${tables[@]}; do
 fndb_online -N -e "select * from ${db}.${tab}" > $export_dir"/"$tab &
 create_sql=`fndb_online -N -e "show create table ${db}.${tab}"`
 len=${#tab}
 create_sql=${create_sql:$len}
 echo -e "$create_sql" > $export_dir"/create_"$tab &
done;
wait
echo 'finished to export from fndb online.'
echo 'start to import to fndb offline...'
for tab in ${tables[@]}; do
 fndb_mine -e "drop table if exists ${db} . ${tab}"
 create_sql=`cat ${export_dir}/create_${tab}`
 fndb_mine -e "use ${db}; $create_sql"
 fndb_mine -N -e "truncate ${db} . ${tab}; LOAD DATA LOCAL INFILE '$export_dir/$tab' INTO TABLE ${db} . ${tab}"
 wait
 echo ${tab}" done."
 rm $export_dir"/"$tab &
 rm $export_dir/"create_"$tab &
done;
echo 'done.'
此条目发表在 mysql 分类目录。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*


*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>