title: Getting OperationalError: (2000, 'Unknown MySQL error') when accessing mysql database using celery and django
body: <p>I am using celery with my django application. My application works fine with mysql database, but I am getting <code>(2000, 'Unknown MySQL error')</code> when celery tries to access the database. This happens only when I run celery in a container, when I run it in my ubuntu machine, it works fine.</p>
  <p>This is the error that I am getting:</p>
  <pre><code>[2022-06-18 13:39:33,717: ERROR/ForkPoolWorker-1] Task taskMonitor.tasks.monitor[7e6696aa-d602-4336-a582-4c719f8d72df] raised unexpected: OperationalError(2000, 'Unknown MySQL error')
  Traceback (most recent call last):
    File &quot;/.venv/lib/python3.9/site-packages/django/db/backends/utils.py&quot;, line 89, in _execute
      return self.cursor.execute(sql, params)
    File &quot;/.venv/lib/python3.9/site-packages/django/db/backends/mysql/base.py&quot;, line 75, in execute
      return self.cursor.execute(query, args)
    File &quot;/.venv/lib/python3.9/site-packages/MySQLdb/cursors.py&quot;, line 206, in execute
      res = self._query(query)
    File &quot;/.venv/lib/python3.9/site-packages/MySQLdb/cursors.py&quot;, line 319, in _query
      db.query(q)
    File &quot;/.venv/lib/python3.9/site-packages/MySQLdb/connections.py&quot;, line 254, in query
      _mysql.connection.query(self, query)
  MySQLdb._exceptions.OperationalError: (2000, 'Unknown MySQL error')
  
  The above exception was the direct cause of the following exception:
  
  Traceback (most recent call last):
    File &quot;/.venv/lib/python3.9/site-packages/celery/app/trace.py&quot;, line 451, in trace_task
      R = retval = fun(*args, **kwargs)
    File &quot;/.venv/lib/python3.9/site-packages/celery/app/trace.py&quot;, line 734, in __protected_call__
      return self.run(*args, **kwargs)
    File &quot;/app/taskMonitor/tasks.py&quot;, line 18, in monitor
      for obj in objs.iterator():
    File &quot;/.venv/lib/python3.9/site-packages/django/db/models/query.py&quot;, line 401, in _iterator
      yield from self._iterable_class(
    File &quot;/.venv/lib/python3.9/site-packages/django/db/models/query.py&quot;, line 57, in __iter__
      results = compiler.execute_sql(
    File &quot;/.venv/lib/python3.9/site-packages/django/db/models/sql/compiler.py&quot;, line 1361, in execute_sql
      cursor.execute(sql, params)
    File &quot;/.venv/lib/python3.9/site-packages/django/db/backends/utils.py&quot;, line 103, in execute
      return super().execute(sql, params)
    File &quot;/.venv/lib/python3.9/site-packages/django/db/backends/utils.py&quot;, line 67, in execute
      return self._execute_with_wrappers(
    File &quot;/.venv/lib/python3.9/site-packages/django/db/backends/utils.py&quot;, line 80, in _execute_with_wrappers
      return executor(sql, params, many, context)
    File &quot;/.venv/lib/python3.9/site-packages/django/db/backends/utils.py&quot;, line 89, in _execute
      return self.cursor.execute(sql, params)
    File &quot;/.venv/lib/python3.9/site-packages/django/db/utils.py&quot;, line 91, in __exit__
      raise dj_exc_value.with_traceback(traceback) from exc_value
    File &quot;/.venv/lib/python3.9/site-packages/django/db/backends/utils.py&quot;, line 89, in _execute
      return self.cursor.execute(sql, params)
    File &quot;/.venv/lib/python3.9/site-packages/django/db/backends/mysql/base.py&quot;, line 75, in execute
      return self.cursor.execute(query, args)
    File &quot;/.venv/lib/python3.9/site-packages/MySQLdb/cursors.py&quot;, line 206, in execute
      res = self._query(query)
    File &quot;/.venv/lib/python3.9/site-packages/MySQLdb/cursors.py&quot;, line 319, in _query
      db.query(q)
    File &quot;/.venv/lib/python3.9/site-packages/MySQLdb/connections.py&quot;, line 254, in query
      _mysql.connection.query(self, query)
  django.db.utils.OperationalError: (2000, 'Unknown MySQL error')
  </code></pre>