Create a Mysql Container
Pull an image from Docker Hub
terminal
docker pull mysql
Start a mysql server instance
The following command starts another mysql container instance and runs the mysql command line client against your original mysql container, allowing you to execute SQL statements against your database instance:
terminal
docker container run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=mydb mysql
Container shell access and viewing MySQL logs
The docker exec command allows you to run commands inside a Docker container. The following command line will give you a bash shell inside your mysql container:
terminal
docker exec -it mysql bash
Connecting to and Disconnecting from the Server
terminal
mysql -u root -p
Enter password:
User infomation in mysql
terminal
select user, host from mysql.user;
database infomation
terminal
show databases;
stop mysql container
terminal
docker container stop mysql