How can I export csv from MySQL automatically?
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.
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.
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
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.
Please note due to presence of flag — fields-enclosed-by = " all column data will be enclosed with double quotes.
Hope this helps you.