The SQL LOAD statement (most commonly LOAD DATA INFILE in MySQL and MariaDB) is a high-performance, server-side mechanism for ingesting large datasets stored in text or CSV files into an existing table. Unlike iterative INSERT statements, LOAD parses the source file in a streaming fashion and commits the rows in batches, drastically reducing network overhead and transaction time. Options let you define character sets, field and line delimiters, selective column mapping, and on-the-fly transformations via SET expressions. Because the command executes on the database server, the file path must be accessible to the server OS unless the LOCAL keyword is used, which streams the file from the client. File permissions, secure-file-priv restrictions, and column type mismatches are common pitfalls to check before running.
file_path
(string) - Absolute or relative path to the source fileLOCAL
(keyword) - Streams file from client instead of server file systemcharset_name
(string) - Character set used in the file (e.g., utf8mb4)FIELDS TERMINATED BY
(string) - Field delimiter, often a comma or tabOPTIONALLY ENCLOSED BY
(string) - Text qualifier, usually a double quoteLINES TERMINATED BY
(string) - Line break sequence (e.g., \n, \r\n)(column list) (identifier list)
- Optional order of columns to importSET clause
(expression) - Assigns computed values to columns during loadCOPY, BULK INSERT, INSERT, IMPORT, SELECT INTO OUTFILE
MySQL 3.23
Add `IGNORE 1 LINES` after the `LINES TERMINATED BY` clause so MySQL discards the first record.
Yes. List the desired columns in parentheses after the table name. Columns omitted receive their default values or NULL.
If the target table is InnoDB and the command runs inside an explicit transaction, it can be rolled back. Otherwise, rows are committed immediately.
Temporarily disable indexes and foreign keys, increase `bulk_insert_buffer_size`, and wrap the load in a single transaction.