Skip to main content
6 de 7
se añadieron 100 caracteres en el cuerpo

MySQLdb._exceptions.OperationalError: (2006, '') al cerrar una consulta SQL. Es a causa de la connecion?

Al cerrar de mi consulta SQL sobre la tabla cacia user en mi ETL obtengo un error:

(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, '')

Aqui esta el ETL. Este script fue hecho cuando la biblioteca era 1.3.7 y estoy tratando de cambiar a 2.0.3:

    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)

Parece que es cuando el cliente no puede enviar una pregunta al servidor, muy probablemente porque el propio servidor ha cerrado la conexión. Sin embargo pensaba que ya habia la conexion:

introducir la descripción de la imagen aquí

Ademas hay estas lineas al principio:

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...

Intenté aumentar el max_allowed_packet:

mysql> select @@max_allowed_packet;
+----------------------+
| @@max_allowed_packet |
+----------------------+
|              4194304 |
+----------------------+
1 row in set (0.00 sec)

mysql> set global max_allowed_packet=10485760;
Query OK, 0 rows affected (0.01 sec)

Pero sigue siendo el mismo espacio:

mysql> select @@max_allowed_packet;
+----------------------+
| @@max_allowed_packet |
+----------------------+
|              4194304 |
+----------------------+
1 row in set (0.00 sec)