title: Docker MySQL: create new user
body: <p>In the <a href="https://hub.docker.com/_/mysql/" rel="nofollow">mysql docker hub page</a> there's a reference on how to create users with:</p>
  
  <pre><code>MYSQL_USER, MYSQL_PASSWORD
  </code></pre>
  
  <p>But how can you specify those parameters on the docker-compose.yml file?</p>
  
  <p>So far I have:</p>
  
  <pre><code>mysql:
    image: mysql:5.7
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: R00t+
  </code></pre>
  
  <p>Another question; how can I connect to the mysql host from outside the container? Inside the container I can connect using:</p>
  
  <pre><code>$user = 'root';
  $pass = 'R00t+';
  $server = 'mysql';
  
  $dbh = new PDO( "mysql:host=$server", $user, $pass );
  </code></pre>