Posted under » MySQL » System Admin on 16 May 2025
We continue from running Moodle using docker ...--e or --env stands for environment
It is hard to use AWS RDS with just MySQL because it does not support integrations with AWS like Percona MySQL does. In order to evaluate Perconal MySQL, I've decided to try it on docker. You can read in detail from the Percona guide.
According to #1 docker hub. However, in the Percona guide it is #2
1. $ docker run --name perconek -e MYSQL_ROOT_PASSWORD=secret -d percona/percona-server:8.0 2. $ docker run -d -p 3306:3306 --name perconek \ -e MYSQL_ROOT_PASSWORD=secret \ -v myvol:/var/lib/mysql \ percona/percona-server:8.0
#2 has the -v or volume defined. What it does is to mount a host directory (myvol) as the container’s data volume, ensuring persistent storage for the database between container lifecycles.
Since I am following the guide, then I should follow #2 percona-server image.
$ docker pull percona/percona-server
You already know I am already running MySQL so I need to use another port. So I change it to
$ docker run -d -p 6603:3306 --name perconek \ -e MYSQL_ROOT_PASSWORD=secret \ -v myvol:/var/lib/mysql \ percona/percona-server:8.0
When you run ps -a, you will see 33060/tcp, 0.0.0.0:6603->3306/tcp, [::]:6603->3306/tcp and you can check ports to be sure.
Now you can connect to MySQL like
$ mysql -u root -p --port=6603 --host=127.0.0.1 $ mysql -u root -p -h 127.0.0.1 -P 6603
Both MySQL command will work. If you do not have MySQL installed, then you can connect to Percona MySQL using docker.
$ docker exec -it perconek mysql -u root -pWhat it does is that it runs the Percona monitoring which is like a MySQL client. The -i stands for interactive and -t is for terminal.
*TIP : We have configured volumes and ports etc. If we want to see all the info. You can use the docker inspect command.
Sometimes, we need to share a Docker volume across different containers. For example, if you want to upgrade your database image to a newer version, you can stop the old container and start a new one with the same volume attached without losing any data.
You can quickly backup and restore your data using the docker cp command or mount the volume to another container.
$ docker volume create backupvol
Now let's connect the Percona XtraBackup container to the Percona Server container.
$ docker run --name pxb --volumes-from perconek -v backupvol:/backup_8034 \ -it --user root percona/percona-xtrabackup:8.0.34 /bin/bash \ -c "xtrabackup --backup --datadir=/var/lib/mysql/ --target-dir=/backup_8034 --user=root --password; xtrabackup --prepare --target-dir=/backup_8034"
The command runs a Docker container pxb from the percona/percona-xtrabackup:8.0.34 image and mounts two volumes: one from another container named perconek, which contains Percona Server data directory, and another named backupvol, which is where the backup files are stored. The command also sets the user to root and prompts the user to enter the password. The command then executes two steps:
You can check the Xtrabackup logs with the docker container logs xtrabackup backup the whole db including priviledges and users, not just schema or tables.
Next we restore the backups.
$ docker container logs pxb