Category Archives: MySQL

Exporting query details to csv file

Founded somewhere in the net. Really useful.
From the Unix commandline (Bourne Shell compatible):

output tab-seperated:
echo “select * from example;” | mysql -u user -h host -ppass

Want another delimeter? Add
| tr ‘^V^I’ ‘;’
to the pipe and you will get csv or any other delimeter you want.

Skipping the first row (Table Header): add
| tail -n +2 [...]

Import data into table from a file

Very useful feature of mysql:
CREATE TEMPORARY TABLE table1(id int);
LOAD DATA LOCAL INFILE ‘/dir/file’ INTO TABLE table1