
MySQL databases are a common way to manage and store a wide variety of structured data. However, you would often need to migrate data from your MySQL database to another. There are many ways to migrate data. One of the popular methods to migrate data is to export MySQL data in CSV files. But, migration is not limited to just moving between two databases. There are many reasons to export MySQL data with CSV files.
Following are some of the reasons for MySQL to CSV export.
- You can build reports from the exported CSV data.
- You can easily access your database data in offline mode.
- Several SaaS tools accept CSV files to import or export data.
In this article, we’ll walk through 6 effective ways to export MySQL to CSV, covering both command-line and GUI tools — plus one bonus method for automated real-time exports. But first, let’s briefly understand what CSV and MySQL are.
What is a CSV file?
A CSV (Comma-Separated Value) file is a plain text file used to store data. The values in CSV files are separated using commas. Since separating data with commas is a simple process, the CSV files are lightweight. As a result, it is a popular choice for exporting and importing data among data professionals.
Although the data in CSV files are separated in comma-delimited format, you can quickly convert them into a columnar format. This allows you to quickly read and analyze data with different programming languages.
What is MySQL?
MySQL is an open-source Relational Database Management System. It is widely used to store structured data to perform quick analysis. With MySQL, you can store data across multiple tables and apply the relationship among data points for better accessibility.
MySQL works with Structured Query Language (SQL), making it accessible to a wider range of users. However, you can also talk to the MySQL database with different programming languages like Python, Java, and more.
Methods of Exporting Data to CSV from MySQL Database
Whether you're building reports, backing up data, or integrating with SaaS tools, exporting MySQL data to a CSV file is a common task. Depending on your needs and technical preferences, there are several ways to do it.
In this guide, you’ll learn how to export MySQL tables to CSV using:
- Using the Command Line
- Using Mysqldump
- Using phpMyAdmin
- Using the CSV Engine
- Using MySQL Workbench
- SaaS Alternatives
We’ll walk through each approach step-by-step, so you can choose the one that works best for your use case.
Method 1: Export MySQL to CSV Using the Command Line
You can use the command line method to establish a connection with your MySQL database and export data into a CSV file.
- To open a command prompt, press the Windows button + R and type cmd in the run window.
- A command line interface will appear on your screen. Verify if MySQL is running by executing the
net start
command in the command prompt. You will see a list of services that are currently running. - Connect with your local MySQL server using the below command:
mysql -u [username] -p
Enter the username at[username]
that you created for MySQL installation. - You can log in to your MySQL local server as the root user using
mysql -u root -p
command.
- On execution of the above command, you will be prompted to enter the password.
Enter password: ******* - Now, you’re connected to the MySQL server. The command prompt will now look like this:
mysql>
- Move to the MySQL folder using the cd command and list the files in this folder using dir command.
cd c:\Program Files\MySQL
dir
- To check the list of databases, enter the below command.
show databases;
- To select a specific database, use the name of the database that you want to use.
use [databasename];
Replace[databasename]
with the name of the database you want to select. - Now, let’s export the data in a CSV file. Let’s consider the below MySQL database table for exporting in a CSV file.
Image Credit: learnsql
- Use the below command to export data from MySQL to CSV.
SELECT * FROM data.employees
INTO OUTFILE 'employees.csv';
Here, theSELECT
statement is used to get the data from thedata.employees
table and the data is exported in theemployees.csv
file.INTO OUTFILE
statement will load the data into theemployees.csv
file.
If you are using Windows, your file will be stored at theC:\ProgramData\MySQL\MySQL Server 8.0\Data location
.
The above method will export data into CSV without any specific customization. You can follow the below methods to add column names, export specific columns of a table, or handle null values.
Using the command line method, you can also export customized data from MySQL to CSV with the following approaches:- Export data with a column heading
- Handling NULL values
- Export specific columns of a table
Export Data with a Column Heading
It would be easier to understand data if the exported CSV files contained a column heading as their first line. Use the UNION
operator to add a column heading to the CSV file.
As shown in the command below, you need to add a column heading for every column.
Code:
plaintext(SELECT 'Order Number','Order Date','Status')
UNION
(SELECT orderNumber, orderDate, status
FROM orders
INTO OUTFILE 'C:/tmp/orders.csv'
FIELDS ENCLOSED BY ' " ' TERMINATED BY ';' ESCAPED BY ' " '
LINES TERMINATED BY '\r\n');
Let’s understand the query in more detail:
- In the first
SELECT
statement mention the column heading, add the column heading that you want in the output file. - In the
OUTFILE
, mention the path where you want to store your csv file with .csv extension.
Handling NULL Values
Often your tables might contain NULL values which would be shown as ‘N’ in the exported file. You can change this ‘N’ with your preferred text for better understanding using the IFNULL function.
Code:
plaintextSELECT empName, empjoinDate, IFNULL(empNumber, 'N/A')
FROM employee INTO OUTFILE 'C:/tmp/employeedata2.csv'
FIELDS ENCLOSED BY ' " '
TERMINATED BY ';'
ESCAPED BY ' " ' LINES
TERMINATED BY '\r\n';
In the above query statement, the ‘Null’ values in the empNumber column are replaced with ‘N/A’ string.
Export Specific Columns of the Table
For more convenient use, you would want to select specific columns from a table. Using the SELECT statement and WHERE clause, you can achieve filtered results. For reference, check the below command lines.
plaintextSELECT employeeName,
FROM Employee
WHERE employeeName= 'value';
INTO OUTFILE 'employees.csv';
In the above query, employeeName
is the column name and Employee
is the table name. Using the WHERE
clause, you can select specific values from the column. With this method, you can export specific columns and values from the table.
Method 2: Export MySQL to CSV Using mysqldump
mysqldump is commonly used for backing up or transferring MySQL databases, but you can also use it to export table data in a CSV-like format.
⚠️ Note: mysqldump itself doesn’t export data in CSV directly. You need to use it with specific flags and output options to simulate a CSV export.
To perform a MySQL dump to CSV, use the following command in the terminal.
Syntax to Export a Table to CSV:
plaintextmysqldump -u your_username -p \
--tab=/path/to/output_dir \
--fields-terminated-by=',' \
--fields-enclosed-by='"' \
your_database your_table
Explanation of Flags:
- --tab: Specifies the output directory (must exist and be writable by MySQL).
- --fields-terminated-by=',': Sets the comma as the field separator.
- --fields-enclosed-by='"': Wraps fields in double quotes, useful for strings.
- your_database your_table: Replace with your database and table names.
This command generates two files:
- A .sql file containing the table’s schema
- A .txt file containing the data (in CSV-compatible format)
You can rename the .txt file to .csv for clarity.
Exporting the Entire Database
To export all tables in a database using mysqldump and still get delimited output, you’ll need to combine the --tab flag with shell scripting or post-processing steps, which can get messy. For large-scale or ongoing exports, consider using tools like Estuary Flow for automation.
When to Use
Good for:
- Server-level backups with some CSV-style formatting
- Exporting individual tables with clean structure
Not ideal for:
- Real-time syncing
- Automated or recurring exports
- Cloud-based workflows
Method 3: Export MySQL to CSV Using phpMyAdmin (GUI)
With phpMyAdmin, you can export your databases in CSV, XML, YAML, and JSON formats. It provided a Graphical User Interface (GUI) to export data from the database to any other format.
Below is the step-by-step guide to exporting data using phpMyAdmin.
Step 1: Log in to your phpMyAdmin. Next, choose the database and select the table you want to export. Now, click the ‘Export’ button from the top menu bar.
Image Credit: inmotionhosting.com
Step 2: Next, you need to select the ‘Export Method’. In order to export all the data from the table, select the ‘Quick’ option. You can choose the 'Custom' option if you want to export specific data from the table.
Image Credit: inmotionhosting.com
Step 3: After selecting an Export method option, you need to select the format of your exported file. Now, choose the CSV from the dropdown list under the format menu.
Click on Go. Next, click on the Save button.
💡 If you need to integrate MySQL data with another platform (like Google Sheets or Snowflake) on a regular basis, a real-time pipeline using Estuary Flow may be a more efficient long-term solution.
Looking for something else? Check out our Mysql to other database migration guide:
Method 4: Export MySQL to CSV Using the CSV Storage Engine
The CSV store engine is one of the ways to export to CSV from MySQL. It uses CSV format to house data in text files.
Once you create a table, the server will create a .csv extension file name. The file name will be the same as that of the table name. It stores data using comma-separated values format, as shown below in the output.
Code:
plaintextCREATE TABLE test (i INT NOT NULL, c CHAR(10) NOT NULL)
ENGINE = CSV;
Query OK, 0 rows affected
INSERT INTO test VALUES(1,'record one'),(2,'record two');
Query OK, 2 rows affected
Records: 2 Duplicates: 0 Warnings: 0
After executing the above commands, you will get a test.csv file in the database directory. The data in the file should look like this.
Output:
plaintext"1","record one"
"2","record two"
Estuary Flow offers a real-time alternative for exporting MySQL data to cloud destinations without needing low-level file system access or storage engines.
Method 5: Export MySQL to CSV Using MySQL Workbench (GUI)
MySQL Workbench provides import/export wizard that allows you to import or export your database or specific tables. The wizard uses a Graphical User Interface (GUI) and supports CSV and JSON format.
Click here to download MySQL Workbench.
Follow the below steps to export MySQL output to CSV files.
Step 1: Open MySQL Workbench and select the database. Right-click on the table name and choose ‘Table Data Export Wizard.’ You can also perform this step from the tab menu, click ‘Server’, and select ‘Data Export.’
Image Credit: dev.mysql.com
Step 2: After selecting the ‘Table Data Export Wizard,’ you will see the below window. By default, all the tables will be selected from that schema. You can uncheck if you don’t want to export any table. Click Next.
Image Credit: dev.mysql.com
Step 3: Next, you will get a ‘Table Data Export’ window. Here, you can browse the path to store your file. Choose the CSV format. Click Next.
Image Credit: dev.mysql.com
Step 4: In the ‘Export Data’ window, check if ‘Prepare export’ and ‘Export data to file’ are selected. Then click Next. Your data will start exporting, and you can track the process through Logs.
Image Credit: dev.mysql.com
Method 6: SaaS Alternatives to CSV Export (Like Estuary Flow)
If you're manually exporting CSVs just to upload them elsewhere—like a BI tool, data warehouse, or spreadsheet—you're likely spending more time than necessary. CSV exports are fine for one-off tasks, but they break down quickly at scale.
Why CSV Export Isn’t Always the Best Option
- Time-Consuming: Exporting multiple tables manually is tedious and error-prone.
- Stale Data: Your MySQL data may change frequently. Once exported, the CSV becomes outdated almost instantly.
- Lack of Automation: There's no built-in way to keep data up-to-date without constant re-exports and uploads.
A Better Approach: Estuary Flow
Estuary Flow is a real-time data integration platform that connects MySQL to cloud destinations without needing to export/import CSVs manually.
With Estuary Flow, you can:
- Automatically extract data from MySQL using Change Data Capture (CDC)
- Stream data in real-time to destinations like Google Sheets, BigQuery, Snowflake, and many more
- Apply transformations in-flight using SQL or TypeScript
- Eliminate manual steps and ensure your data is always fresh
Example: Instead of exporting a MySQL customer table to CSV and uploading it to Snowflake weekly, Estuary Flow can continuously sync that table—no code, no delay.
When to Use
Ideal for:
- Real-time reporting and analytics
- SaaS-to-warehouse or SaaS-to-spreadsheet sync
- Teams looking to automate and scale data workflows
Skip if:
- You only need a one-time backup of a small table
Conclusion
Exporting MySQL data to CSV is a straightforward way to back up your data, build reports, or share snapshots with other tools. Whether you prefer the command line, a GUI like phpMyAdmin or Workbench, or even the CSV storage engine, you have plenty of options to get the job done manually.
But when data freshness, scale, and efficiency matter, manual CSV exports fall short.
That’s where Estuary Flow shines. With its real-time pipelines, no-code interface, and support for 200+ sources and destinations, you can keep your data flowing—without repetition or delay.
Whether you want to sync MySQL to a spreadsheet, a cloud warehouse like BigQuery or Snowflake, or a downstream analytics tool, Estuary Flow gives you the speed and simplicity you need.
Your first pipeline is free. Get started with Estuary Flow today and say goodbye to repetitive CSV exports.
FAQs
1. How do I export data from MySQL to a CSV file?
2. Can I export MySQL data to CSV without using the command line?
3. What is the best way to export large MySQL tables to CSV?

About the author
With over 15 years in data engineering, a seasoned expert in driving growth for early-stage data companies, focusing on strategies that attract customers and users. Extensive writing provides insights to help companies scale efficiently and effectively in an evolving data landscape.
