Thursday, 12 July 2012

Export MySQL tables into CSV/PSV/TSV format


CSV:
mysql my_db -e "SELECT * FROM my_table" | sed 's/\t/","/g;s/^/"/;s/$/"/;' > my_db.my_table.csv
 
PSV:
mysql my_db -e "SELECT * FROM my_table" | sed 's/\t/|/g' > my_db.my_table.psv
 
TSV:
mysql my_db -e "SELECT * FROM my_table" > my_db.my_table.tsv 

No comments:

Post a Comment