如何循环浏览目录中的文件(它们都是csv文件),然后使用登录mysql mysql -u root
(为了简单起见没有密码)并将它们全部添加到mysql表中?这是将文件快速加载到mysql的查询:
LOAD DATA LOCAL INFILE "C:/prog/mydb_load_Cards_chunks.dump" INTO TABLE vcc2.tmp_cards CHARACTER SET latin1
FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES;
如何在登录mysql时对目录中的每个文件执行此操作?
1条答案
按热度按时间envsm3lx1#
尝试:
文件:
load_csv.sh (-r-x------ user user load_csv.sh*)
```!/bin/bash
for current_csv in *.csv
do
mysql --login-path=myconnection -e "USE test" -e "
LOAD DATA LOCAL INFILE '$current_csv'
INTO TABLE temp_table
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(DATE, TIME);"
done
文件:
1.csv
```DATE,TIME
"2003-01-01","23:00:00"
"2004-01-01","00:00:00"
"2005-01-01","12:00:00"
mysql命令行: