HI guys
Here's an example of loading data from a text file into a mysql database.
This assumes your file is tab delimited, however you can change the SQL
command to incorporate different types of delimited text files:
Code: Select all
LOAD DATA INFILE '/tmp/add1.txt' IGNORE INTO
TABLE accounts FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'
(email, phone, address);
This add1.txt files is a tab delimited file containing email, phone,
and addresses. It is terminated by '\t" (tabs) and is newline
terminated "\n". The last part of the sql statement (email, phone,
address) maps the tab delimited file columns to columns in the database
table. Also, I use IGNORE to ignore duplicate entries on keys. You
could alternatively use REPLACE.
For more info, see the mysql LOAD DATA INFILE documentation!
thanks
---------------------
les metiers lies a la protection de l'environnement