Articles in this section

How to install a MySQL database server in a Docker container hosted in Plesk

kb: how-to Plesk for Linux

Applicable to:

  • Plesk for Linux

Question

How to install a MySQL database server in a Docker container hosted in Plesk?

Answer

  1. Connect to your Plesk server via SSH.

  2. Create directory /var/docker/mysql:

    # mkdir -p /var/docker/mysql/

  3. Log in to Plesk.

  4. Go to Docker extension.

    Note: If Docker is not installed, get it from Extensions catalog.

  5. Click Run Container and search for mysql.



  6. Select required version and click Next. In this example, we are installing MySQL version 8.0.




  7. Click Next. The image download will begin.

  8. Once downloaded, configure the container:

    • Give it a recognizable name

    • Select Automatic start after system reboot

    • Uncheck Automatic port mapping

    • Uncheck Make the port inaccessible from the Internet for both port mappings

    • Point:

      • internal port 3306 to external port 3307

      • internal port 33060 to external port 33070

    • In Volume mapping field, point /var/docker/mysql (host) to /var/lib/mysql (container).

      Note: Volume mapping is required to recover MySQL data if something happens to this Docker container.




    • In Environment variables section, click Add one more and add MYSQL_ROOT_PASSWORD to Variable and your root password to Value.

      Note: Keep default environment variables as-is.



  9. Click Run.

  10. Once container is started, go to Tools & Settings > Database Servers and click Add Database Server.

  11. Fill in the fields:

    • Host name or IP address: 127.0.0.1

    • Port number: 3307

    • Username: root

    • Password: your_root_password




  12. Click OK.

 

Additional Information

  • To allow remote connections to this database server:
    1. Go to Tools & Settings > Database Servers > localhost and tick the option Allow local MariaDB/MySQL server to accept external connections.

    2. Access the MySQL server from a command-line interface:

      Note: Replace mysql-8.0 with the name of your Docker container with MySQL server.

      # docker exec -it mysql-8.0 bash

      # mysql -p

    3. Update the host for root user:

      MYSQL_LIN: UPDATE mysql.user SET host='%' WHERE user='root';

      MYSQL_LIN: FLUSH PRIVILEGES;

      MYSQL_LIN: exit

    4. Open ports 3307 and 33070 in Plesk firewall and other firewall systems, if you use any.

  • To use this database server as default, go to Tools & Settings > Database Servers > 127.0.0.1 and tick the option Use this server as default for MySQL.

 

 

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.