<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="docker-mysql-more-topics">
      </a>
      2.5.6.2 More Topics on Deploying MySQL Server with Docker
     </h4>
    </div>
   </div>
  </div>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    Most of the following sample commands have
    <code class="literal">
     container-registry.oracle.com/mysql/community-server
    </code>
    as the Docker image being used (like with the
    <span class="command">
     <strong>
      docker
          pull
     </strong>
    </span>
    and
    <span class="command">
     <strong>
      docker run
     </strong>
    </span>
    commands);
          change that if your image is from another repository—for
          example, replace it with
    <code class="literal">
     container-registry.oracle.com/mysql/enterprise-server
    </code>
    for MySQL Enterprise Edition images downloaded from the Oracle Container Registry
          (OCR), or
    <code class="literal">
     mysql/enterprise-server
    </code>
    for MySQL Enterprise Edition
          images downloaded from
    <a class="ulink" href="https://support.oracle.com/" target="_blank">
     My Oracle
          Support
    </a>
    .
   </p>
  </div>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="xref" href="docker-mysql-more-topics.html#docker-optimized-installation" title="The Optimized MySQL Installation for Docker">
       The Optimized MySQL Installation for Docker
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="docker-mysql-more-topics.html#docker-configuring-server" title="Configuring the MySQL Server">
       Configuring the MySQL Server
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="docker-mysql-more-topics.html#docker-persisting-data-configuration" title="Persisting Data and Configuration Changes">
       Persisting Data and Configuration Changes
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="docker-mysql-more-topics.html#docker-additional-init" title="Running Additional Initialization Scripts">
       Running Additional Initialization Scripts
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="docker-mysql-more-topics.html#docker-app-in-another-container" title="Connect to MySQL from an Application in Another Docker Container">
       Connect to MySQL from an Application in Another Docker Container
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="docker-mysql-more-topics.html#docker-server-error-log" title="Server Error Log">
       Server Error Log
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="docker-mysql-more-topics.html#docker-meb" title="Using MySQL Enterprise Backup with Docker">
       Using MySQL Enterprise Backup with Docker
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="docker-mysql-more-topics.html#docker-mysqldump" title="Using mysqldump with Docker">
       Using mysqldump with Docker
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="docker-mysql-more-topics.html#docker-known-issues" title="Known Issues">
       Known Issues
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="docker-mysql-more-topics.html#docker-environment-variables" title="Docker Environment Variables">
       Docker Environment Variables
      </a>
     </p>
    </li>
   </ul>
  </div>
  <h5>
   <a name="docker-optimized-installation">
   </a>
   The Optimized MySQL Installation for Docker
  </h5>
  <p>
   Docker images for MySQL are optimized for code size, which means
        they only include crucial components that are expected to be
        relevant for the majority of users who run MySQL instances in
        Docker containers. A MySQL Docker installation is different from
        a common, non-Docker installation in the following aspects:
  </p>
  <p>
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Only a limited number of binaries are included.
     </p>
    </li>
    <li class="listitem">
     <p>
      All binaries are stripped; they contain no debug
              information.
     </p>
    </li>
   </ul>
  </div>
  <p>
  </p>
  <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Warning
   </div>
   <p>
    Any software updates or installations users perform to the
          Docker container (including those for MySQL components) may
          conflict with the optimized MySQL installation created by the
          Docker image. Oracle does not provide support for MySQL
          products running in such an altered container, or a container
          created from an altered Docker image.
   </p>
  </div>
  <h5>
   <a name="docker-configuring-server">
   </a>
   Configuring the MySQL Server
  </h5>
  <p>
   When you start the MySQL Docker container, you can pass
        configuration options to the server through the
   <span class="command">
    <strong>
     docker
        run
    </strong>
   </span>
   command. For example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa10145275"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">docker run <span class="token property">--name</span> mysql1 <span class="token property">-d</span> container-registry<span class="token punctuation">.</span>oracle<span class="token punctuation">.</span>com/mysql/community-server<span class="token punctuation">:</span><em class="replaceable">tag</em> <span class="token constant">--character-set-server</span><span class="token attr-value"><span class="token punctuation">=</span>utf8mb4</span> <span class="token constant">--collation-server</span><span class="token attr-value"><span class="token punctuation">=</span>utf8mb4_col</span></code></pre>
  </div>
  <p>
   The command starts the MySQL Server with
   <code class="literal">
    utf8mb4
   </code>
   as the default character set and
   <code class="literal">
    utf8mb4_col
   </code>
   as the default collation for
        databases.
  </p>
  <p>
   Another way to configure the MySQL Server is to prepare a
        configuration file and mount it at the location of the server
        configuration file inside the container. See
   <a class="xref" href="docker-mysql-more-topics.html#docker-persisting-data-configuration" title="Persisting Data and Configuration Changes">
    Persisting Data and Configuration Changes
   </a>
   for
        details.
  </p>
  <h5>
   <a name="docker-persisting-data-configuration">
   </a>
   Persisting Data and Configuration Changes
  </h5>
  <p>
   Docker containers are in principle ephemeral, and any data or
        configuration are expected to be lost if the container is
        deleted or corrupted (see discussions
   <a class="ulink" href="https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/" target="_blank">
    here
   </a>
   ).
   <a class="ulink" href="https://docs.docker.com/engine/admin/volumes/volumes/" target="_blank">
    Docker
        volumes
   </a>
   provides a mechanism to persist data created
        inside a Docker container. At its initialization, the MySQL
        Server container creates a Docker volume for the server data
        directory. The JSON output from the
   <span class="command">
    <strong>
     docker
        inspect
    </strong>
   </span>
   command on the container includes a
   <code class="literal">
    Mount
   </code>
   key, whose value provides information
        on the data directory volume:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa82076562"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">docker</span> inspect mysql1
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
 <span class="token atrule">"Mounts"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token inlinejson">            <span class="token punctuation">{</span>
                <span class="token property">"Type"</span><span class="token operator">:</span> <span class="token string">"volume"</span><span class="token punctuation">,</span>
                <span class="token property">"Name"</span><span class="token operator">:</span> <span class="token string">"4f2d463cfc4bdd4baebcb098c97d7da3337195ed2c6572bc0b89f7e845d27652"</span><span class="token punctuation">,</span>
                <span class="token property">"Source"</span><span class="token operator">:</span> <span class="token string">"/var/lib/docker/volumes/4f2d463cfc4bdd4baebcb098c97d7da3337195ed2c6572bc0b89f7e845d27652/_data"</span><span class="token punctuation">,</span>
                <span class="token property">"Destination"</span><span class="token operator">:</span> <span class="token string">"/var/lib/mysql"</span><span class="token punctuation">,</span>
                <span class="token property">"Driver"</span><span class="token operator">:</span> <span class="token string">"local"</span><span class="token punctuation">,</span>
                <span class="token property">"Mode"</span><span class="token operator">:</span> <span class="token string">""</span><span class="token punctuation">,</span>
                <span class="token property">"RW"</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
                <span class="token property">"Propagation"</span><span class="token operator">:</span> <span class="token string">""</span>
            <span class="token punctuation">}</span></span>
        <span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
  </div>
  <p>
   The output shows that the source directory
   <code class="filename">
    /var/lib/docker/volumes/4f2d463cfc4bdd4baebcb098c97d7da3337195ed2c6572bc0b89f7e845d27652/_data
   </code>
   ,
        in which data is persisted on the host, has been mounted at
   <code class="filename">
    /var/lib/mysql
   </code>
   , the server data directory
        inside the container.
  </p>
  <p>
   Another way to preserve data is to
   <a class="ulink" href="https://docs.docker.com/engine/reference/commandline/service_create/#add-bind-mounts-volumes-or-memory-filesystems" target="_blank">
    bind-mount
   </a>
   a host directory using the
   <code class="option">
    --mount
   </code>
   option when
        creating the container. The same technique can be used to
        persist the configuration of the server. The following command
        creates a MySQL Server container and bind-mounts both the data
        directory and the server configuration file:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa12138508"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">docker run <span class="token constant">--name</span><span class="token attr-value"><span class="token punctuation">=</span>mysql1</span> \
