[英]Using a cursor to access a MySQL database using Python?
I'm in the process of writing a simple Python script which grabs some data from an API and inserts it into my database. 我正在编写一个简单的Python脚本,它从API中获取一些数据并将其插入到我的数据库中。 I would use a language I'm more familiar with, but as far as I'm aware, the API I'm working with is only accessible in Python.
我会使用一种我更熟悉的语言,但据我所知,我正在使用的API只能在Python中访问。
Naturally, I'm now at the step where I need to insert the data into my database. 当然,我现在正处于需要将数据插入数据库的步骤。 Most documentation and references I've read seem to prefer to use the
mysqldb
package. 我读过的大多数文档和参考资料似乎都更喜欢 使用
mysqldb
包。
At a glance, this package appears to involve the use of cursors. 乍一看,这个软件包似乎涉及使用游标。
However, I've always heard that cursors are bad for a variety of reasons, mainly related to table locking, and excessive memory consumption. 但是,我总是听说游标因各种原因都很糟糕 ,主要与表锁定和内存消耗过多有关。
Considering at the same time as this Python script will be updating my database, there will be concurrent read requests on my database, should I be using the mysqldb
to access my database or not? 考虑到这个Python脚本将同时更新我的数据库,我的数据库上会有并发读取请求,我是否应该使用
mysqldb
来访问我的数据库? Is there a better solution? 有更好的解决方案吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.