MySQLdb._exceptions.OperationalError: (2006, '') when closing a SQL query. Is it because of the connection?
1
vote
1
answer
4026
views
Salut les administrateurs ! I have a question (and an issue) When closing my SQL query in my ETL I get a connection error while it seemed I was able to get connected:
c.execute("""
UPDATE
Even more there are also these lines at the beginning:
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...
So when I get a
{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)
Indeed, I get:
(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
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, '')
I thought it was when the client cannot send a query to the server, most likely because the server itself has closed the connection. However I thought there was already a connection:

MySQLdb._exceptions.OperationalError: (2006, '')
when closing a SQL query. Is it because of the connection?
Asked by Revolucion for Monica
(677 rep)
Jun 29, 2021, 09:23 AM
Last activity: May 3, 2025, 02:04 PM
Last activity: May 3, 2025, 02:04 PM