title: Grant Privileges to Root via Dockerfile
body: <p>Is there some way to grant all privileges to root via Dockerfile ou docker-compose.yml?
  I'm trying to boot up a mysql:latest image like this:</p>
  <p><strong>docker-compose.yml</strong></p>
  <pre><code>version: &quot;3.9&quot;
   services:
    mysql_database:
     container_name: mysql_test_server
     restart: always
     build: .
     image: mysql:latest
     command: --default-authentication-plugin=mysql_native_password
     ports:
       - 3306:3306
     volumes:
       - ./data:/var/lib/mysql
       - ./config:/etc/mysql/conf.d
    environment:
      MYSQL_ROOT_PASSWORD: root
  </code></pre>
  <p><strong>dockerfile</strong> (the build: . on .yml)</p>
  <pre><code>FROM mysql:latest
  RUN mysql -u root -proot -h localhost -p 3306
  RUN grant all privileges on *.* to 'root'@'%' identified by 'root';
  RUN flush all privileges;
  RUN exit;
  EXPOSE 3306
  </code></pre>
  <p>TLDR; I just want to grant privileges for remote connections (SQLYog, DBeaver, etc) automatically... if docker-compose up, run this command so I don't need to do manually, like <code>docker exet -it mysql_test_server mysql -u root ...</code></p>
  <p>I awalys get this:</p>
  <pre><code>ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
  </code></pre>