Current location - Training Enrollment Network - Books and materials - How to import the contents of multiple txt files in a folder into mysql database tables
How to import the contents of multiple txt files in a folder into mysql database tables
1, example of load data statement

Mysql & gt uses db1;

Mysql & gt loads the data in the file' datafile.txt' into the table db2.table _ name.

or

Mysql & gt loads the data in the file' datafile.txt' into table db2.table_name, and the fields end with',', which can be enclosed by' "';

or

Mysql & gt loads the data in the file "file.txt" into the table_name field terminated by' \t' (sid, name);

2.mysqlimport command

Mysqlimport can automatically generate a LOAD DATA statement and load the data in the filename.txt file into the table_name table.

For example:

MySQL import-L-u root-proot db 0 1 table _ name . txt;

MySQL import- local table name filename.txt

3. Multiple txt files can be looped in a shell.

#! /bin/sh

Used to find files in. -type f -name "*. txt " `; do

MySQL import-L-u root-PP password db 0 1 $ { file };

finished