import csv to mysql workbench

How to Import CSV to MySQL Workbench

Sometimes, you may need to import CSV file into MySQL workbench for SQL querying. Here’s how to import CSV to MySQL Workbench.

 

How to Import CSV to MySQL Workbench

Here are the steps to import CSV to MySQL Workbench. After importing CSV file with header into MySQL, you may want to use a reporting tool to query your MySQL table and ensure everything is working well.

 

1. Create Table

First, you need to create a database table with same number of columns as those in your CSV file. Let’s say you want to import CSV file with 4 fields – id, title, expired_date, amount

So we will create a discounts(id, title, expired_date, amount) table using mysql.

mysql> create table 
discounts(id int, title varchar(255), expired_date varchar(255), amount int);

 

Bonus Read : How to Create Histogram in MySQL

 

2. Import CSV file into MySQL table

Open your table in Workbench. Click Import button shown below

mysql workbench import csv

 

You’ll see a “Open File” Dialog Box. Navigate to your CSV file and click Open button.

import csv into mysql workbench

 

Bonus Read : How to Calculate Conversion Rate in MySQL

 

Workbench will show you a preview of how your data would look in the table, after import. Review it and click Apply

review import csv mysql

 

Bonus Read : How to Fill Missing Dates in MySQL

 

Next, Workbench an SQL Script to be executed to import csv into MySQL. Review the queries and click “Apply SQL Script to Database”

sql script to import csv

 

You can use the same queries with CSV or TXT files, by changing the file extension in your query. You can also use it to import tab delimited file into MySQL Workbench.

After you import CSV to MySQL Workbench, you can use a mysql reporting tool like Ubiq to plot your data in line/column charts as shown below.

daily sales report chart graph

 

Hopefully, the above steps will help you easily import CSV file into MySQL workbench. By the way, if you want to create charts & dashboards to monitor your business or website, you can try Ubiq. We offer a 14-day free trial.

mm

About Ubiq

Ubiq is a powerful dashboard & reporting platform. Build dashboards, charts & reports for your business in minutes. Try it for free!