to****@NOSPAMnterport.net wrote:
I have a text file with 180 headers.
Is it possible to import this file into mysql where mysql will
automatically create the table with column headings from the headers
(as sql server and access do?)
I can't find an option like this in the docs for the mysqlimport tool or
its statement equivalent, LOAD DATA INFILE. It seems from the docs that
you must have a table created before you can import into it from a text
file. I don't know if another tool exists to do what you want.
In case that doesn;t work, how can I create the table and past the
header names into th command line, or use a text file to impoprt the
headers in somehow?
If it were me, I'd write a Perl script to parse the headers in the text
file, and generate an appropriate CREATE TABLE statement from them.
For instance:
head -1 textfile | perl -ane 'print "CREATE TABLE myTable (\n\t",
join(",\n\t", map("$_ VARCHAR(100)", @F)), "\n);\n";'
Edit the resulting CREATE TABLE statement if you want to change some of
the column defs, and then run the statement using the mysql tool.
Then use mysqlimport to load the rest of the data from the file into the
table.
Regards,
Bill K.