<span class="token property">--mount</span> type<span class="token attr-value"><span class="token punctuation">=</span>bind,src=</span><em class="replaceable"><span class="token attr-value">/path</span><span class="token constant">-on-host-machine/my.cnf</span></em><span class="token constant">,dst</span><span class="token attr-value"><span class="token punctuation">=</span>/etc/my.cnf</span> \
<span class="token property">--mount</span> type<span class="token attr-value"><span class="token punctuation">=</span>bind,src=</span><em class="replaceable"><span class="token attr-value">/path</span><span class="token constant">-on-host-machine/datadir</span></em><span class="token constant">,dst</span><span class="token attr-value"><span class="token punctuation">=</span>/var/lib/mysql</span> \
<span class="token property">-d</span> container-registry<span class="token punctuation">.</span>oracle<span class="token punctuation">.</span>com/mysql/community-server<span class="token punctuation">:</span><em class="replaceable">tag</em></code></pre>
  </div>
  <p>
   The command mounts
   <code class="filename">
    <em class="replaceable">
     <code>
      path-on-host-machine/my.cnf
     </code>
    </em>
   </code>
   at
   <code class="filename">
    <code class="filename">
     /etc/my.cnf
    </code>
   </code>
   (the
        server configuration file inside the container), and
   <code class="filename">
    <em class="replaceable">
     <code>
      path-on-host-machine/datadir
     </code>
    </em>
   </code>
   at
   <code class="filename">
    /var/lib/mysql
   </code>
   (the data directory
        inside the container). The following conditions must be met for
        the bind-mounting to work:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      The configuration file
      <code class="filename">
       <em class="replaceable">
        <code>
         path-on-host-machine/my.cnf
        </code>
       </em>
      </code>
      must already exist, and it must contain the specification
              for starting the server by the user
      <code class="literal">
       mysql
      </code>
      :
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa46894309"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-ini"><span class="token selector">[mysqld]</span>
<span class="token constant">user</span><span class="token attr-value"><span class="token punctuation">=</span>mysql</span></code></pre>
     </div>
     <p>
      You can also include other server configuration options in
              the file.
     </p>
    </li>
    <li class="listitem">
     <p>
      The data directory
      <code class="filename">
       <em class="replaceable">
        <code>
         path-on-host-machine/datadir
        </code>
       </em>
      </code>
      must already exist. For server initialization to happen,
              the directory must be empty. You can also mount a
              directory prepopulated with data and start the server with
              it; however, you must make sure you start the Docker
              container with the same configuration as the server that
              created the data, and any host files or directories
              required are mounted when starting the container.
     </p>
    </li>
   </ul>
  </div>
  <p>
  </p>
  <h5>
   <a name="docker-additional-init">
   </a>
   Running Additional Initialization Scripts
  </h5>
  <p>
   If there are any
   <code class="filename">
    .sh
   </code>
   or
   <code class="filename">
    .sql
   </code>
   scripts you want to run on the
        database immediately after it has been created, you can put them
        into a host directory and then mount the directory at
   <code class="filename">
    /docker-entrypoint-initdb.d/
   </code>
   inside the
        container. For example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa62518177"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">docker run <span class="token constant">--name</span><span class="token attr-value"><span class="token punctuation">=</span>mysql1</span> \
