26.01.2024

How to set up MySQL on Docker?

In the realm of database management, Docker has emerged as a game-changer, providing a streamlined and efficient approach to setting up and running databases. This tutorial focuses on MySQL installation through Docker—a method favored by developers and DevOps professionals. Much like the advantages it offers for MongoDB, leveraging Docker for MySQL installation brings unprecedented benefits in terms of portability, scalability, and isolation.

Installation MySQL on Docker

At the start of installation process we update indexes and upgrade packages of currently application and utility. That help to avoid potential compatibility issues :

apt update && apt upgrade -y

Screenshot №1 — Update package

At the end of the process make sure that process was completed successfully and no one issues was pop-uped. Next stage, will installation software for containerization application, by the command below:

apt install docker.io

Screenshot №2 — Installation of Docker

Docker represent platform for start isolated application, utility or system with integrated file-system, network and kit-tools for properly work. We can download from repository image and install them into the container, in isolated part! And connect to them we can through localhost and indicated port or literally use straight connection via terminal. After installation docker, we can download and automatically deploy server MySQL, by the command:

docker run --name my-db -e MYSQL_ROOT_PASSWORD=123321 -d mysql

Screenshot №3 — Pull packages

Checking the installation of MySQL on Docker

Alright, now we need to make sure that our Docker container was created and upped, for that we can use command:

docker ps

Screenshot №4— Process

If you have any issues you can type command below for check log container and troubleshoot them:

docker logs my-db

Screenshot №5— Logs

Now, we can connect to the container via network and indicate credentials, for manage with utility:

docker exec -it my-db bash

And after that command we can start our DB using appropriate utility:

mysql -h localhost -u root -p

Screenshot №6— Connection

Alright! Our connection was established and we can use them from their client.

In this comprehensive exploration of usage Docker for MySQL, we've navigated the transformative landscape of database management, where Docker emerges as a pivotal force. Developers and DevOps professionals increasingly favor this approach for MySQL setup, drawing parallels with the efficiency seen in MongoDB deployments. Leveraging Docker for MySQL not only simplifies the installation process but also introduces unmatched benefits in terms of portability, scalability, and isolation.