Run Mysql in Docker Part 2

Опубликовано: 16 Октябрь 2024
на канале: Aveti Tutorials
667
23

This tutorial shows how to start mysql with docker compose. Here you learn how persist docker mysql data and how to use external mysql config in docker.
This also covers few mysql sql queries.

This is a continuation of previous mysql tutorial

Follow this tutorial to learn
1. mysql docker compose
2. persist mysql data in docker
3. custom configuation for mysql

Prerequisites
Docker installed

Steps:
1. Go to https://hub.docker.com/_/mysql and pull mysql image
docker pull mysql:latest
2. Create docker-compose.yml file
3. Run mysql docker container
docker-compose up -d
4. Check logs
docker logs container-id -f
5. Connect to mysql
docker exec -it mysql-docker bash
mysql -uroot -p

6. Mysql queries
a)View all available databases in mysql
show databases;
b)Using a selected database
use database-name
c)create table
CREATE TABLE persons (
personid int,
lastname varchar(255),
firstname varchar(255)
);

d) to view tables
show tables;

e) Insert into table
INSERT INTO persons (personid, lastname, FirstName) VALUES (1,'aveti','tutorial');
INSERT INTO persons (personid, lastname, firstname) VALUES (2,'John','Doe');

7. Persist Data of mysql
Use volume mount in docker-compose file
sudo mkdir -p ./data/db
map above directory in docker-compose.yml

8. Use custom configuration file
a) store conf in your local machine and use it mysql container
b) validate the applied mysql configuration
mysql -p -e "show variables like '%max_allowed_packet%';"
mysql -p -e "show variables like '%max_connections%';"

https://github.com/avetichamp/phpmyad...
Facebook :   / aveti.tutorial.9  

Chapters
0:00 Introduction
1:35 Use docker compose with mysql
10:15 Persist mysql datain docker
15:50 Use custom configuration for mysql


Please like subscribe to this channel