title: Efficiently writing a large mysql2 result to CSV
body: <p>We're building a CSV export mechanism in a CMS we just built and we're having trouble keeping memory down on result sets with millions of rows. What is the best way to write a 1MM+ row result from MySQL (via the <code>mysql2</code> gem) to CSV. If it makes any difference, we're on Ruby 1.9.3p194 and MySQL 5.5. Our main goal is to keep memory consumption down on the Ruby process.</p>