MySQL installation using docker compose | MySQL | Docker | Docker Compose | Installation

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello people this is selfs and in this video we'll learn how to install MySQL using Docker compose so MySQL is a relational database and it is used to store data which is used for different purposes so the first prerequisite for this particular video is talker must be installed and Docker compose must be installed we are not going to do the separate installation and make this video very lengthy so you should have Docker and Docker compose installed on your operating system the next thing is what let's say suppose this is your host operating system it can be Windows it can be open2 it can be Mac OS and then once you do the docker installation so already there's a environment running inside your host operating system and that is Docker environment inside the docker environment we are going to create this MySQL container and then we are going to expose the port one port that is 3306 which is the default port for MySQL will be exposed on the host operating system and the other Port will be exposed inside the docker container inside the docker environment that will be 3306 so why this is important because the applications would be running on your host operating system and then should be able to connect this MySQL on this 33064 so the request will come to the port of the host operating system and it will automatically get proxy to the 3306 of your Docker container so this is the whole setup that we are going to do I have already written this blog and I'll give the link in the description where where I have detailed out all the steps that is is needed to uh run the MySQL on the docker compose so basically we'll create a file that will be myql Docker compost. yl because we have yl as the default configuration file for writing your Docker compost configurations so we are going to use version 3.7 and we'll be defining the services and the service name will be and the service will be called as my SQL and the image that we are going to use is my SQL 5.7 so the container that will be created will have have a MySQL 5.7 version the name of the container will be MySQL 5.7 you can write whatever you want here it will always restart so let's say there's a crash so still after the crash it will automatically restart then we will Define some of the environment variables and these are very important once you do the installation so what will happen you will have a root user for the MySQL and the default password for that root user will be password so you can change if you want we will also create a user that will be called as sample and and the password for that user will also be password and the sample datab base will be created that will be test database the port exposing which I've already shown you in the slide that will expose this 3306 port on the host and 3306 port on the docker container we have also defined a volume with the name MySQL DB because we want to give a specific name to this volume so why volume is important so let's say you delete or you remove your my SQL container and after that you create a new container and you point the container to this particular volume so what will happen the data will still persist so let's say you have created 10 to 15 different databases and there's already some data inside it so that will not be lost and we are naming it because it will be easy for you to find so that's why this is the configuration so these details are written here which is in the blog you can go through it I'll put the link of this blog in the descriptions second thing is what if you want to learn about Docker so I have this whole playlist on the docker where where I have created multiple videos you can go through it also to understand Docker and Docker compose let's go to the terminal and here what we'll do we will do the steps that is present in that block so we'll do a LS and inside we'll go to workspace and here I'll say mkd Docker compose MySQL I'll go to Docker compose MySQL and this is empty folder in the blog we are seeing that we have to create this file MySQL Docker compose EML so let's create my SQL Docker compose do EML so let's go inside to that file so that we can edit something and let's copy the data from here so I'm going to copy it and what I'm going to do I'll do copy and just paste it here so let's paste it and do a right and quit so if you want to run this file using the docker compose so the command is Docker compose hyen F my SQL Docker compose EML and and then up up is for starting the containers which is present or starting the services which is present inside the docker compos EML so what this is going to do there's a f APS or connection because okay so let me check Docker PS it is not running okay so let me start it so I have started Docker okay now let me again run the file so this time what will happen you are seeing it is creating this MySQL container MySQL 5.7 because we have given that that container name let me open a new terminal on the right hand side and what I'm going to do I'm going to connect to this MySQL so I'm in the same server so what will happen I can put the host as 127.0.0.1 and I'm trying to connect using the root user and I need this password so I'll hit enter and then again enter the password that is p a s w r d so now I'm inside this MySQL so if I do to show datab bases so what it will do it will give me a new database and you can see here the test database is already created I can create a database so create data base and then I can say let's say something leaderboard so I can again do show databases and it will give you that leaderboard is present here now let's do what let's do a control C so what will happen the docker container will stop I'll show you how so if I do let me exit from here so that everything is visible so I'll do Docker PS to check what are the running containers so there's nothing if I do Docker PS high so what will happen Okay the container is stopped and it is listed here so now if I want to again go to the I want to connect to here so what will happen it will not get connected okay so I'll hit and it will say can't connect to my SQL Server because the container is town so what I'm going to do this time I'm going to run the docker container in the background mode so up hyph D so what is d hyph d it is demon mode that is it will not run in foreground but it will run in background so if I do enter so what will happen it will start the my SQL and it will exit but if I do Docker PS so what will happen you can see the container is running and if if I want to connect so I'll give the password and I'm able to connect so this is the thing minus D thing okay once one thing also you have uh seen that I stopped the container and then I uh started it again so let's see the leaderboard database is present there or not so let's go inside it and if I see so databases so data bases so you can see that leaderboard databases present which means that data is still persisting so this is all about this video you can just copy paste the uh Docker compose file data you can just run the mySQL database and you can start using it with your application so this is the easiest way and it is OS agnostic like uh it will not have a separate installation for Mac OS or for Windows or for UB 2 everything will have the same installation so this is the beauty of talkers thank you for watching this video please share this video and please subscribe to my channel thanks
Info
Channel: CodeWithRajRanjan
Views: 2,303
Rating: undefined out of 5
Keywords: mysql, mysql installation using docker, mysql installation using docker compose, docker compose mysql, mysql docker, how to install mysql, how to install mysql using docker
Id: 5T1-1luUvn8
Channel Id: undefined
Length: 8min 1sec (481 seconds)
Published: Sun Dec 31 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.