Docker

Run MySQL Server Using Docker On A Remote Machine

Learn how to run a MySQL server using Docker on a remote machine, connect with MySQL Workbench, and manage the container safely.

Run MySQL Server Using Docker On A Remote Machine thumbnail

Running a MySQL server on a remote machine using Docker can simplify database setup for learning, testing, and practice environments. In this guide, we will set up a remote MySQL server with Docker and connect to it from MySQL Workbench.

This is useful for QA engineers who want to practice database testing, API testing, and integration workflows against a real database server.

Step 1: Get A Server You Can Access Remotely

In the original tutorial, I used DigitalOcean. You can use a VPS from any provider you prefer.

Create the server with these basic specifications:

  • Operating system: Ubuntu.
  • Authentication: password or SSH key.
  • Plan: the cheapest small plan is enough for practice.

DigitalOcean droplet creation screen showing server image options

DigitalOcean droplet plan selection screen

DigitalOcean droplet authentication setup screen

DigitalOcean droplet final creation settings

Step 2: SSH Into The Droplet Or Use The Browser Console

Once the droplet is created, you can SSH into it from your terminal, CMD, or PowerShell.

ssh root@your_droplet_ip

Alternatively, you can use the console provided in the DigitalOcean browser interface.

DigitalOcean droplet access console option

DigitalOcean browser console connected to droplet

Step 3: Install Docker

Run the following commands on the server to install Docker:

apt-get update
apt-get install -y docker.io

Verify Docker is installed:

docker --version

Step 4: Run The MySQL Container

Use this command to run the MySQL container:

docker run --name mysql-demo \
  -e MYSQL_ROOT_PASSWORD=SuperSecretForRoot \
  --restart always \
  -p 3307:3306 \
  -d mysql:8.0

Command breakdown:

OptionMeaning
--name mysql-demoNames the container mysql-demo.
-e MYSQL_ROOT_PASSWORD=SuperSecretForRootSets the root password for MySQL. Replace this with your own password.
--restart alwaysRestarts the container automatically if it stops.
-p 3307:3306Maps port 3307 on the server to port 3306 inside the container.
-d mysql:8.0Runs MySQL 8.0 in detached mode.

Running the MySQL Docker container command

Verify that the container is running and that port 3307 is available:

docker ps

Verifying the MySQL container is running

Step 5: Open MySQL Workbench

If you do not have MySQL Workbench installed, download it from the official MySQL Workbench page:

https://dev.mysql.com/downloads/workbench/

Step 6: Create A Connection In MySQL Workbench

In MySQL Workbench:

  1. Open MySQL Workbench.
  2. Click + Add New Connection.
  3. Enter the connection details.
  4. Click Test Connection.
  5. Click OK to save the connection.

Use these values:

FieldValue
Connection NameMySQL Docker
HostnameYour droplet IP address
Port3307
Usernameroot
PasswordThe password you used in MYSQL_ROOT_PASSWORD

MySQL Workbench home screen

MySQL Workbench connection settings for remote Docker MySQL

Restart The Container If MySQL Is Stuck

If you cannot access the MySQL server or the container is stuck, restart the container. These commands assume the container name is mysql-demo.

Stop the container:

docker stop mysql-demo

Start the container:

docker start mysql-demo

Restart the container:

docker restart mysql-demo

Optional: Use A Subdomain Instead Of An IP Address

If you want to connect using a subdomain like mysql.mydomain.com instead of an IP address, create an A record that points to your server.

General steps:

  1. Log in to your domain registrar or DNS provider.
  2. Open DNS management.
  3. Add an A record.
  4. Set the host to your subdomain, such as mysql.
  5. Point it to your droplet IP address.
  6. Save the record and wait for DNS propagation.

Important Security Note

For practice, exposing MySQL on a public server can be acceptable if you understand the risk, use a strong password, and restrict access. For anything serious, avoid exposing a database port publicly.

Safer options include:

  • Restrict port 3307 to your own IP address using a firewall.
  • Use SSH tunneling instead of opening MySQL to the internet.
  • Keep this setup for disposable practice environments only.

Example SSH tunnel:

ssh -L 3307:127.0.0.1:3307 root@your_droplet_ip

Then connect MySQL Workbench to 127.0.0.1 on port 3307.

The original Kajabi page included an Nginx reverse proxy example, but HTTP reverse proxying is not the normal way to expose MySQL. For a database, firewall rules or SSH tunneling are a better fit.

Run MySQL Server Using Docker On A Remote Machine | SuperSQA