I am trying to output an SQL request into a CSV file but I can’t add two options that will help me to set it up. Here is the part of the request that works well:
mysql --host=localhost --user=root --password=pass --quick -e 'SELECT * FROM DB.TABLE' > '/stupidpath withaspace/stuff/myrep/export.csv'
I would like to add those two options to this request, but there something with the quote I don’t get:
FIELDS TERMINATED BY ','
and
ENCLOSED BY '"'
How can I integrate this?
Probably the easiest way is to put your exporting SQL in a separate file and then feed that into
mysql. The SQL file,exporter.sql, would look like this:And then run it with:
Putting the SQL in a separate file avoids the usual escaping and quoting problems of trying to send quotes into something from the shell.