我可以在不先创建数据库表的情况下将制表符分隔的文件导入 MySQL 吗?

发布于 2024-08-19 23:32:58 字数 204 浏览 4 评论 0原文

正如标题所说:我有一堆包含数据的制表符分隔的文本文件。

我知道,如果我使用“CREATE TABLE”语句手动设置所有表,然后我可以使用“load data”或“mysqlimport”将它们导入等待表中。

但是MySQL有没有办法根据tab文件自动创建表呢?好像应该有。 (我知道 MySQL 可能必须猜测每列的数据类型,但您可以在选项卡文件的第一行中指定。)

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

I know that if I use '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.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静若繁花 2024-08-26 23:32:58

不,没有。无论如何,您都需要首先CREATE一个TABLE

自动创建表和猜测字段类型不是 DBMS 工作的一部分。该任务最好留给外部工具或应用程序(然后创建必要的 CREATE 语句)。

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).

暗恋未遂 2024-08-26 23:32:58

如果您愿意在第一行中键入数据类型,为什么不键入正确的 CREATE TABLE 语句。

然后你可以将excel数据导出为txt文件并使用

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

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; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文