Import .csv file into MySQL database
I was implementing PhishTank database to one of my projects.
PhishTank is a service, operated by OpenDNS which updates a current list of phishing sites on the Internet.
When dealing with large number or requests it is advised that you download their hourly updated database dump.
I decided to grab the .csv dump and import it in my database using cron.
The heart of this cron is the following command which imports .csv data into local database
mysql -u$username -p$password -e \
"load \
data local
infile \
\"./verified_online.csv\" \
into table \
$database.$table \
fields terminated by \",\" \
enclosed by '\"' \
lines terminated by \"\n\" \
( \
phish_id, \
phish_detail_url, \
url, \
submission_time, \
verified, \
verification_time, \
online, \
target \
);"
Make sure that you already have the table created with following fields “phish_id, phish_detail_url, url, submission_time, verified, verification_time, online, target”
Comments Off