title: Airflow + MySQL in docker compose - Unknown host and Access denied
body: <p>newbies for airflow and mysql settings here. I am trying to set up airflow in docker-compose with MySQL as backend.</p>
  <p>I have my mySQL connection string as <code>sql_alchemy_conn_cmd=mysql://localuser:localpassword@mock_mysql/metastore</code> in <code>airflow.cfg</code></p>
  <p>I have my <code>docker-compose.yml</code> as</p>
  <pre><code>version: &quot;3.9&quot;
  networks:
    airflow:
  services:
    redis_local:
      image: redis:latest
      container_name: redis_server
      ports:
        - 6379:6379
      command: redis-server
      restart: on-failure
      networks:
        - airflow
    mysql_local:
      image: mysql:5.7
      container_name: mysql_local
      environment:
        - MYSQL_ROOT_HOST=%
        - MYSQL_USER=localuser
        - MYSQL_PASSWORD=localpassword
        - MYSQL_ROOT_PASSWORD=localpassword
        - MYSQL_DATABASE=metastore
      volumes:
        - ./script/init.sql:/data/application/init.sql
        - ./dbdata:/var/lib/mysql
      ports:
        - 3306:3306
      restart: on-failure
      healthcheck:
        test: [&quot;CMD&quot;, &quot;mysqladmin&quot; ,&quot;ping&quot;, &quot;-h&quot;, &quot;localhost&quot;]
        timeout: 1s
        retries: 10
      command:
        --init-file /data/application/init.sql
        --explicit_defaults_for_timestamp=1
      networks:
        - airflow
    airflow_init_db:
      depends_on:
        - redis_local
        - mysql_local
      container_name: airflow_init_db
      image: apache/airflow:2.0.0-python3.8
      command: airflow initdb
  
  </code></pre>
  <p>since it's connecting to the <code>metastore</code> database, it will required to set up the database in mysql when the database is starting. i have my init.sql as</p>
  <pre><code>CREATE DATABASE IF NOT EXISTS metastore;
  CREATE USER 'localuser'@'localhost' IDENTIFIED BY 'localpassword';
  GRANT ALL PRIVILEGES ON metastore . * TO 'localuser'@'localhost';
  FLUSH PRIVILEGES;
  </code></pre>
  <p>However from the healthcheck, mysql itself was failing with</p>
  <pre><code>mysql_local        | 2021-07-06T04:29:04.011037Z 3 [Note] Access denied for user 'root'@'localhost' (using password: NO)
  </code></pre>
  <p>init db and scheduler both failed with</p>
  <pre><code>sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (2005, &quot;Unknown MySQL server host 'mock_mysql' (-2)&quot;)
  </code></pre>
  <p>I wasn't really sure what are missing at this point.
  really appreciate any help!
  Thanks</p>