Run database using Docker
MySQL
Start MySQL-8 server container
docker run -itd -p 3306:3306 -e MYSQL_ROOT_PASSWORD=Demo@123 -e
MYSQL_DATABASE=demo_mysql_80 --name mysql_8 mysql:8
Start MySQL-5.6 server container
docker run -itd -p 3306:3306 -e MYSQL_ROOT_PASSWORD=Demo@123 -e
MYSQL_DATABASE=demo_mysql_56 --name mysql_56 mysql:5.6
Login inside MySQL shell
The docker exec command allows you to run commands inside a Docker container. The following command open a bash shell inside your MySQL container
docker exec -it mysql_56
bash
This will open bash shell, there you can run MySQL commands to login inside MySQL shell
$ mysql -uroot -pDemo@123
$ mysql >
View MySQL docker container log
$ docker logs mysql_56
Take Database backup as SQL dump
With Dcoker container to take ysql dump, run docker exec command as shown
$ docker exec mysql_56 sh -c 'exec mysqldump --all-databases -uroot -pDemo@123' > /local/path/on/system/mysql56-all-databases.sql
Restore Database SQL dump
For restoring SQL dump you can use docker exec command with -i flag, as shown
$ docker exec -imysql_56 sh -c 'exec mysql -uroot -pDemo@123' < /local/path/on/system/mysql56-all-databases.sql