INFILE is a MySQL and MariaDB keyword that appears inside the bulk-loading commands LOAD DATA and LOAD XML. It tells the server where to find the external text or XML file that contains rows to be inserted. When the optional LOCAL modifier precedes INFILE, the client, rather than the server, reads the file and streams its contents to the server—useful when the database server cannot access the file system directly. Without LOCAL, the file must reside on the database server host and be readable by the MySQL/MariaDB process.Important caveats:- File path must be quoted and use the server’s file-system conventions.- The server requires the FILE privilege (or the secure_file_priv directory restriction) when LOCAL is not used.- INFILE is case-insensitive but conventionally written in uppercase.- Performance is significantly faster than multiple INSERT statements because data is parsed in bulk.- Security configurations such as --local_infile flag or the server variable local_infile may disable LOCAL INFILE for safety.
file_path
(string) - Absolute or relative path to the file containing data.LOCAL
(keyword) - Optional keyword that forces the client to read the file and send it to the server.LOAD DATA, LOCAL, OUTFILE, COPY (PostgreSQL), BULK INSERT, SQL*Loader
MySQL 3.23
You need the FILE privilege for server-side files and an enabled local_infile setting for LOCAL INFILE. The target table also requires INSERT privileges.
Not directly. Decompress the file first or use a pipeline that writes to a temporary uncompressed file before running LOAD DATA INFILE.
Specify the NULL keyword or use a custom string in the FIELDS clauses, for example: FIELDS TERMINATED BY ',' NULL '\\N'.
Yes. If autocommit is off, the rows are loaded within the current transaction and can be rolled back before COMMIT.