Moving Spreadsheet Data into MySQL Through a Controlled CSV Import

Image retained from the original article.

Originally published 26 July 2023; rewritten and reviewed on 15 October 2026.

A spreadsheet is convenient for collecting information, but its flexible cells can hide inconsistent dates, blank identifiers and mixed number formats. Before importing it into MySQL, I would make those assumptions visible in a small staging process.

Convert the workbook deliberately

LOAD DATA is a text-data import facility, not an Excel workbook parser. Export the relevant sheet as CSV and confirm its encoding, line endings and quoting rules. Keep the original workbook so questionable values can be traced back.

Prepare a staging table with a schema suited to validation. Values that need cleaning may be easier to inspect as text before conversion into the production types.

LOAD DATA INFILE '/var/lib/mysql-files/customers.csv'
INTO TABLE customer_import_stage
CHARACTER SET utf8mb4
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(customer_code, customer_name, email);

Adjust the terminator to the actual file, including carriage returns where applicable. The example assumes a header and the stated column order.

Understand who reads the file

Server-side INFILE uses the database server’s filesystem and access controls, including secure_file_priv where configured. LOCAL INFILE follows a different client-side path and security model. Do not enable it globally merely to bypass an unexplained error. Consult the MySQL LOAD DATA reference for your deployed version’s requirements.

Check the batch before using it

Compare counts, review warnings and examine names, leading zeros, empty fields and quoted delimiters. Decide how duplicates and rejected records will be handled. Promote validated data through a controlled operation that can be explained and repeated.

An import succeeds when the intended records arrive with their meaning intact. A fast command is useful; a reconciled batch is what makes the result trustworthy.

Related reading