我在python 3中使用pymysql运行查询,类似于:
conn = 'con info here'
cur = conn.cursor()
cu.execute('sql goes here')
该查询属于以下行:
load data
local infile 'file path'
ignore into table table_name
fields terminated by '/t'
optionally enclosed by '"'
lines terminated by '\r\n'
ignore 1 lines
(@col1,
@col2,
@col3)
set
(col1indb = @col1,
col2indb = @col2,
col3indb = @col3)
当我执行查询时,我立即得到这个:
File "/opt/python3/lib/python3.4/site-packages/pymysql/cursors.py", line 296, in _query
conn.query(q)
File "/opt/python3/lib/python3.4/site-packages/pymysql/connections.py", line 781, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/opt/python3/lib/python3.4/site-packages/pymysql/connections.py", line 942, in _read_query_result
result.read()
File "/opt/python3/lib/python3.4/site-packages/pymysql/connections.py", line 1143, in read
self._read_load_local_packet(first_packet)
File "/opt/python3/lib/python3.4/site-packages/pymysql/connections.py", line 1178, in _read_load_local_packet
sender.send_data()
File "/opt/python3/lib/python3.4/site-packages/pymysql/connections.py", line 1317, in send_data
self.connection._write_bytes(packet)
File "/opt/python3/lib/python3.4/site-packages/pymysql/connections.py", line 929, in _write_bytes
raise err.OperationalError(2006, "MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
由于错误立即发生,我确信它不是超时。我运行的每一个其他查询都可以正常工作,甚至类似的加载查询。
我的问题是,MySQL语法中的哪些内容会导致此错误?
谢谢!
答案 0 :(得分:0)
我对pymysql,python3.5和远程MySQL服务器有同样的问题。当我尝试插入一个包含巨大LONGTEXT字段的条目(例如man gcc 4次)时,它将回答相同的错误:MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))
。当我只使用短文本行时,它很有效,例如" HELLO WORLD"。