Creating a MySQL Dump in CSV Format
SQL dumps are the standard for database backups, but sometimes you need to share data with non-technical users. CSV files can be opened in Excel, OpenOffice Calc, or any spreadsheet application—much more accessible than a SQL file.
Here’s how to export a MySQL database directly to CSV format:
mysqldump -p -u USER -T DIRECTORY --fields-enclosed-by=\" --fields-terminated-by=, DATABASE
Parameter Breakdown
- -p — Prompts for password authentication
- -u USER — Specifies the database username
- -T DIRECTORY — Output directory for the files
- —fields-enclosed-by=” — Wraps fields in quotation marks for proper CSV parsing
- —fields-terminated-by=, — Uses commas as delimiters instead of tabs
- DATABASE — The database to export
This converts mysqldump’s default tab-delimited output into proper comma-separated values.
Note: You need FILE privileges on the database to execute this command. The output directory must also be writable by the MySQL server process.
Each table gets exported as a separate CSV file, making it easy to share specific data with whoever needs it.