<span class="token property">--mount</span> type<span class="token attr-value"><span class="token punctuation">=</span>bind,src=</span><em class="replaceable"><span class="token attr-value">/path</span><span class="token constant">-on-host-machine/scripts/</span></em><span class="token constant">,dst</span><span class="token attr-value"><span class="token punctuation">=</span>/docker-entrypoint-initdb.d/</span> \
<span class="token property">-d</span> container-registry<span class="token punctuation">.</span>oracle<span class="token punctuation">.</span>com/mysql/community-server<span class="token punctuation">:</span><em class="replaceable">tag</em></code></pre>
  </div>
  <h5>
   <a name="docker-app-in-another-container">
   </a>
   Connect to MySQL from an Application in Another Docker Container
  </h5>
  <p>
   By setting up a Docker network, you can allow multiple Docker
        containers to communicate with each other, so that a client
        application in another Docker container can access the MySQL
        Server in the server container. First, create a Docker network:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa61407296"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">docker network create <em class="replaceable">my-custom-net</em></code></pre>
  </div>
  <p>
   Then, when you are creating and starting the server and the
        client containers, use the
   <code class="option">
    --network
   </code>
   option to
        put them on network you created. For example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa39882164"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">docker run <span class="token constant">--name</span><span class="token attr-value"><span class="token punctuation">=</span>mysql1</span> <span class="token constant">--network</span><span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">my-custom-net</em></span> <span class="token property">-d</span> container-registry<span class="token punctuation">.</span>oracle<span class="token punctuation">.</span>com/mysql/community-server</code></pre>
  </div>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa31617757"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">docker run <span class="token constant">--name</span><span class="token attr-value"><span class="token punctuation">=</span>myapp1</span> <span class="token constant">--network</span><span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">my-custom-net</em></span> <span class="token property">-d</span> myapp</code></pre>
  </div>
  <p>
   The
   <code class="literal">
    myapp1
   </code>
   container can then connect to the
   <code class="literal">
    mysql1
   </code>
   container with the
   <code class="literal">
    mysql1
   </code>
   hostname and vice versa, as Docker
        automatically sets up a DNS for the given container names. In
        the following example, we run the
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   client from inside the
   <code class="literal">
    myapp1
   </code>
   container to
        connect to host
   <code class="literal">
    mysql1
   </code>
   in its own container:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa55511078"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">docker exec <span class="token property">-it</span> myapp1 mysql <span class="token constant">--host</span><span class="token attr-value"><span class="token punctuation">=</span>mysql1</span> <span class="token constant">--user</span><span class="token attr-value"><span class="token punctuation">=</span>myuser</span> <span class="token property">--password</span></code></pre>
  </div>
  <p>
   For other networking techniques for containers, see the
   <a class="ulink" href="https://docs.docker.com/engine/userguide/networking/" target="_blank">
    Docker
        container networking
   </a>
   section in the Docker
        Documentation.
  </p>
  <h5>
   <a name="docker-server-error-log">
   </a>
   Server Error Log
  </h5>
  <p>
   When the MySQL Server is first started with your server
        container, a
   <a class="link" href="error-log.html" title="7.4.2 The Error Log">
    server error log
   </a>
   is NOT generated if either of the following conditions is true:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      A server configuration file from the host has been mounted,
            but the file does not contain the system variable
      <a class="link" href="server-system-variables.html#sysvar_log_error">
       <code class="literal">
        log_error
       </code>
      </a>
      (see
      <a class="xref" href="docker-mysql-more-topics.html#docker-persisting-data-configuration" title="Persisting Data and Configuration Changes">
       Persisting Data and Configuration Changes
      </a>
      on
            bind-mounting a server configuration file).
     </p>
    </li>
    <li class="listitem">
     <p>
      A server configuration file from the host has not been
            mounted, but the Docker environment variable
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql-log-console">
       <code class="option">
        MYSQL_LOG_CONSOLE
       </code>
      </a>
      is
      <code class="literal">
       true
      </code>
      (which is the variable's default
            state for MySQL 8.4 server containers). The
            MySQL Server's error log is then redirected to
      <code class="literal">
       stderr
      </code>
      , so that the error log goes into
            the Docker container's log and is viewable using the
      <span class="command">
       <strong>
        docker logs
        <em class="replaceable">
         <code>
          mysqld-container
         </code>
        </em>
       </strong>
      </span>
      command.
     </p>
    </li>
   </ul>
  </div>
  <p>
   To make MySQL Server generate an error log when either of the
        two conditions is true, use the
   <a class="link" href="server-options.html#option_mysqld_log-error">
    <code class="option">
     --log-error
    </code>
   </a>
   option to
   <a class="link" href="docker-mysql-more-topics.html#docker-configuring-server" title="Configuring the MySQL Server">
    configure the
        server
   </a>
   to generate the error log at a specific location
        inside the container. To persist the error log, mount a host
        file at the location of the error log inside the container as
        explained in
   <a class="xref" href="docker-mysql-more-topics.html#docker-persisting-data-configuration" title="Persisting Data and Configuration Changes">
    Persisting Data and Configuration Changes
   </a>
   . However,
        you must make sure your MySQL Server inside its container has
        write access to the mounted host file.
  </p>
  <h5>
   <a name="docker-meb">
   </a>
   Using MySQL Enterprise Backup with Docker
  </h5>
  <p>
   <a class="link" href="mysql-enterprise-backup.html" title="32.1 MySQL Enterprise Backup Overview">
    MySQL Enterprise Backup
   </a>
   is a
        commercially-licensed backup utility for MySQL Server, available
        with
   <a class="ulink" href="https://www.mysql.com/products/enterprise/" target="_blank">
    MySQL Enterprise Edition
   </a>
   .
        MySQL Enterprise Backup is included in the Docker installation of MySQL Enterprise Edition.
  </p>
  <p>
   In the following example, we assume that you already have a
        MySQL Server running in a Docker container (see
   <a class="xref" href="docker-mysql-getting-started.html" title="2.5.6.1 Basic Steps for MySQL Server Deployment with Docker">
    Section 2.5.6.1, “Basic Steps for MySQL Server Deployment with Docker”
   </a>
   on how to start a
        MySQL Server instance with Docker). For MySQL Enterprise Backup to back up the
        MySQL Server, it must have access to the server's data
        directory. This can be achieved by, for example,
   <a class="link" href="docker-mysql-more-topics.html#docker-persisting-data-configuration" title="Persisting Data and Configuration Changes">
    bind-mounting
        a host directory on the data directory of the MySQL
        Server
   </a>
   when you start the server:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa17902398"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">docker run <span class="token constant">--name</span><span class="token attr-value"><span class="token punctuation">=</span>mysqlserver</span> \
<span class="token property">--mount</span> type<span class="token attr-value"><span class="token punctuation">=</span>bind,src=</span><em class="replaceable"><span class="token attr-value">/path</span><span class="token constant">-on-host-machine/datadir/</span></em><span class="token constant">,dst</span><span class="token attr-value"><span class="token punctuation">=</span>/var/lib/mysql</span> \
<span class="token property">-d</span> mysql/enterprise-server<span class="token punctuation">:</span>8<span class="token punctuation">.</span>4</code></pre>
  </div>
  <p>
  </p>
  <p>
   With this command, the MySQL Server is started with a Docker
        image of the MySQL Enterprise Edition, and the host directory
   <em class="replaceable">
    <code>
     /path-on-host-machine/datadir/
    </code>
   </em>
   has
        been mounted onto the server's data directory
        (
   <code class="filename">
    /var/lib/mysql
   </code>
   ) inside the server
        container. We also assume that, after the server has been
        started, the required privileges have also been set up for MySQL Enterprise Backup
        to access the server (see
   <a class="ulink" href="/doc/mysql-enterprise-backup/8.4/en/mysqlbackup.privileges.html" target="_top">
    Grant MySQL Privileges to Backup Administrator
   </a>
   , for details). Use the
        following steps to back up and restore a MySQL Server instance.
  </p>
  <p>
   To back up a MySQL Server instance running in a Docker container
        using MySQL Enterprise Backup with Docker, follow the steps listed here:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      On the same host where the MySQL Server container is
            running, start another container with an image of MySQL Enterprise Edition to
            perform a back up with the MySQL Enterprise Backup command
      <a class="ulink" href="/doc/mysql-enterprise-backup/8.4/en/backup-commands-backup.html#option_meb_backup-to-image" target="_top">
       <code class="option">
        backup-to-image
       </code>
      </a>
      . Provide access
            to the server's data directory using the bind mount we
            created in the last step. Also, mount a host directory
            (
      <em class="replaceable">
       <code>
        /path-on-host-machine/backups/
       </code>
      </em>
      in this example) onto the storage folder for backups in the
            container (
      <code class="filename">
       /data/backups
      </code>
      in the
            example) to persist the backups we are creating. Here is a
            sample command for this step, in which MySQL Enterprise Backup is started with
            a Docker image downloaded from
      <a class="ulink" href="https://support.oracle.com/" target="_blank">
       My
            Oracle Support
      </a>
      :
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa97012680"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">docker</span> run \
<span class="token property">--mount</span> type<span class="token attr-value"><span class="token punctuation">=</span>bind,src=</span><em class="replaceable"><span class="token attr-value">/path</span><span class="token constant">-on-host-machine/datadir/</span></em><span class="token constant">,dst</span><span class="token attr-value"><span class="token punctuation">=</span>/var/lib/mysql</span> \
<span class="token property">--mount</span> type<span class="token attr-value"><span class="token punctuation">=</span>bind,src=</span><em class="replaceable"><span class="token attr-value">/path</span><span class="token constant">-on-host-machine/backups/</span></em><span class="token constant">,dst</span><span class="token attr-value"><span class="token punctuation">=</span>/data/backups</span> \
<span class="token property">--rm</span> mysql/enterprise-server<span class="token punctuation">:</span>8<span class="token punctuation">.</span>4 \
mysqlbackup <span class="token property">-u<em class="replaceable">mysqlbackup</em></span> <span class="token property">-p<em class="replaceable">password</em></span> <span class="token constant">--backup-dir</span><span class="token attr-value"><span class="token punctuation">=</span>/tmp/backup-tmp</span> <span class="token property">--with-timestamp</span> \
<span class="token constant">--backup-image</span><span class="token attr-value"><span class="token punctuation">=</span>/data/backups/db.mbi</span> backup-to-image</code></pre>
     </div>
     <p>
      It is important to check the end of the output by
      <span class="command">
       <strong>
        mysqlbackup
       </strong>
      </span>
      to make sure the backup has
            been completed successfully.
     </p>
    </li>
    <li class="listitem">
     <p>
      The container exits once the backup job is finished and,
            with the
      <code class="literal">
       --rm
      </code>
      option used to start it, it
            is removed after it exits. An image backup has been created,
            and can be found in the host directory mounted in the last
            step for storing backups, as shown here:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa1017724"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">ls</span> /tmp/backups
