{"id":471,"date":"2018-08-01T11:01:46","date_gmt":"2018-08-01T18:01:46","guid":{"rendered":"http:\/\/www.brightbill.net\/notes\/?p=471"},"modified":"2018-12-20T16:08:27","modified_gmt":"2018-12-21T00:08:27","slug":"dumping-a-sql-query-into-a-csv-file-in-mysql","status":"publish","type":"post","link":"https:\/\/www.brightbill.net\/notes\/2018\/08\/dumping-a-sql-query-into-a-csv-file-in-mysql\/","title":{"rendered":"Dumping a SQL query into a CSV file in MySQL"},"content":{"rendered":"<p>Yet another note to myself&#8230;<\/p>\n<pre>SELECT order_id,product_name,qty \nFROM orders\nINTO OUTFILE '\/tmp\/orders.csv'\nFIELDS TERMINATED BY ','\nENCLOSED BY '\"'\nLINES TERMINATED BY '\\n'<\/pre>\n<p>Credit to <a href=\"http:\/\/www.tech-recipes.com\/rx\/1475\/save-mysql-query-results-into-a-text-or-csv-file\/\">http:\/\/www.tech-recipes.com\/rx\/1475\/save-mysql-query-results-into-a-text-or-csv-file\/<\/a><\/p>\n<p>(Since this apparently doesn&#8217;t work with one of the versions of MySQL I use, the following can be used from the operating system command line:)<\/p>\n<pre>mysql -p -u username databasename &lt; query.sql &gt; results.txt<\/pre>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yet another note to myself&#8230; SELECT order_id,product_name,qty FROM orders INTO OUTFILE &#8216;\/tmp\/orders.csv&#8217; FIELDS TERMINATED BY &#8216;,&#8217; ENCLOSED BY &#8216;&#8221;&#8216; LINES TERMINATED BY &#8216;\\n&#8217; Credit to http:\/\/www.tech-recipes.com\/rx\/1475\/save-mysql-query-results-into-a-text-or-csv-file\/ (Since this apparently doesn&#8217;t work with one of the versions of MySQL I use, &hellip; <a href=\"https:\/\/www.brightbill.net\/notes\/2018\/08\/dumping-a-sql-query-into-a-csv-file-in-mysql\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","footnotes":""},"categories":[4],"tags":[73],"class_list":["post-471","post","type-post","status-publish","format-standard","hentry","category-technology","tag-mysql"],"_links":{"self":[{"href":"https:\/\/www.brightbill.net\/notes\/wp-json\/wp\/v2\/posts\/471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.brightbill.net\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.brightbill.net\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.brightbill.net\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.brightbill.net\/notes\/wp-json\/wp\/v2\/comments?post=471"}],"version-history":[{"count":3,"href":"https:\/\/www.brightbill.net\/notes\/wp-json\/wp\/v2\/posts\/471\/revisions"}],"predecessor-version":[{"id":729,"href":"https:\/\/www.brightbill.net\/notes\/wp-json\/wp\/v2\/posts\/471\/revisions\/729"}],"wp:attachment":[{"href":"https:\/\/www.brightbill.net\/notes\/wp-json\/wp\/v2\/media?parent=471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.brightbill.net\/notes\/wp-json\/wp\/v2\/categories?post=471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.brightbill.net\/notes\/wp-json\/wp\/v2\/tags?post=471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}