Export MySQL data to CSV: Comprehensive tutorial & best practices

Jamey Barton - Mar 25 - - Dev Community

CSV is one of the most versatile data formats that is widely used to exchange structured data between different applications. The convenience of CSV lies in simplicity. CSV files contain plain text that can be opened by any text editing app, such as Notepad. They can fit well into Excel spreadsheets, and, of course, they can be easily imported and exported from databases. And it's the latter case that we'll explore below.

What is CSV?

But before we do, let's take a closer look at this format. CSV stands for comma-separated values, which basically explains how data is organized in these files. To make it clear right from the start, the content of a CSV file roughly looks as follows:

Product, Size, Color, Price
T-Shirt, S, Yellow, $13
Jeans, M, Blue, $27
Jacket, XL, Brown, $35
Skirt, S, Red, $20
Shirt, L, White, $29

Although commas remain the most common separators (a.k.a. delimiters), they are not the one and only option. You might as well use other characters, such as semicolons, colons, or spaces.

Now, let us show you how to export data from a MySQL table into a CSV file, and we'll use three different approaches to it. The first one is a mysqldump command. The second one is based on the OUTFILE statement. The third one involves a wizard with flexible settings. Which one is the best? Well, it's up to you to choose.

https://www.devart.com/dbforge/mysql/studio/export-mysql-data-from-table-to-csv.html

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .