Possible Duplicate:
Generate table schema inspecting Excel(CSV) and import data
我正在开发一个根据输入自动创建 MySQL 表的工具。
例如。
输入
Y|abc|123|1.12|2012-12-20 00:00:00
输出
CREATE TABLE MyTable (
is_enabed char(1),
call_sign varchar(8),
facility_id tinyint(4),
bounds decimal(4,2)
created_time datetime
) ENGINE=MyISAM DEFAULT CHARSET=latin1
我现在有一个用 Python 编写的准工作原型(prototype)。在深入研究之前,我想看看是否已经存在类似的项目(免费、开源)。如果是这样,我的努力可能会更好地花在研究该项目上,而不是不知疲倦地重新发明轮子。
最佳答案
Generate table schema inspecting Excel(CSV) and import data
这个问题(以及最上面的回复,提到xlrd
)已经讨论了这个主题。
事实上,MySQL 显然内置了这样的函数:
https://dev.mysql.com/doc/refman/5.0/en/procedure-analyse.html
ANALYSE() examines the result from a query and returns an analysis of the results that suggests optimal data types for each column that may help reduce table sizes.
关于python - 从输入/文件自动创建 MySQL 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12992796/