'Export of MySQL database with --complete-insert does not include column names in resulting txt files

I am trying to export database with multiple tables into csv / txt files including column names. However, using --complete-insert flag in the statement does export txt files but without corresponding column headers. The exported sql file does contain the column headers.

This is the command I am using:

mysqldump --password --fields-optionally-enclosed-by='"' --fields-terminated-by=',' --tab /var/lib/mysql-files/ --complete-insert test

I am using latest docker image with MySQL 8.0.28 installed on it. I tried different ways of including --complete-insert statement with no effect.



Solution 1:[1]

Yes, that's how mysqldump works, by design. The option --complete-insert is irrelevant when using --tab.

When using mysqldump --tab the export is not formatted as INSERT statements. It's just a dump of CSV data, one file per table.

Then mysqldump executes SELECT * INTO OUTFILE for each table. The result of that SELECT statement is only the data, no header that includes column names.

The column names are implicit. They match the order of columns in the corresponding CREATE TABLE statement.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bill Karwin