title: Access denied for user 'root'@'localhost' (using password: YES) when connecting from golang mysql to mysql container
body: <p>I have 2 containers, one for the main logic in my app and another for a mysql db. This is the docker-compose file</p>
  <pre><code>version: '3'
  services:
      database:
          image: mysql
          container_name: mysql-db
          command: --default-authentication-plugin=mysql_native_password
          restart: always
          env_file:
            - environment-variables.env
          ports:
            - 3306:3306
      logic:
          container_name: main-logic
          build: ./logic/.
  </code></pre>
  <p>The logic is in golang and I am attempting to connect to the database. Here is the go code.</p>
  <pre><code>    err := godotenv.Load(&quot;/environment-variables.env&quot;)
      if err != nil {
          log.Fatalln(&quot;Error in fetching environment variables&quot;, err)
      }
      dataSourceName := fmt.Sprint(&quot;root:&quot;, os.Getenv(&quot;MYSQL_ROOT_PASSWORD&quot;), &quot;@tcp(docker.for.mac.localhost:3306)/some-db&quot;)
      log.Println(dataSourceName)
      db, err := sql.Open(&quot;mysql&quot;, dataSourceName)
      if err != nil {
          log.Fatalln(&quot;Some error in connecting to the database in the method&quot;, err)
      }
      db.SetMaxOpenConns(1)
      err = db.Ping()
      log.Println(&quot;Error is&quot;, err.Error())
      defer db.Close()
  </code></pre>
  <p>Within the environment variables file is</p>
  <pre><code>MYSQL_ROOT_PASSWORD=password
  MYSQL_DATABASE=some-db
  </code></pre>
  <p>When I attempt to connect, I always get the error:</p>
  <pre><code>Error is Error 1045: Access denied for user 'root'@'localhost' (using password: YES)
  </code></pre>
  <p>How to resolve this?</p>