The server rejects an external data file because its first line does not match the file type header expected by MySQL.
MySQL Error 1341: ER_FPARSER_BAD_HEADER occurs when the server reads an external data file whose first line lacks the expected file-type header. Correct or regenerate the source file so the header conforms exactly to MySQL’s format to remove the error.
Malformed file type header in file '%s'
MySQL raises error 1341 when it tries to parse an external file and the first line does not contain the required file-type header. The message returned is: HY000: Malformed file type header in file 'path/file'
.
The error usually appears during LOAD DATA INFILE
, the CSV storage engine, full-text parser plugins, or any feature that feeds MySQL with a structured file. The header tells MySQL which parser to use. A mismatch stops the entire import to guard data integrity.
A missing header line is the most frequent trigger. If the source system does not prepend the signature that MySQL expects, the parser cannot continue.
A corrupted or manually edited file can alter the header bytes. Even an invisible BOM or newline can render the header invalid.
Mixing file formats is another cause. For example, sending a CSV file to a parser that expects a custom FILETYPE=XXX
header produces the error immediately.
Inspect the first line of the failing file with a hex editor or a simple text viewer. Confirm that it exactly matches the specification required by the MySQL component you are using.
If the header is missing or wrong, regenerate the file from the source application with the correct export option. This guarantees a clean header and consistent delimiters.
When regeneration is impossible, manually add the header. Copy the header from a known-good file of the same type, paste it as the first line, then retry the import.
CSV storage engine table copy - Provide the filetype csv
header line before the comma-separated data rows.
Custom full-text dictionary - Ensure the dictionary file starts with ftdict1
followed by a newline in UTF-8.
Bulk load with Galaxy - Galaxy’s file preview flags missing headers before execution, letting you correct the file in-editor and rerun instantly.
Standardize all exports from upstream systems. Document the exact header each file needs and enforce it with CI jobs or Galaxy run hooks.
Validate files automatically. A simple shell script that checks the first 32 bytes can block malformed uploads early in your pipeline.
Use Galaxy collections to store trusted import scripts. Version control ensures that any header requirement change is reviewed and communicated.
ER_FPARSER_TOO_LONG_IDENT (1342) - Identifier in the header exceeds allowed length. Shorten the label.
ER_LOAD_DATA_REPLICA (1270) - Replication attempted to load data on the replica. Disable --replicate-ignore-db
if unintended.
ER_TEXTFILE_NOT_READABLE (1085) - MySQL lacks file privileges. Grant FILE
or move the file to secure_file_priv
.
Export tools that default to raw CSV often omit the signature line MySQL expects, instantly producing ER_FPARSER_BAD_HEADER.
Opening a file in Excel or a code editor can prepend a BOM or change line endings, corrupting the header.
Users sometimes feed a CSV file into a loader configured for a custom full-text dictionary format, causing a header mismatch.
Non-UTF-8 headers can misalign byte patterns, leading MySQL to misread the file signature as malformed.
Raised when the file parser encounters a null symbol where one is not allowed. Usually fixed by removing null bytes.
Identifier in the file header exceeds the maximum length. Trim the identifier to 64 characters or fewer.
Occurs when MySQL lacks permission to read the file. Verify FILE
privilege and secure_file_priv
path.
No. MySQL checks the internal header, not the extension. You must correct the first line inside the file.
The check is hard-coded for safety. Bypassing it would risk corrupt imports. Always supply a valid header instead.
The error exists in MySQL 5.5 and later, including 8.0. Behavior is consistent across versions.
Galaxy previews the file header and warns on mismatch, letting you correct the file before running LOAD DATA
.