并行MySQL选择请求(python) [英] MySQL select request in parallel (python)

查看:88
本文介绍了并行MySQL选择请求(python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了一个类似的帖子并行执行MySQL SELECT *查询,购买我的问题是不同的,而且这个问题也没有得到回答,所以我想这不是重复的问题.

I saw a "similar" post Executing MySQL SELECT * query in parallel, buy my question is different, and this has not been answered either, so i guess its not a duplicate.

我正在尝试并行执行一个MySQL选择请求.原因是因为我需要快速响应.当我也使连接并行时,我设法创建了请求,但是由于连接花费的时间比实际的select多,因此一次连接并并行执行select会更快.

I am trying to do a MySQL select request in parallel. The reason is because i need the response fast. I managed to create the request when i paralleled the connection as well, but as the connection takes more time then the actual select it would be faster to connect one time, and do the select in parallel.

我的方法:

import mysql.connector
import multiprocessing

def func(id):
    return GetFasta(id, cnx).sequence()

cnx = mysql.connector.connect(user='U_NAME', host='IP_ADDR', database='DB_NAME')
p = multiprocessing.Pool()

for x in p.imap_unordered(func, ["Q32P44", "ASD"]):
    print x

p.close()
p.join()
cnx.close()

GetFastaClass,它可以按预期工作,需要一个连接器和一个ID,并对其进行简单的SELECT.

The GetFasta is a Class and its working as intended, requires a connector, and an ID and does a simple SELECT with those.

如果我执行此脚本,解释器将冻结,并且我必须手动将其杀死.我猜这不是那么简单,或者不可能与一个连接器并行地select.

If i execute this script the interpreter freezes, and i have to kill it manually. I guess it is either not this trivial, or maybe impossible to select in parallel with one connector.

是吗?

有什么解决方法吗?

推荐答案

经过大量研究,我找到了解决方案".实际上是不可能的. MySQL不支持来自同一 user connection 的并行查询.这绝对是不可能的,并且没有计划添加它.

I found the "solution" after a lot of research. It is actually not possible. MySQL does not support parallel queries from the same user connection. It is absolutely impossible, and there are no plans to add this.

您能获得的最好的就是我实现它的方式,因此也要并行连接.

The best you can get is the way i implemented it, so parallel the connection as well.

在某些其他类型的数据库中也是可行的,但现在我将坚持使用MySQL并使用并行连接方法

In some other types of databases it is possible, but for now i ll stick with MySQL and use the parallel connection method

这篇关于并行MySQL选择请求(python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