How can I export csv from MySQL automatically?

Asked By 0 points N/A Posted on -
qa-featured

Hi,

I need your help. I'm facing problem to export csv from mysql automatically? How can I do it easily? What kind of software is better? Please inform me in details.

Thanks.

SHARE
Best Answer by Mclean Buono
Answered By 0 points N/A #150232

How can I export csv from MySQL automatically?

qa-featured

Hi Edward,

I will provide you a simple solution to this problem.

MySQL has more options for exporting data, one of them being “SELECT INTO OUTFILE” query.

This will export your results returned by your sql query into the CSV file specified by you.

Using this code:

SELECT * INTO OUTFILE '/tmp/your_file.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\' LINES TERMINATED BY 'n' FROM table_that_you_want

Please make sure that MySQL has write permission on “/tmp/” folder.

Happy coding.

Aabel

Best Answer
Best Answer
Answered By 10 points N/A #150233

How can I export csv from MySQL automatically?

qa-featured

Hi Edward,

It is even possible to export all tables from a database in a CSV file, you can use the mysqldump utility to do that.

This command will help

mysqldump – u [username] – p – t – T[/path/to/directory] [database] — fields – enclosed-by =" –fields-terminated – by =,

Replace [username] with the MySQL username

[/path/to/directory] with the path to the directory where data will exported to.

[database] the name of the database from which all tables will be exported.

  • T indicates create table statements will not be exported.
  • T will dump the data in tab delimited format,
  • Fields-terminated-by will change the delimiter from tab to comma

Please note due to presence of flag — fields-enclosed-by = " all column data will be enclosed with double quotes.

Hope this helps you.

Related Questions