Question

How do I import a .txt file into a MySQL table?

My .txt file is like this...

ex : AF0856427R1  000002200R HADISUMARNO            GGKAMP MALANG WET 3   6   00705    AFAAADF16000-AD-FA P00.001.0  1 000001.00022947.70023290.00 T511060856425A 022014B

There are 39 fields in my file.

No correct solution

OTHER TIPS

Try mysqlimport command

name of the text file should be the name of the table in which you want the data to be imported. For eg, if your file name is patient.txt, data will be imported into patient table

mysqlimport [options] db_name textfile

There are lot of options that you can pass in. Documentation here

Especially since some of your fields are terminated by spaces and some are based on string length, I would definitely first do some string manipulation with your favorite tool (sed, awk, and perl are all likely very good choices).

Create an intermediary comma separated file. If you have commas in the existing file, you can easily use some other character. The goal is to create a file that has one consistent separator.

You've used the phpMyAdmin tag, so from your table go to the Import tab, select the file, and pick CSV from the dropdown of file types. Edit the options according to what your file looks like (for instance, perhaps § is your column separator and you might leave the next two options blank). Then try the import and check the data to make sure it all arrived in the columns you expected.

Good luck.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top