When working with MySQL, Error 1087 SQLSTATE: HY000 (ER_LOAD_INFO) Records: %ld Deleted: %ld Skipped: %ld Warnings: %ld
is not an error message but rather an informational message that typically appears after executing a LOAD DATA INFILE
command. This message provides a summary of the operation, including the number of records loaded, deleted, skipped, and any warnings generated during the process. The %ld
placeholders are replaced with the actual numbers. Understanding this message can help you verify the results of your data import and troubleshoot any issues that may arise. Let’s look at different scenarios related to the LOAD DATA INFILE
operation and how to address potential concerns.
Understanding LOAD DATA INFILE
Summary Message
Records Loaded
The number of records loaded indicates how many rows have been successfully imported into the table.
Example:
LOAD DATA INFILE '/path/to/datafile.csv'
INTO TABLE my_table
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
If the number of records loaded is less than expected, check the data file for formatting issues or inconsistencies with the table structure.
Records Deleted
The number of records deleted applies when using the REPLACE
or IGNORE
keywords in the LOAD DATA INFILE
statement, which can lead to the deletion of existing rows in the table that conflict with the new data.
Example:
LOAD DATA INFILE '/path/to/datafile.csv'
REPLACE INTO TABLE my_table
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
To avoid unintentional deletions, ensure that the unique keys or primary keys in your data file correctly match those in the table.
Records Skipped
The number of records skipped usually indicates that some rows in the data file did not match the expected format or violated table constraints and were therefore not imported.
Example:
LOAD DATA INFILE '/path/to/datafile.csv'
IGNORE INTO TABLE my_table
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
Review the skipped records to correct any data issues and retry the import if necessary.
Warnings Generated
Warnings may occur when the data does not perfectly match the expected format, such as incorrect data types or potential data truncation.
Example:
SHOW WARNINGS;
After a LOAD DATA INFILE
operation, use the SHOW WARNINGS
command to display detailed information about each warning and address the issues in the data file or table schema accordingly.
Conclusion
When you see the MySQL summary message Error 1087 after a LOAD DATA INFILE
operation, it’s important to:
- Review the number of records loaded to ensure all intended data has been imported.
- Understand the implications of the
REPLACE
andIGNORE
keywords and their effect on records deleted. - Investigate any skipped records to identify data inconsistencies or constraint violations.
- Use the
SHOW WARNINGS
command to diagnose and fix any issues that generated warnings.
By carefully examining the summary message and taking appropriate action based on its contents, you can ensure the integrity and success of your data import operations. If you encounter difficulties, consulting the MySQL documentation on LOAD DATA INFILE
can provide further guidance, and community forums can be a valuable resource for additional support.