shell脚本写csv文件进mysql

代码实现

#!/bin/bash

# 设置MySQL连接参数
MYSQL_USER="root"
MYSQL_PASSWORD="password"
MYSQL_HOST="mysql"
MYSQL_DATABASE="finance"

echo "insert begin"
for arg in "$@"
do
        mysql --user=${MYSQL_USER} --password=${MYSQL_PASSWORD} --host=${MYSQL_HOST} ${MYSQL_DATABASE} << EOF

        LOAD DATA LOCAL INFILE '$arg'
        INTO TABLE test_table
        FIELDS TERMINATED BY ','
        ENCLOSED BY '"'
        LINES TERMINATED BY '\n'
        IGNORE 1 ROWS;
EOF
        echo "$arg insert success"
        #rm -rf $arg
        #echo "delete file $arg success"
done

你可能感兴趣的:(linux,mysql,android,数据库)