title: Can't connect to MySQL server on 'db'
body: <p>I am trying to run python backend with mysql database  in docker container locally and stumble upon the error when I run <code>docker-compose up</code> command</p>
  <blockquote>
  <p>backend_1  | django.db.utils.OperationalError: (2002, &quot;Can't connect
  to MySQL server on 'db' (115)&quot;)</p>
  </blockquote>
  <p>My <strong>Docker</strong> file:</p>
  <pre><code>FROM python:3.9
  ENV PYTHONUNBUFFERED 1
  
  WORKDIR /app
  
  COPY requirements.txt /app/requirements.txt
  RUN pip install -r requirements.txt
  
  COPY . /app
  CMD python manage.py runserver 0.0.0.0:8000
  </code></pre>
  <p><strong>docker-compose.yml</strong></p>
  <pre><code>version: '3.8'
  services:
    backend:
      restart: always
      build:
        context: .
        dockerfile: Dockerfile
      command: 'python manage.py runserver 0.0.0.0:8000'
      ports:
        - 8000:8000
      volumes:
        - .:/app
      depends_on:
        - db
      links:
        - db
  
    db:
      image: mysql:5.7.22
      restart: always
      environment:
        MYSQL_DATABASE: mysql
        MYSQL_USER: admin
        MYSQL_PASSWORD: password
        MYSQL_ROOT_PASSWORD: password
      volumes:
        - .dbdata:/var/lib/mysql
      ports:
        - 33066:3306
  </code></pre>
  <p>In settings.py</p>
  <pre><code># Database
  # https://docs.djangoproject.com/en/3.1/ref/settings/#databases
  
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.mysql',
          'NAME': 'mysql',
          'USER': 'admin',
          'PASSWORD': 'password',
          'HOST': 'db',
          'PORT': '3306',
      }
  }
  </code></pre>