MySQL
Running a second MySQL instance on your server
Sometimes you are using MySQL 5.7 for your main project but now you need to run another project on the same server that uses MySQL 8.0. In this case you can choose to run MySQL using docker.
Please be aware that our default MySQL installations have distinct configuration tweaks to ensure high performance on high traffic websites. When using this generic docker based MySQL do not run heavy workloads like your customer facing website.
We do provide some MySQL images that are close to our full service configured MySQL instances:
registry.hipex.cloud/hipex-services/docker-image-mysql/8.0
registry.hipex.cloud/hipex-services/docker-image-mysql/5.7
registry.hipex.cloud/hipex-services/docker-image-mysql/5.6
A simple list of available tags can be found here:
- http://registry.hipex.cloud/?page=1#!taglist/hipex-services/docker-image-mysql/8.0
- http://registry.hipex.cloud/?page=1#!taglist/hipex-services/docker-image-mysql/5.7
- http://registry.hipex.cloud/?page=1#!taglist/hipex-services/docker-image-mysql/5.6
Service configuration
Place to following files in ~/domains/example.com/mysql/docker-compose.yml
version: "3.2"
services:
mysql:
image: registry.hipex.cloud/hipex-services/docker-image-mysql/8.0:v1.0.1
restart: "always"
volumes:
- data:/var/lib/mysql
ports:
- "13600:3306"
environment:
MYSQL_ROOT_PASSWORD: "rootchangeme"
MYSQL_USER: "user"
MYSQL_PASSWORD: "changeme"
MYSQL_DATABASE: "database"
Create in the same folder a new folder named data
, after that you need to run the follow command for the right access.
chmod a+rwx data
Then start your MySQL container with hipex docker:compose:up -d
. You can follow the logs to see what is happening with
hipex docker:compose:logs --follow
. Once the container is up and running you can connect to port 13600
with the
username / password configured in the environment variables.
Backups
Since you can not just copy the MySQL data files a backup need to be created periodically with MySQL dump. This can be done with this cronjob to create a backup every night at 2:00.
Firt create the backup folder: mkdir ~/domains/example.com/mysql/backups
. And configure the cronjob:
0 2 * * * cd ~/domains/example.com/mysql && hipex docker:compose:exec mysql -T -- mysqldump --single-transaction --quick -u user -p'changeme' database | gzip > backups/backup.sql.gz