huddds huddds - 1 year ago 103
MySQL Question

Insert a plain text list to mysql table

I have a very long list in plain text which I need to insert into a table my database. Do I have to manually input each line of my plain text document or is there a way to insert long lists into independent rows in a table using a query?

I have a table with 2 columns, id and club_name, club_name is the list which is plain text in a notepad document.

Answer Source

You can use LOAD DATA, e.g.:

mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet

You can also use the multi-row insert syntax (if you are using InnoDB tables), like this:

INSERT INTO yourtable VALUES (1,2), (5,5), ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download