title: Access denied to MySQL database in Docker
body: <p>My Docker (v.2) <code>docker-compose.yml</code> file has 2 Ubuntu images and 2 MariaDB images:</p>
  
  <pre><code>app:
      container_name: app
      image:php-apache-dev:ubuntu-16.04
      links:
        - mysql
      depends_on:
        - mysql
      ports:
        - '8443:443'
      volumes:
        - .:/app
      environment:
        docker: 'true'
        PHP_DEBUGGER: 'xdebug'
        WEB_DOCUMENT_ROOT: '/app/public'
        WEB_NO_CACHE_PATTERN: '\.(.*)$$'
        working_dir: '/app'
        CONF_FILE: 'conf/local/develop.php'
    test:
        container_name: test
        image:php-apache-dev:ubuntu-16.04
        links:
          - mysql_test
        depends_on:
          - mysql_test
        ports:
          - '8444:443'
        volumes:
          - .:/app
        environment:
          docker: 'true'
          WEB_DOCUMENT_ROOT: '/app/public'
          WEB_NO_CACHE_PATTERN: '\.(.*)$$'
          working_dir: '/app'
          CONF_FILE: 'conf/local/test.php'
    mysql:
      image: mariadb:latest
      ports:
        - '3306:3306'
      environment:
        MYSQL_ROOT_PASSWORD: 'dev'
        MYSQL_DATABASE: 'dev'
        MYSQL_USER: 'dev'
        MYSQL_PASSWORD: 'dev'
    mysql_test:
      image: mariadb:latest
      ports:
        - '3307:3306'
      environment:
        MYSQL_ROOT_PASSWORD: 'dev'
        MYSQL_DATABASE: 'dev_test'
        MYSQL_USER: 'dev'
        MYSQL_PASSWORD: 'dev'
  </code></pre>
  
  <p>One is for development, one is for testing. When I access the first one (on <code>localhost:4443</code>) it works. When I access the second one (on <code>localhost:4444</code>) I am able to view the website, but it denies access to the user:</p>
  
  <blockquote>
    <p>Access denied for user 'dev'@'%' to database 'dev_test'</p>
  </blockquote>
  
  <p>My configuration for the second site is set up to access the second MySQL port/user:</p>
  
  <pre><code>'db_port'             =&gt; env('DB_PORT', '3307'),
  'db_name'             =&gt; env('DB_NAME', 'dev_test'),
  </code></pre>
  
  <p>I tried the answer to <a href="https://stackoverflow.com/questions/37459031/connecting-to-a-docker-compose-mysql-container-denies-access-but-docker-running">this question</a> but without success. If I <code>docker exec bash</code> into the test database image, and run <code>SHOW GRANTS FOR dev</code>, it says:</p>
  
  <pre><code>GRANT ALL PRIVILEGES ON `dev_test`.* TO 'dev'@'%'
  </code></pre>