Last updated on May 17th, 2020 at 06:10 am
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
You’ll see a “Open File” Dialog Box. Navigate to your CSV file and click Open button.
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
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”
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.
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.
Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI & software development.