首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MySQLdb._exceptions.OperationalError:(2006,'')关闭SQL查询时。是因为这种联系吗?

MySQLdb._exceptions.OperationalError:(2006,'')关闭SQL查询时。是因为这种联系吗?
EN

Database Administration用户
提问于 2021-06-29 09:23:40
回答 1查看 2.3K关注 0票数 2

向行政长官致敬!在我的ETL中关闭SQL查询时,我有一个问题(和一个问题),当我似乎能够连接时,我会得到一个连接错误:

代码语言:javascript
复制
    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)

事实上,我明白:

代码语言:javascript
复制
(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, '')

我认为当客户端无法向服务器发送查询时,很可能是因为服务器本身关闭了连接。然而,我认为已经有一种联系:

更多的是,在开始的时候也有这样的线条:

代码语言:javascript
复制
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, '')时。是因为这种联系吗?

EN

回答 1

Database Administration用户

发布于 2022-03-25 06:28:01

好极了,亲爱的!

我想你忘了包括c.close()

我知道我迟到了8个月,但我猜这一错误足以满足其他人的要求

我认为您一定指定了c=mysql.connection.cursor()来建立代码c.execute。我遇到了类似的错误,我通过添加c.close()来解决

票数 0
EN
页面原文内容由Database Administration提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://dba.stackexchange.com/questions/294984

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档