MySQL LOAD DATA LOCAL INFILE python 中的示例?
我正在寻找语法定义、示例、示例代码、wiki 等 从 python 执行 LOAD DATA LOCAL INFILE 命令。
我相信如果可用的话我也可以使用 mysqlimport,因此欢迎任何有关更好路线的反馈(和代码片段)。 谷歌搜索并没有以当前信息的方式出现太多这
两种情况的目标都是相同的:自动加载数百个具有已知命名约定和名称的文件。 日期结构,放入单个 MySQL 表中。
大卫
I am looking for a syntax definition, example, sample code, wiki, etc. for
executing a LOAD DATA LOCAL INFILE command from python.
I believe I can use mysqlimport as well if that is available, so any feedback (and code snippet) on which is the better route, is welcome. A Google search is not turning up much in the way of current info
The goal in either case is the same: Automate loading hundreds of files with a known naming convention & date structure, into a single MySQL table.
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,使用 python 的 MySQLdb,我使用这个:
根据您的需要替换主机/用户/密码/db。 这是基于MySQL文档这里,确切的LOAD DATA INFILE 语句取决于您的具体要求等(请注意,FIELDS TERMINATED BY、ENCLOSED BY 和 ESCAPED BY 语句将特定于您尝试读入的文件类型)。
Well, using python's MySQLdb, I use this:
replacing the host/user/passwd/db as appropriate for your needs. This is based on the MySQL docs here, The exact LOAD DATA INFILE statement would depend on your specific requirements etc (note the FIELDS TERMINATED BY, ENCLOSED BY, and ESCAPED BY statements will be specific to the type of file you are trying to read in).
您还可以通过在查询后添加以下行来获取导入结果:
You can also get the results for the import by adding the following lines after your query: