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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14313708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:10:29  来源:igfitidea点击:

import text file into mysql workbench?

mysqldatabasecsvimportmysql-workbench

提问by hellomello

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

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

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

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

FEATURE_ID|FEATURE_NAME|FEATURE_CLASS

then it follows by data information after that

然后是数据信息之后

1388627|Etena|Populated Place

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

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

Thanks1

谢谢1

回答by peterm

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 INFILElike this:

目前尚不清楚您到底打算实现什么,但是如果您想将分隔的文本文件导入数据库,那么您可以LOAD DATA INFILE像这样使用:

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

UPDATE:

更新:

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`)
)

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

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