Import CSV files into MySQL Workbench using the command line (LOAD DATA INFILE)
Even though MySQL workbench is a popular tool, it is a surprise that a most basic task like importing a few MBs of CSV file into it takes a lot of time. The command line (LOAD DATA INFILE command) is undoubtedly the fastest way to import CSV files into MySQL Workbench. It is so fast that it takes only a few seconds to import a CSV file that Table Data Import Wizard would take hours to do.
85k records. 22 Seconds
Here is how to do it from beginning to end, step by step with a full description.
Step 1 - Prepare CSV files to import
To do this, you need 2 copies of the same CSV file to import into MySQL Workbench. The first is to import and the second file is to create the table in the schema.
Open the second file and delete all raws except the Header raw and the first record raw and save.
Step 2 - Create a Table
Import the second file (edited with only one recorded) using Table Data Import Wizard. This will create a new table with only column headers and one record.
Step 3 - The Command Prompt
On the MySQL Command Line Client log in to the MySQL connection and select the Database with the table that you just created.
USE databasename
Then check if the table you created exists in the database.
SHOW tables;
Then add the below script and run it.
LOAD DATA INFILE 'C:/Program Files/MySQL/Excel Files/CovidDeaths original.csv'
INTO TABLE coviddeaths1
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 2 ROWS;
on the first line add the path to the CSV file with forward slashes.
Check the table in MySQL Workbench.