title: How to export a MySQL database to JSON?
body: <p>I am interested in exporting a subset of values from a MySQL database into a JSON-formatted file on disk.</p>
  
  <p>I found a link that talks about a possible way to do this: <a href="http://www.thomasfrank.se/mysql_to_json.html" rel="noreferrer">http://www.thomasfrank.se/mysql_to_json.html</a></p>
  
  <p>... but when I use the method from that page, it seems to work but with two problems:</p>
  
  <p>1) It only returns around 15 results, with the last one abruptly cut off (incomplete). My standard query for this returns around 4000 results when I just run it as <code>SELECT name, email FROM students WHERE enrolled IS NULL</code>
  But when I run it as:</p>
  
  <pre><code>SELECT 
       CONCAT("[",
            GROUP_CONCAT(
                 CONCAT("{name:'",name,"'"),
                 CONCAT(",email:'",email,"'}")
            )
       ,"]") 
  AS json FROM students WHERE enrolled IS NULL;
  </code></pre>
  
  <p>... as described in the link, it only returns (as I mentioned) 15 results. (fwiw, I checked these results against the 4000 I'm supposed to get, and these 15 are the same as the first 15 of the 4000)</p>
  
  <p>2) There seem to be "escape" characters included in the actual file when I add <code>INTO OUTFILE '/path/to/jsonoutput.txt' FIELDS TERMINATED BY ','</code> to the end of that query. So commas end up looking like '\,' when obviously I would just like to have the commas without the \.</p>
  
  <p>Any ideas on how to get proper JSON output from MySQL? (Either using this method, or some other method)?</p>
  
  <p>Thanks!</p>