【发布时间】:2016-05-10 12:50:25
【问题描述】:
我正在尝试使用 MySQL 连接器作为 pymysql 的替代方案,因为它在一个查询中支持多个语句,以便我必须进行一些更新 (Here is my other question related to that) 但是对于我发送非常大的选择的其他用例来说它失败了声明。
我有一个动态生成的 Select 语句,它检索与传入的任何指定值匹配的所有行;例如Select * from table where col_a in (val_1, val_2.... val_350,000)
我的选择语句不断收到同样的错误:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mysql/connector/network.py", line 212, in send_compressed
self.sock.sendall(zip_packet)
BlockingIOError: [Errno 35] Resource temporarily unavailable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/threading.py", line 921, in _bootstrap_inner
self.run()
File "/Users/maldeiri/raw_data_processing/sql_retriever.py", line 22, in run
self.mysql_cursor.execute(self.sql_statement)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mysql/connector/cursor.py", line 515, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mysql/connector/connection.py", line 488, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mysql/connector/connection.py", line 261, in _send_cmd
packet_number)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mysql/connector/network.py", line 215, in send_compressed
errno=2055, values=(self.get_address(), _strioerror(err)))
mysql.connector.errors.OperationalError: 2055: Lost connection to MySQL server at 'database_end_point:3306', system error: 35 Resource temporarily unavailable
无论我有 compress=True 还是 False,都会发生这种情况。我也不认为这是服务器端问题,因为我提到完全相同的 Select 语句似乎正在与运行相同代码和机器的 pymysql 一起使用。
有什么想法可以解决这个问题吗?
【问题讨论】:
-
您从哪里获得参数中的 350k 值?数据库?
-
不,我有一个原始文本文件,其中包含它们(它们总是不同的),我需要从数据库中提取相应的行以使用其他原始数据进行一些转换和更新。
-
@RyanVincent 我可以,这是我的一项工作,但它添加了更多我认为不应该存在的代码。困扰我的是我知道数据库可以处理它,我知道 python 可以处理它,因为它使用 PyMYSQL 工作,所以不知道为什么它不能与连接器库一起工作令人沮丧 1) 将值分成 40,000 组 2 ) 构建 N 个查询并进行调用 3) 将结果合并在一起
-
如果每次第 3 方包裹阻碍实现目标时,我都能得到一分钱……
标签: python mysql mysql-python