将文本文件导入mysql工作台?

2021-12-25 00:00:00 csv import database mysql mysql-workbench

我想知道如何将文本文件导入 MySQL 工作台?

I was wondering how to import text file into MySQL workbench?

我有一个由 | 分隔的文本文件,第一行是表格,

I have a text file delimited by | and the first row are the tables,

FEATURE_ID|FEATURE_NAME|FEATURE_CLASS

然后是后面的数据信息

1388627|Etena|Populated Place

将此 .txt 文件导入 MySQL 工作台的最佳方法是什么?

What is the best way to import this .txt file into MySQL workbench?

谢谢1

推荐答案

目前还不清楚您到底要实现什么,但是如果您想将带分隔符的文本文件导入到 db 中,则可以使用 LOAD DATA INFILE 像这样:

It's not clear what exactly you intend to achieve, but if you want to import delimited text file into db then you can use LOAD DATA INFILE like this:

LOAD DATA INFILE '/path/file.txt' 
INTO TABLE tablename 
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '
'
IGNORE 1 LINES;

更新:

首先,您需要像这样创建表(如果还没有完成):

First of cause you need to create the table (if it's not done yet) like this:

CREATE TABLE `tablename` (
  `FEATURE_ID` int(11) unsigned NOT NULL,
  `FEATURE_NAME` varchar(512) DEFAULT NULL,
  `FEATURE_CLASS` varchar(512) DEFAULT NULL,
  PRIMARY KEY (`FEATURE_ID`)
)

您可能需要调整该表的数据类型、长度和约束.例如,您可能不需要那个桌子上的 PK.

You might need to adjust data types, lengths, and constraints on that table. For example you might not need a PK on that table.

相关文章