MySQL + SQL · Lesson 105
Import and Export CSV in MySQL
CSV Import / Export
MySQL can read data from a CSV file into a table and write query results out to a CSV — useful for Excel and bulk data.
Import (LOAD DATA)
LOAD DATA INFILE 'students.csv'
INTO TABLE students
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;IGNORE 1 ROWS skips the header line of the CSV.
Export (INTO OUTFILE)
SELECT * FROM students
INTO OUTFILE 'out.csv'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
Summary
- LOAD DATA INFILE imports a CSV into a table.
- SELECT ... INTO OUTFILE exports query results to a CSV.
💻 Live Code Editor
This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.