开发者

Can I import tab-separated files into MySQL without creating database tables first?

As the title says: I've got a bunch of tab-separated text files containing data.

I know that if I 开发者_如何学Gouse 'CREATE TABLE' statements to set up all the tables manually, I can then import them into the waiting tables, using 'load data' or 'mysqlimport'.

But is there any way in MySQL to create tables automatically based on the tab files? Seems like there ought to be. (I know that MySQL might have to guess the data type of each column, but you could specify that in the first row of the tab files.)


No, there isn't. You need to CREATE a TABLE first in any case.

Automatically creating tables and guessing field types is not part of the DBMS's job. That is a task best left to an external tool or application (That then creates the necessary CREATE statements).


If your willing to type the data types in the first row, why not type a proper CREATE TABLE statement.

Then you can export the excel data as a txt file and use

LOAD DATA INFILE 'path/file.txt' INTO TABLE your_table; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