db<span class="token punctuation">.</span>mbi</code></pre>
     </div>
     <p>
     </p>
    </li>
   </ol>
  </div>
  <p>
   To restore a MySQL Server instance in a Docker container using
        MySQL Enterprise Backup with Docker, follow the steps listed here:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      Stop the MySQL Server container, which also stops the MySQL
            Server running inside:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa52553183"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">docker stop mysqlserver</code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      On the host, delete all contents in the bind mount for the
            MySQL Server data directory:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa67121652"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">rm <span class="token property">-rf</span> <em class="replaceable">/path-on-host-machine/datadir</em>/*</code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      Start a container with an image of MySQL Enterprise Edition to perform the
            restore with the MySQL Enterprise Backup command
      <a class="ulink" href="/doc/mysql-enterprise-backup/8.4/en/backup-commands-restore.html#option_meb_copy-back-and-apply-log" target="_top">
       <code class="option">
        copy-back-and-apply-log
       </code>
      </a>
      .
            Bind-mount the server's data directory and the storage
            folder for the backups, like what we did when we backed up
            the server:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa4980852"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">docker</span> run \
<span class="token property">--mount</span> type<span class="token attr-value"><span class="token punctuation">=</span>bind,src=</span><em class="replaceable"><span class="token attr-value">/path</span><span class="token constant">-on-host-machine/datadir/</span></em><span class="token constant">,dst</span><span class="token attr-value"><span class="token punctuation">=</span>/var/lib/mysql</span> \
<span class="token property">--mount</span> type<span class="token attr-value"><span class="token punctuation">=</span>bind,src=</span><em class="replaceable"><span class="token attr-value">/path</span><span class="token constant">-on-host-machine/backups/</span></em><span class="token constant">,dst</span><span class="token attr-value"><span class="token punctuation">=</span>/data/backups</span> \
<span class="token property">--rm</span> mysql/enterprise-server<span class="token punctuation">:</span>8<span class="token punctuation">.</span>4 \
mysqlbackup <span class="token constant">--backup-dir</span><span class="token attr-value"><span class="token punctuation">=</span>/tmp/backup-tmp</span> <span class="token property">--with-timestamp</span> \
<span class="token constant">--datadir</span><span class="token attr-value"><span class="token punctuation">=</span>/var/lib/mysql</span> <span class="token constant">--backup-image</span><span class="token attr-value"><span class="token punctuation">=</span>/data/backups/db.mbi</span> copy-back-and-apply-log

mysqlbackup completed OK! with 3 warnings</code></pre>
     </div>
     <p>
      The container exits with the message "
      <code class="literal">
       mysqlbackup
            completed OK!
      </code>
      " once the backup job is finished
            and, with the
      <code class="option">
       --rm
      </code>
      option used when
            starting it, it is removed after it exits.
     </p>
    </li>
    <li class="listitem">
     <p>
      Restart the server container, which also restarts the
            restored server, using the following command:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa45862268"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">docker restart mysqlserver</code></pre>
     </div>
     <p>
      Or, start a new MySQL Server on the restored data directory,
            as shown here:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa67290853"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">docker run <span class="token constant">--name</span><span class="token attr-value"><span class="token punctuation">=</span>mysqlserver2</span> \
<span class="token property">--mount</span> type<span class="token attr-value"><span class="token punctuation">=</span>bind,src=</span><em class="replaceable"><span class="token attr-value">/path</span><span class="token constant">-on-host-machine/datadir/</span></em><span class="token constant">,dst</span><span class="token attr-value"><span class="token punctuation">=</span>/var/lib/mysql</span> \
<span class="token property">-d</span> mysql/enterprise-server<span class="token punctuation">:</span>8<span class="token punctuation">.</span>4</code></pre>
     </div>
     <p>
      Log on to the server to check that the server is running
            with the restored data.
     </p>
    </li>
   </ol>
  </div>
  <h5>
   <a name="docker-mysqldump">
   </a>
   Using
   <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
    <span class="command">
     <strong>
      mysqldump
     </strong>
    </span>
   </a>
   with Docker
  </h5>
  <p>
   Besides
   <a class="link" href="docker-mysql-more-topics.html#docker-meb" title="Using MySQL Enterprise Backup with Docker">
    using MySQL Enterprise Backup to back up a
        MySQL Server running in a Docker container
   </a>
   , you can
        perform a logical backup of your server by using the
   <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
    <span class="command">
     <strong>
      mysqldump
     </strong>
    </span>
   </a>
   utility, run inside a Docker
        container.
  </p>
  <p>
   The following instructions assume that you already have a MySQL
        Server running in a Docker container and, when the container was
        first started, a host directory
   <em class="replaceable">
    <code>
     /path-on-host-machine/datadir/
    </code>
   </em>
   has
        been mounted onto the server's data directory
   <code class="filename">
    /var/lib/mysql
   </code>
   (see
   <a class="link" href="docker-mysql-more-topics.html#docker-persisting-data-configuration" title="Persisting Data and Configuration Changes">
    bind-mounting
        a host directory on the data directory of the MySQL
        Server
   </a>
   for details), which contains the Unix socket file
        by which
   <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
    <span class="command">
     <strong>
      mysqldump
     </strong>
    </span>
   </a>
   and
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   can connect to the server. We also
        assume that, after the server has been started, a user with the
        proper privileges (
   <code class="literal">
    admin
   </code>
   in this example) has
        been created, with which
   <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
    <span class="command">
     <strong>
      mysqldump
     </strong>
    </span>
   </a>
   can access
        the server. Use the following steps to back up and restore MySQL
        Server data:
  </p>
  <p>
   <span class="emphasis">
    <em>
     Backing up MySQL Server data using
     <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
      <span class="command">
       <strong>
        mysqldump
       </strong>
      </span>
     </a>
     with Docker
    </em>
   </span>
   :
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      On the same host where the MySQL Server container is
            running, start another container with an image of MySQL
            Server to perform a backup with the
      <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
       <span class="command">
        <strong>
         mysqldump
        </strong>
       </span>
      </a>
      utility (see documentation of
            the utility for its functionality, options, and
            limitations). Provide access to the server's data
            directory by bind mounting
      <em class="replaceable">
       <code>
        /path-on-host-machine/datadir/
       </code>
      </em>
      .
            Also, mount a host directory
            (
      <em class="replaceable">
       <code>
        /path-on-host-machine/backups/
       </code>
      </em>
      in this example) onto a storage folder for backups inside
            the container (
      <code class="filename">
       /data/backups
      </code>
      is used in
            this example) to persist the backups you are creating. Here
            is a sample command for backing up all databases on the
            server using this setup:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa37252493"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">docker</span> run <span class="token property">--entrypoint</span> <span class="token atrule">"/bin/sh"</span> \ 
<span class="token property">--mount</span> type<span class="token attr-value"><span class="token punctuation">=</span>bind,src=<em class="replaceable">/path-on-host-machine/datadir/</em>,dst=/var/lib/mysql</span> \
<span class="token property">--mount</span> type<span class="token attr-value"><span class="token punctuation">=</span>bind,src=</span><em class="replaceable"><span class="token attr-value">/path</span><span class="token constant">-on-host-machine/backups/</span></em><span class="token constant">,dst</span><span class="token attr-value"><span class="token punctuation">=</span>/data/backups</span> \
<span class="token property">--rm</span> container-registry<span class="token punctuation">.</span>oracle<span class="token punctuation">.</span>com/mysql/community-server<span class="token punctuation">:</span>8<span class="token punctuation">.</span>4 \
<span class="token property">-c</span> <span class="token atrule">"mysqldump -u<em class="replaceable">admin</em> --password='<em class="replaceable">password</em>' --all-databases &gt; /data/backups/all-databases.sql"</span></code></pre>
     </div>
     <p>
      In the command, the
      <code class="literal">
       --entrypoint
      </code>
      option
            is used so that the system shell is invoked after the
            container is started, and the
      <code class="literal">
       -c
      </code>
      option
            is used to specify the
      <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
       <span class="command">
        <strong>
         mysqldump
        </strong>
       </span>
      </a>
      command
            to be run in the shell, whose output is redirected to the
            file
      <code class="filename">
       all-databases.sql
      </code>
      in the backup
            directory.
     </p>
    </li>
    <li class="listitem">
     <p>
      The container exits once the backup job is finished and,
            with the
      <code class="literal">
       --rm
      </code>
      option used to start it, it
            is removed after it exits. A logical backup been created,
            and can be found in the host directory mounted for storing
            the backup, as shown here:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa73845891"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">ls</span> <em class="replaceable">/path-on-host-machine/backups/</em>
all-databases<span class="token punctuation">.</span>sql</code></pre>
     </div>
     <p>
     </p>
    </li>
   </ol>
  </div>
  <p>
   <span class="emphasis">
    <em>
     Restoring MySQL Server data using
     <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
      <span class="command">
       <strong>
        mysqldump
       </strong>
      </span>
     </a>
     with Docker
    </em>
   </span>
   :
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      Make sure you have a MySQL Server running in a container,
            onto which you want your backed-up data to be restored.
     </p>
    </li>
    <li class="listitem">
     <p>
      Start a container with an image of MySQL Server to perform
            the restore with a
      <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
       <span class="command">
        <strong>
         mysql
        </strong>
       </span>
      </a>
      client.
            Bind-mount the server's data directory, as well as the
            storage folder that contains your backup:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa49983152"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">docker</span> run  \
<span class="token property">--mount</span> type<span class="token attr-value"><span class="token punctuation">=</span>bind,src=</span><em class="replaceable"><span class="token attr-value">/path</span><span class="token constant">-on-host-machine/datadir/</span></em><span class="token constant">,dst</span><span class="token attr-value"><span class="token punctuation">=</span>/var/lib/mysql</span> \
<span class="token property">--mount</span> type<span class="token attr-value"><span class="token punctuation">=</span>bind,src=</span><em class="replaceable"><span class="token attr-value">/path</span><span class="token constant">-on-host-machine/backups/</span></em><span class="token constant">,dst</span><span class="token attr-value"><span class="token punctuation">=</span>/data/backups</span> \
<span class="token property">--rm</span> container-registry<span class="token punctuation">.</span>oracle<span class="token punctuation">.</span>com/mysql/community-server<span class="token punctuation">:</span>8<span class="token punctuation">.</span>4 \
mysql <span class="token property">-u<em class="replaceable">admin</em></span> <span class="token constant">--password</span>=<span class="token atrule">'<em class="replaceable">password</em>'</span> <span class="token property">-e</span> <span class="token atrule">"source /data/backups/all-databases.sql"</span></code></pre>
     </div>
     <p>
      The container exits once the backup job is finished and,
            with the
      <code class="option">
       --rm
      </code>
      option used when starting it,
            it is removed after it exits.
     </p>
    </li>
    <li class="listitem">
     <p>
      Log on to the server to check that the restored data is now
            on the server.
     </p>
    </li>
   </ol>
  </div>
  <h5>
   <a name="docker-known-issues">
   </a>
   Known Issues
  </h5>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      When using the server system variable
      <a class="link" href="audit-log-reference.html#sysvar_audit_log_file">
       <code class="literal">
        audit_log_file
       </code>
      </a>
      to configure
            the audit log file name, use the
      <code class="literal">
       loose
      </code>
      <a class="link" href="option-modifiers.html" title="6.2.2.4 Program Option Modifiers">
       option modifier
      </a>
      with
            it; otherwise, Docker cannot start the server.
     </p>
    </li>
   </ul>
  </div>
  <h5>
   <a name="docker-environment-variables">
   </a>
   Docker Environment Variables
  </h5>
  <p>
   When you create a MySQL Server container, you can configure the
        MySQL instance by using the
   <code class="option">
    --env
   </code>
   option (short
        form
   <code class="option">
    -e
   </code>
   ) and specifying one or more environment
        variables. No server initialization is performed if the mounted
        data directory is not empty, in which case setting any of these
        variables has no effect (see
   <a class="xref" href="docker-mysql-more-topics.html#docker-persisting-data-configuration" title="Persisting Data and Configuration Changes">
    Persisting Data and Configuration Changes
   </a>
   ), and no
        existing contents of the directory, including server settings,
        are modified during container startup.
  </p>
  <p>
   Environment variables which can be used to configure a MySQL
        instance are listed here:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      The boolean variables including
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_random_root_password">
       <code class="option">
        MYSQL_RANDOM_ROOT_PASSWORD
       </code>
      </a>
      ,
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_onetime_password">
       <code class="option">
        MYSQL_ONETIME_PASSWORD
       </code>
      </a>
      ,
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql-allow-empty-password">
       <code class="option">
        MYSQL_ALLOW_EMPTY_PASSWORD
       </code>
      </a>
      ,
            and
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql-log-console">
       <code class="option">
        MYSQL_LOG_CONSOLE
       </code>
      </a>
      are made true by setting them with any strings of nonzero
            lengths.



            Therefore, setting them to, for example,
      <span class="quote">
       “
       <span class="quote">
        0
       </span>
       ”
      </span>
      ,
      <span class="quote">
       “
       <span class="quote">
        false
       </span>
       ”
      </span>
      , or
      <span class="quote">
       “
       <span class="quote">
        no
       </span>
       ”
      </span>
      does not make
            them false, but actually makes them true. This is a known
            issue.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a name="docker_var_mysql_random_root_password">
      </a>
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_random_root_password">
       <code class="option">
        MYSQL_RANDOM_ROOT_PASSWORD
       </code>
      </a>
      :
            When this variable is true (which is its default state,
            unless
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql-root-password">
       <code class="option">
        MYSQL_ROOT_PASSWORD
       </code>
      </a>
      is set or
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql-allow-empty-password">
       <code class="option">
        MYSQL_ALLOW_EMPTY_PASSWORD
       </code>
      </a>
      is set to true), a random password for the server's root
            user is generated when the Docker container is started. The
            password is printed to
      <code class="literal">
       stdout
      </code>
      of the
            container and can be found by looking at the container’s
            log (see
      <a class="xref" href="docker-mysql-getting-started.html#docker-starting-mysql-server" title="Starting a MySQL Server Instance">
       Starting a MySQL Server Instance
      </a>
      ).
     </p>
    </li>
    <li class="listitem">
     <p>
      <a name="docker_var_mysql_onetime_password">
      </a>
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_onetime_password">
       <code class="option">
        MYSQL_ONETIME_PASSWORD
       </code>
      </a>
      :
            When the variable is true (which is its default state,
            unless
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql-root-password">
       <code class="option">
        MYSQL_ROOT_PASSWORD
       </code>
      </a>
      is set or
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql-allow-empty-password">
       <code class="option">
        MYSQL_ALLOW_EMPTY_PASSWORD
       </code>
      </a>
      is set to true), the root user's password is set as expired
            and must be changed before MySQL can be used normally.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a name="docker_var_mysql_database">
      </a>
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_database">
       <code class="option">
        MYSQL_DATABASE
       </code>
      </a>
      :
            This variable allows you to specify the name of a database
            to be created on image startup. If a user name and a
            password are supplied with
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_user_password">
       <code class="option">
        MYSQL_USER
       </code>
      </a>
      and
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_user_password">
       <code class="option">
        MYSQL_PASSWORD
       </code>
      </a>
      ,
            the user is created and granted superuser access to this
            database (corresponding to
      <code class="literal">
       GRANT ALL
      </code>
      ).
            The specified database is created by a
      <a class="link" href="create-database.html" title="15.1.12 CREATE DATABASE Statement">
       CREATE DATABASE IF NOT
            EXIST
      </a>
      statement, so that the variable has no effect
            if the database already exists.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a name="docker_var_mysql_user_password">
      </a>
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_user_password">
       <code class="option">
        MYSQL_USER
       </code>
      </a>
      ,
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_user_password">
       <code class="option">
        MYSQL_PASSWORD
       </code>
      </a>
      :
            These variables are used in conjunction to create a user and
            set that user's password, and the user is granted superuser
            permissions for the database specified by the
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_database">
       <code class="option">
        MYSQL_DATABASE
       </code>
      </a>
      variable. Both
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_user_password">
       <code class="option">
        MYSQL_USER
       </code>
      </a>
      and
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_user_password">
       <code class="option">
        MYSQL_PASSWORD
       </code>
      </a>
      are required for a user to be created—if any of the
            two variables is not set, the other is ignored. If both
            variables are set but
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_database">
       <code class="option">
        MYSQL_DATABASE
       </code>
      </a>
      is not, the user is created without any privileges.
     </p>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       There is no need to use this mechanism to create the
                root superuser, which is created by default with the
                password set by either one of the mechanisms discussed
                in the descriptions for
       <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql-root-password">
        <code class="option">
         MYSQL_ROOT_PASSWORD
        </code>
       </a>
       and
       <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_random_root_password">
        <code class="option">
         MYSQL_RANDOM_ROOT_PASSWORD
        </code>
       </a>
       ,
                unless
       <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql-allow-empty-password">
        <code class="option">
         MYSQL_ALLOW_EMPTY_PASSWORD
        </code>
       </a>
       is true.
      </p>
     </div>
     <p>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a name="docker_var_mysql-root-host">
      </a>
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql-root-host">
       <code class="option">
        MYSQL_ROOT_HOST
       </code>
      </a>
      :
            By default, MySQL creates the
      <code class="literal">
       'root'@'localhost'
      </code>
      account. This account
            can only be connected to from inside the container as
            described in
      <a class="xref" href="docker-mysql-getting-started.html#docker-connecting-within-container" title="Connecting to MySQL Server from within the Container">
       Connecting to MySQL Server from within the Container
      </a>
      . To
            allow root connections from other hosts, set this
            environment variable. For example, the value
      <code class="literal">
       172.17.0.1
      </code>
      , which is the default Docker
            gateway IP, allows connections from the host machine that
            runs the container. The option accepts only one entry, but
            wildcards are allowed (for example,
      <code class="option">
       MYSQL_ROOT_HOST=172.*.*.*
      </code>
      or
      <code class="option">
       MYSQL_ROOT_HOST=%
      </code>
      ).
     </p>
    </li>
    <li class="listitem">
     <p>
      <a name="docker_var_mysql-log-console">
      </a>
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql-log-console">
       <code class="option">
        MYSQL_LOG_CONSOLE
       </code>
      </a>
      :
            When the variable is true (which is its default state for
            MySQL 8.4 server containers), the MySQL
            Server's error log is redirected to
      <code class="literal">
       stderr
      </code>
      , so that the error log goes into
            the Docker container's log and is viewable using the
      <span class="command">
       <strong>
        docker logs
        <em class="replaceable">
         <code>
          mysqld-container
         </code>
        </em>
       </strong>
      </span>
      command.
     </p>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       The variable has no effect if a server configuration file
              from the host has been mounted (see
       <a class="xref" href="docker-mysql-more-topics.html#docker-persisting-data-configuration" title="Persisting Data and Configuration Changes">
        Persisting Data and Configuration Changes
       </a>
       on
              bind-mounting a configuration file).
      </p>
     </div>
    </li>
    <li class="listitem">
     <p>
      <a name="docker_var_mysql-root-password">
      </a>
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql-root-password">
       <code class="option">
        MYSQL_ROOT_PASSWORD
       </code>
      </a>
      :
            This variable specifies a password that is set for the MySQL
            root account.
     </p>
     <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Warning
      </div>
      <p>
       Setting the MySQL root user password on the command line
              is insecure. As an alternative to specifying the password
              explicitly, you can set the variable with a container file
              path for a password file, and then mount a file from your
              host that contains the password at the container file
              path. This is still not very secure, as the location of
              the password file is still exposed. It is preferable to
              use the default settings of
       <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_random_root_password">
        <code class="option">
         MYSQL_RANDOM_ROOT_PASSWORD
        </code>
       </a>
       and
       <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_onetime_password">
        <code class="option">
         MYSQL_ONETIME_PASSWORD
        </code>
       </a>
       both being true.
      </p>
     </div>
    </li>
    <li class="listitem">
     <p>
      <a name="docker_var_mysql-allow-empty-password">
      </a>
      <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql-allow-empty-password">
       <code class="option">
        MYSQL_ALLOW_EMPTY_PASSWORD
       </code>
      </a>
      .
            Set it to true to allow the container to be started with a
            blank password for the root user.
     </p>
     <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Warning
      </div>
      <p>
       Setting this variable to true is insecure, because it is
                going to leave your MySQL instance completely
                unprotected, allowing anyone to gain complete superuser
                access. It is preferable to use the default settings of
       <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_random_root_password">
        <code class="option">
         MYSQL_RANDOM_ROOT_PASSWORD
        </code>
       </a>
       and
       <a class="link" href="docker-mysql-more-topics.html#docker_var_mysql_onetime_password">
        <code class="option">
         MYSQL_ONETIME_PASSWORD
        </code>
       </a>
       both being true.
      </p>
     </div>
     <p>
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
