Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Import a .csv file into MySQL using SQuirreL

I m using SQuirreL SQL and I want to import a .csv file into MySQL. Please tell how to do that.

like image 561
kratika gupta Avatar asked Oct 07 '14 06:10

kratika gupta


2 Answers

If you need to create the table from .CSV

My case differs a bit in that I have the table exported to a .CSV and I need to create and import the table from that file.

1. Get the column definitions

a. You have access to the original source

If you exported the CSV yourself from another database, you might as well go back to that database and get the "create table script" from there (objects panel --> right click on the table in question --> Scripts --> Create Table Script).

Same case if you can reach out to the originator of the .CSV: you may ask for the Create table script.

b. You just have the .CSV

Connect to the .CSV as a database from within SQuirreL (you may use hxtt, csvjdbc or cdata) and you can get the Create table script.

But this way (well, I tried csvjdbc), you just get all columns as varchar(max) and you will have to edit them to your liking. For 200+ columns, this might be a little bit of a pain. On the other hand, you get the data inside a DB and then you might exercise your SQL wizardry and convert data into another table, with proper column definitions.

2. Create the table in your destination schema

That is just connecting to the DB and Schema where you miss the table and running the Create table script there. You will get the empty table.

3. Import the data

Objects panel --> right click on the table you just created --> Import File

Then follow the wizard.

like image 22
manuelvigarcia Avatar answered Sep 27 '22 00:09

manuelvigarcia


According importing-data-from-a-file-like-csv you should right-click on the table, where you want to import into, and in the context menu you should see a menu-item called "Import file", where you choose your csv-file.

With F1 -> Help -> Data Import Plugin you should get some help about that.

like image 137
sqlab Avatar answered Sep 27 '22 00:09

sqlab