简体   繁体   English

如何使用SQuirreL将.csv文件导入MySQL

[英]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. 我正在使用SQuirreL SQL,我想将.csv文件导入MySQL。 Please tell how to do that. 请告诉我该怎么做。

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. 根据import-data-from-a-file-like-csv你应该右键单击要导入的表格,在上下文菜单中你应该看到一个名为“Import file”的菜单项,你在那里选择你的csv文件。

With F1 -> Help -> Data Import Plugin you should get some help about that. 使用F1 - >帮助 - >数据导入插件,你应该得到一些帮助。

If you need to create the table from .CSV 如果需要从.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. 我的情况略有不同,我将表导出到.CSV,我需要从该文件创建和导入表。

1. Get the column definitions 1.获取列定义

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). 如果您自己从另一个数据库导出CSV,您也可以返回该数据库并从那里获取“创建表脚本”(对象面板 - >右键单击相关表格 - >脚本 - >创建表脚本)。

Same case if you can reach out to the originator of the .CSV: you may ask for the Create table script. 如果您可以联系.CSV的发起人,也可以使用相同的情况:您可以要求创建表脚本。

b. You just have the .CSV 你刚才有.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. 从SQuirreL中连接到.CSV作为数据库(您可以使用hxttcsvjdbccdata ),您可以获取Create表脚本。

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. 但是这种方式(好吧,我尝试过csvjdbc),你只需将所有列作为varchar(max) ,你就必须根据自己的喜好进行编辑。 For 200+ columns, this might be a little bit of a pain. 对于200多列,这可能有点痛苦。 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. 另一方面,您获取数据库中的数据,然后您可以使用适当的列定义来练习SQL向导并将数据转换为另一个表。

2. Create the table in your destination schema 2.在目标架构中创建表

That is just connecting to the DB and Schema where you miss the table and running the Create table script there. 这只是连接到您错过表并在那里运行Create表脚本的DB和Schema。 You will get the empty table. 你会得到空表。

3. Import the data 3.导入数据

Objects panel --> right click on the table you just created --> Import File 对象面板 - >右键单击刚刚创建的表 - >导入文件

Then follow the wizard. 然后按照向导操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM