Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import a csv file into MySQL workbench?

Tags:

import

mysql

csv

I have a CSV file. It contain 1.4 million rows of data, so I am not able to open that csv file in Excel because its limit is about 1 million rows.

Therefore, I want to import this file in MySQL workbench. This csv file contains columns like

"Service Area Code","Phone Numbers","Preferences","Opstype","Phone Type"

I am trying to create a table in MySQL workbench named as "dummy" containing columns like

ServiceAreaCodes,PhoneNumbers,Preferences,Opstyp,PhoneTyp. 

The CSV file is named model.csv. My code in workbench is like this:

LOAD DATA LOCAL INFILE 'model.csv' INTO TABLE test.dummy FIELDS TERMINATED BY ',' lines terminated by '\n';

but I am getting an error like model.CSV file not found

like image 812
vps Avatar asked Jul 11 '12 09:07

vps


People also ask

Can you import CSV into MySQL?

MySQL Workbench is a graphical user interface provided by MySQL to manage the database, write the SQL queries, etc. It provides a wizard that allows us to export or import the data in a csv or json format.

Can you import Excel into MySQL Workbench?

Step 1: Click on the Browse button and select the Excel file you want to import to MySQL. Step 2: Select MySQL as your desired database. According to your excel file, check or uncheck My File has a Header Row. Step 3: Based on your Excel file, check Use CHECK IF TABLE EXISTS.


2 Answers

I guess you're missing the ENCLOSED BY clause

LOAD DATA LOCAL INFILE '/path/to/your/csv/file/model.csv' INTO TABLE test.dummy FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'; 

And specify the csv file full path

Load Data Infile - MySQL documentation

like image 152
Packet Tracer Avatar answered Sep 30 '22 15:09

Packet Tracer


In case you have smaller data set, a way to achieve it by GUI is:

  1. Open a query window
  2. SELECT * FROM [table_name]
  3. Select Import from the menu bar
  4. Press Apply on the bottom right below the Result Grid

enter image description here

Reference: http://www.youtube.com/watch?v=tnhJa_zYNVY

like image 31
Gabriel Chung Avatar answered Sep 30 '22 17:09

Gabriel Chung