Install Percona Server for MySQL Inside Docker Container in Linux

Install Percona Server for MySQL Inside Docker Container in Linux

Percona Server for MySQL is a relational database that allows to access data using Structured Query Language (SQL). It is a fork of MySQL Server. Percona Server for MySQL is a fully compatible drop-in replacement for MySQL. All the functionality of MySQL are available in the Percona Server for MySQL. It also provides enhanced features for performance.

This tutorial explains how to install Percona Server for MySQL inside a Docker container in the Linux. Commands have been tested on Ubuntu.

Prepare environment

Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.

Install Percona Server for MySQL

Create directories for data and logs:

sudo mkdir -p /opt/percona-mysql/{data,logs}

Set mysql user (ID: 1001) as owner for newly created directories:

sudo chown -R 1001:1001 /opt/percona-mysql

Note: it doesn't matter that mysql user doesn't exist on host system. The mysql user will be created in the container.

  • Host network

Run the following command to create a container for Percona Server for MySQL that uses host network:

docker run -d --name=percona-mysql --restart=always --network=host \
    -v /opt/percona-mysql/data:/var/lib/mysql \
    -v /opt/percona-mysql/logs:/var/log/mysql \
    -e MYSQL_ROOT_PASSWORD=pwd123 \
    percona/percona-server
  • User-defined bridge network

User-defined bridge network can be used for listening on different port. By default, Percona Server for MySQL service is listening on port 3306. It can be changed with -p option.

docker network create app-net
docker run -d --name=percona-mysql --restart=always --network=app-net \
    -p 8080:3306 \
    -v /opt/percona-mysql/data:/var/lib/mysql \
    -v /opt/percona-mysql/logs:/var/log/mysql \
    -e MYSQL_ROOT_PASSWORD=pwd123 \
    percona/percona-server

Note: don't forget to change root password.

Testing Percona Server for MySQL

Run the following command to open the MySQL client and enter password:

docker exec -it percona-mysql mysql -u root -p -e "SHOW DATABASES"

The command outputs all databases on server:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

Uninstall Percona Server for MySQL

To completely remove Percona Server for MySQL, remove its container:

docker rm --force percona-mysql

Remove Percona Server image:

docker rmi percona/percona-server

You can also remove MySQL data and logs:

sudo rm -rf /opt/percona-mysql

If a user-defined bridge network was created, you can delete it as follows:

docker network rm app-net

Leave a Comment

Cancel reply

Your email address will not be published.