Skip to content

MySQL Docker environment variables

When deploying a MySQL database within a Docker container, environment variables are used to configure the root password, create specific users, and initialize databases upon the first startup.^[600-developer-docker-docker-compose-docker-compouse-02.md]

Configuration

In a docker-compose.yml file, these variables are typically defined under the environment section of the service definition.^[600-developer-docker-docker-compose-docker-compouse-02.md]

Key Variables

Common variables used to configure the MySQL container include:

  • MYSQL_ROOT_PASSWORD: This mandatory variable sets the password for the MySQL root superuser.^[600-developer-docker-docker-compose-docker-compouse-02.md]
  • MYSQL_DATABASE: This variable specifies the name of the database to be created when the image is first started.^[600-developer-docker-docker-compose-docker-compouse-02.md]
  • MYSQL_USER: Used in conjunction with MYSQL_PASSWORD, this variable creates a new user with superuser privileges specifically for the database defined by MYSQL_DATABASE.^[600-developer-docker-docker-compose-docker-compouse-02.md]
  • MYSQL_PASSWORD: Sets the password for the user created by the MYSQL_USER variable.^[600-developer-docker-docker-compose-docker-compouse-02.md]

Sources

  • 600-developer-docker-docker-compose-docker-compouse-02.md