向行政长官致敬!在我的ETL中关闭SQL查询时,我有一个问题(和一个问题),当我似乎能够连接时,我会得到一个连接错误:
c.execute("""
UPDATE `{table_name}`
SET `{column_name}` = CONCAT('hash_', {expression})
WHERE {pk_name} IN ({ids})
""".format(
table_name=table_name, column_name=column_name, expression=expression, pk_name=pk_name,
ids=','.join(ids)
))
print('.', end='', flush=True)事实上,我明白:
(venv) C:\Users\antoi\Documents\Programming\Work\data-tools>python -m etl.main
2021-06-29 10:59:37.814133 - Connecting to database hozana_data...
2021-06-29 10:59:37.822142 - Connecting to archive database hozana_archive...
2021-06-29 10:59:38.046134 - Start ETL main process
2021-06-29 10:59:38.046134 - `users` table:
2021-06-29 10:59:38.046134 - Hashing column `users`.`email:` done.
2021-06-29 10:59:38.054091 - Hashing column `users`.`email_notification:`Traceback (most recent call last):
File "C:\Users\antoi\Documents\Programming\Work\data-tools\etl\task\anonymization.py", line 17, in hash_column
c.execute("""
File "C:\Users\antoi\Documents\Programming\Work\data-tools\venv\lib\site-packages\MySQLdb\cursors.py", line 183, in execute
while self.nextset():
File "C:\Users\antoi\Documents\Programming\Work\data-tools\venv\lib\site-packages\MySQLdb\cursors.py", line 137, in nextset
nr = db.next_result()
MySQLdb._exceptions.OperationalError: (2006, '')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\antoi\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\antoi\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\antoi\Documents\Programming\Work\data-tools\etl\main.py", line 52, in <module>
main()
File "C:\Users\antoi\Documents\Programming\Work\data-tools\etl\main.py", line 24, in main
anonymization.main()
File "C:\Users\antoi\Documents\Programming\Work\data-tools\etl\task\anonymization.py", line 59, in main
hash_column('users', 'email_notification', 'user_id', True)
File "C:\Users\antoi\Documents\Programming\Work\data-tools\etl\task\anonymization.py", line 50, in hash_column
print('.', end='', flush=True)
File "C:\Users\antoi\Documents\Programming\Work\data-tools\venv\lib\site-packages\MySQLdb\connections.py", line 239, in __exit__
self.close()
MySQLdb._exceptions.OperationalError: (2006, '')我认为当客户端无法向服务器发送查询时,很可能是因为服务器本身关闭了连接。然而,我认为已经有一种联系:

更多的是,在开始的时候也有这样的线条:
2021-06-29 10:59:37.814133 - Connecting to database hozana_data...
2021-06-29 10:59:37.822142 - Connecting to archive database hozana_archive...因此,当我在关闭SQL查询时得到一个MySQLdb._exceptions.OperationalError: (2006, '')时。是因为这种联系吗?
发布于 2022-03-25 06:28:01
好极了,亲爱的!
我想你忘了包括c.close()
我知道我迟到了8个月,但我猜这一错误足以满足其他人的要求
我认为您一定指定了c=mysql.connection.cursor()来建立代码c.execute。我遇到了类似的错误,我通过添加c.close()来解决
https://dba.stackexchange.com/questions/294984
复制相似问题