简体   繁体   English

使用游标使用Python访问MySQL数据库?

[英]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? 有更好的解决方案吗?

The cursor object is a required part of the Python DB API . 游标对象是Python DB API的必需部分。 All database library implementations will do it this way. 所有数据库库实现都会这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Cursor的Python MS Access数据库并在不使用unicode的情况下显示 - Python MS Access database using Cursor and display without unicode 使用Python将检索到的游标从一个MySQL数据库传递到另一个MySQL数据库 - Pass retrieved cursor from one MySQL database to another MySQL database using Python 使用 optuna 从 python 成功访问 MySQL 数据库 - Successfully access MySQL database from python using optuna 使用Python远程访问mySQL - Remote access to mySQL using Python 使用python连接MySQL数据库 - Connect to MySQL database using python 如何加密 AWS RDS MySql 数据库以及如何在 Python 中使用 SSL 访问该加密数据库? - How to a encryption to a AWS RDS MySql database and how to access that encrypted database using SSL in Python? 在python中使用cursor.callproc()调用MySQL存储过程 - Call MySQL stored procedure using cursor.callproc() in python 如何使用Python将光标移动到MySQL中的最后一条记录? - How to move my cursor to the last record in MySQL using Python? Python / MySQL:在插入行之前和之后使用cursor.rowcount - Python/MySQL: using cursor.rowcount before and after inserting a row 任何使用python访问DAYWISE Facebook广告洞察并将响应数据添加到mysql数据库表的方法? - Any way to access DAYWISE Facebook ad insights using python and add the response data to an mysql database table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM