MySQL Docker Container Setup And Configuration On Windows 10
MYSQL Docker Container Setup and Configuration on Windows 10
MYSQL:
MySQL is an open-source relational database management system. It can be used for medium and small-size databases.
Docker:
Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers.
Containers are isolated from one another and bundle their own software.
1. MySQL Image:
First step is to get the latest image from the docker hub.
>>> docker pull mysql/mysql-server:latest
It will pull the latest MySQL image from the docker hub.
2. Docker images:
>>> docker images
It will show all the images.
3. Docker container:
Now it's time to create a MySQL container from the image.
>>> Docker run -d -p 2233:3306 --name <container name>
docker run -d -p 80:80 docker/getting-started
container name could be any name like 'SqlContainer' or 'MysqlContainer'
4. Docker running containers:
>>> docker ps -a
It will show all the running images as containers.
5. Access Docker Container:
Now you can access container bash using the below command:
>> Docker exec -it MYSQL /bin/bash
Can access container shell using below command"
>>> Docker exec -it MYSQL shell
Can access container mysql using the below command.
Docker exec -it MYSQL mysql -uroot -p
Docker exec -it MYSQL mysql -u root -p <password>
It will ask for a password if you not provide otherwise you will be on the mysql terminal.
you can get the password below the given method.
If you didn't set the password in the docker run command then it will randomly create the password of MySQL root and add it in the docker log file.
>>> docker log MYSQL-SERVER-CONTAINER
So change the password using the following Alter command on the mysql terminal.
6. Change password:
ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘1234’;
7. Connection with host:
Windows 10 is the operating system on the host machine. You can connect to MySQL in the docker container, using any database administrative tool like Workbench, Heidi, etc..
Use IP address localhost and post (2233) in our case.
You can face the following issues.
“Host '172.18.0.1' is not allowed to connect to this MySQL server”
172.18.0.1 is the docker-machine IP address and It is not allowing the administrative tools to connect to MySQL.
Sol-
Go to MySQL Terminal
>>> docker exec -it <CONTAINER-NAME> mysql -u root -p <passsword>
mysql>>> Select host, user from mysql.user;
mysql>>> Update mysql.user set host=’%’ where user= ‘root’
mysql >>> GRANT ALL ON *.* TO ‘root’@’%’;

Comments
Post a Comment