Databases 5 min read

How to Deploy MySQL 8.0 in Docker on veLinux2 – Step‑by‑Step Guide

This guide walks through deploying MySQL 8.0 in a Docker container on veLinux 2, covering environment requirements, configuring a domestic Docker mirror, pulling the image, running the container with persistence and remote‑access settings, opening firewall ports, granting remote root privileges, and verifying the service.

liandk
liandk
liandk
How to Deploy MySQL 8.0 in Docker on veLinux2 – Step‑by‑Step Guide

Prerequisites

Server: veLinux 2 (EL9 architecture, 2 CPU, 4 GB RAM)

Deployment method: Docker container (avoids system dnf/rpm issues)

Database version: MySQL 8.0 stable

Advantages: no system modifications, stable deployment, data persistence, remote connection support

Preparation

Ensure Docker is installed (run docker --version)

Open network ports (system firewall + cloud security group)

No need to uninstall existing databases; the container is fully isolated from the host environment

Configure Docker mirror (required for fast image pull)

Docker’s default overseas registry is slow; execute the following commands to set domestic mirrors:

# create docker config directory
mkdir -p /etc/docker

# write mirror configuration
tee /etc/docker/daemon.json <<'EOF'
{
  "registry-mirrors": [
    "https://docker.1ms.run",
    "https://hub-mirror.c.163.com",
    "https://mirror.baidubce.com"
  ]
}
EOF

# reload daemon and restart Docker
systemctl daemon-reload
systemctl restart docker

# verify configuration
docker info

Seeing a “Registry Mirrors” field in the output confirms success.

Pull MySQL 8.0 image

docker pull mysql:8.0

Wait until the pull finishes without errors.

Run MySQL 8.0 container (production‑grade configuration)

The command includes auto‑restart, port mapping, data persistence, and a custom root password. Execute:

docker run -d \
--name mysql8 \
--restart=always \
-p 3306:3306 \
-v /opt/mysql-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=root@mysql \
mysql:8.0

Parameter explanation

--name mysql8

: container name for easy management --restart=always: Docker auto‑restart on boot or crash -p 3306:3306: maps host port 3306 to container, enabling remote connections -v /opt/mysql-data:/var/lib/mysql: persists data on the host; data survives container removal or restart -e MYSQL_ROOT_PASSWORD=root@mysql: sets the root password (customizable)

Open port 3306 (required for remote access)

1. Open firewall

firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload

2. Configure cloud security group

In the Volcano Engine console, add an inbound rule for TCP port 3306; otherwise external tools cannot connect to the database.

Configure MySQL remote access

MySQL 8 disables remote root login by default; grant permission with the following steps:

# enter MySQL shell
docker exec -it mysql8 mysql -uroot -proot@mysql

# run SQL statements
CREATE USER 'root'@'%' IDENTIFIED BY 'root@mysql';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
FLUSH PRIVILEGES;
exit;

Verify MySQL status and version

1. Check container status

docker ps | grep mysql8

Output showing “Up …” indicates the container is running normally.

2. Show MySQL version

docker exec -it mysql8 mysql -uroot -proot@mysql -e "SELECT VERSION();"
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerdeploymentLinuxcontainermysqlveLinux2
liandk
Written by

liandk

Seasoned Java and mobile developer with years of experience, specializing in mini‑programs, public accounts, and full‑stack front‑end development. In the AI era, I continuously learn to broaden my knowledge and evolve. I revived a public account I started a decade ago during a dessert‑startup venture, using code as a vessel and knowledge as a companion. I share personal projects, technical articles, programming tips, and growth insights—let’s improve together and set sail.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.