XML to tab separated for MySQL import

Written by Peter Davies on .

This is a simple perl script used for XML to TSV (tab separated) allowing fast MySQL import through the MySQL load data infile approach. For large datasets you can import very quickly using this technique.

Then using a shell script you can import the data in to MySQL by executing the command:

mysql -e "LOAD DATA INFILE 'listing.tsv' INTO TABLE table_name" database_name

OR possibly depending on the purpose something a little more complicated that dumps the table first using the mysqlimport command:

mysqlimport --lines-terminated-by='\n' --local-infile --delete -h localhost -u user_name -ppassword database_name /home/dev/scripts/listings.tsv