Reputation: 37
how to import .txt to mysql file?
I have a .txt file with hundreds of records and I want to import it into the mysql database table.
example: word.txt contains data:
word_1
word_2
word_3
.
.
.
.
.
word_n
I have a table in the mysql database: tbl_word:
field: id_word, value_word, create_date, update_date
value in every line of word.txt file will I insert / import to column value_word with setting id_word AUTO_INCREAMENT, how to do?
Upvotes: 2
Views: 2498
Reputation: 704
Check LOAD DATA INFILE Syntax to import a file into a table
load data infile 'word.txt'
into tbl_word
fields
terminated by '\t'
lines terminated by '\n'
ignore 0 lines
(@c1,@c2,@c3,..,@cN)
set value_word=@c1;
id_word will increment automaticaly
Upvotes: 1
Reputation: 452
tbl_word _listData = new tbl_word();
string text = read all text from text file.
for (iterate till end of text )
{
if(line break logic)
var value = split line;
_listData.value_word = value;
insert into table tbl_word values will have var value;
}
Upvotes: 0