HOWTO · MySQL

How to Import Excel File Into a MySQL Database

Learn three ways to import Excel data into MySQL: convert it to CSV for LOAD DATA or phpMyAdmin, or convert the workbook with Sqlizer.io.

On this page

To import an Excel workbook into MySQL, either save a worksheet as CSV and load it with LOAD DATA or phpMyAdmin, or use Sqlizer.io to convert the workbook into SQL. The CSV routes require a compatible destination table; the Sqlizer.io route works from the workbook but produces SQL that you should review before running. The steps below use a student table with id, firstname, lastname, gender, and city columns.

Use the LOAD DATA Statement to Import Data

Save the worksheet as CSV (comma delimited). Check that its columns match the destination table in both order and meaning. The example assumes the CSV has a header row, comma-separated fields, double-quoted text, and Unix line endings; it assumes the destination table contains no rows initially, so rerunning the import will not duplicate rows. Adjust the format options to match the file you actually saved.

You can preview a representative CSV row with Python’s standard library before loading it. This small example uses one row with the same column names as the sample table:

import csv
from io import StringIO

sample = StringIO("id,firstname,lastname,gender,city\n1,Ada,Lovelace,F,London\n")
row = next(csv.DictReader(sample))
print(f"{row['firstname']} {row['lastname']} — {row['city']}")
Ada Lovelace — London

This preview checks that the header names and values are read as intended; it does not connect to MySQL or replace the import statement below.

The MySQL 8.0.27 example uses a Windows server upload directory. LOAD DATA INFILE reads the path from the MySQL server’s filesystem, so the file must be accessible to the server and permitted by its secure_file_priv setting. In MySQL Workbench, run the statement in a query tab connected to that server; Workbench does not make a path on your workstation available to the server. The same server-side path rule applies from the command-line client. If you use LOAD DATA LOCAL INFILE, the client reads and sends the file instead, and both client and server settings must allow local loading. Consult MySQL’s LOAD DATA security guidance if access is denied.

For the sample file, the statement is LOAD DATA INFILE 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/students.csv' INTO TABLE tb_students FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 ROWS;. Replace the path, table, delimiter, enclosure, and line terminator to match your setup. For tab-separated data use FIELDS TERMINATED BY '\t'; for a single-space delimiter use FIELDS TERMINATED BY ' '. Windows CSV files commonly use \r\n line endings, so use the file’s actual line ending if rows are not split as expected. IGNORE 1 ROWS skips the header; it does not map columns by their names. If the file omits id or its column order differs, specify the matching destination columns after the table name and confirm any auto-generated values are handled as intended.

After loading, check the table in Workbench or query SELECT id, firstname, lastname, gender, city FROM tb_students LIMIT 10;. Compare the rows with the CSV, and check the imported row count before using the data.

top 3 easiest ways to import excel file into mysql database - save as dot csv

top 3 easiest ways to import excel file into mysql database - csv file data

top 3 easiest ways to import excel file into mysql database - table data in mysql

top 3 easiest ways to import excel file into mysql database - new table for cmd

top 3 easiest ways to import excel file into mysql database - load data command in cmd

top 3 easiest ways to import excel file into mysql database - load data output in cmd

Method 2: Use Sqlizer.io to Import Data

Use Sqlizer.io when you want to convert a workbook without first saving it as CSV. Select the workbook and MySQL as the target database type, then indicate whether the first row contains headers. Choose the active worksheet or enter the worksheet name, such as students, and select the whole worksheet or the cell range to convert. Set the destination table name and generate the SQL.

Review the generated statements before running them: confirm the table definition, column names, values, and any create-table or existence-check behavior. Run the SQL against the intended database, then inspect the table and compare representative rows with the workbook. A workbook can contain confidential data, so consider its sensitivity and the service’s terms before uploading it to an external converter.

top 3 easiest ways to import excel file into mysql database - sqlizerio

top 3 easiest ways to import excel file into mysql database - sqlizerio queries

top 3 easiest ways to import excel file into mysql database - sqlizerio queries data

Method 3: Import Data Using phpMyAdmin

This route also uses a CSV file. Save the worksheet as CSV, then open the target database and select the table whose columns match the CSV. The example table, tb_students_phpmyadmin, has id, firstname, lastname, gender, and city columns. In phpMyAdmin, open the table’s Import tab, choose the CSV file, and select CSV as its format. Set the format-specific options to match the file, including the field separator, text enclosure, line ending, and whether to skip the header row. Start the import with Go.

If the CSV columns do not align with the table, correct the table or file before importing; choosing CSV format alone does not match columns by their header names. When the import completes, browse the table or run a row query and compare several values and the row count with the source file.

top 3 easiest ways to import excel file into mysql database - import data using phpmyadmin part 1

top 3 easiest ways to import excel file into mysql database - import data using phpmyadmin part 2

top 3 easiest ways to import excel file into mysql database - import data using phpmyadmin part 3

top 3 easiest ways to import excel file into mysql database - import data using phpmyadmin part 4

Conclusions

Choose LOAD DATA when you can save a worksheet as CSV and the MySQL server can access the file; use phpMyAdmin for a browser-based CSV import. Sqlizer.io converts a workbook into SQL, which you can inspect and run on the intended database. For each method, match the source columns and format to the destination table, then verify the inserted rows.