Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import text file into mysql workbench?

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

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?

Thanks1

like image 746
hellomello Avatar asked Oct 18 '25 19:10

hellomello


1 Answers

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 '\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.

like image 104
peterm Avatar answered Oct 20 '25 10:10

peterm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!