I honestly do not know why somebody would want to export each
record from a table in to its’ own files in a csv format. I am
sure people have their own reasons. But since I got request from
couple people, I figure I would post a solution here. Same script
can be used to dump the whole table in to one csv file as well,
with little tweaking. I will start with creating database with a
table. I then insert three rows with test data into the table
just to show three separate files creation.
mysql> CREATE DATABASE testdump;
mysql> USE testdump
mysql> CREATE TABLE `testtable` (
`id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`testfield` VARCHAR( 15 ) NOT NULL ,
`testfield2` VARCHAR( 15 ) NOT NULL
) ENGINE = innodb COMMENT = 'test table for dumping each row to
file';
mysql> INSERT INTO `testtable` values
('','test1','test2'),('','test3','test4'),('','test5','test6'); …
[Read more]