Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Mysql Image in docker

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to use Mysql mirroring in docker? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.

one。 The docker command used:

1.docker images lists the mirrors on the local host.

2.docker pull pulls or updates the specified image from Docker Hub.

3.docker run

The-d flag is to let the docker container run in the background.

The-p flag tells Docker to map the network ports used inside the container to the hosts we use.

-- name defines the name of a container. If Name is not specified when docker run is executed, deamon will automatically generate a random number string as UUID.

-e set the environment variable, or overwrite an existing environment variable.

For example: docker run-- name mysql- p 3306 MYSQL_ROOT_PASSWORD=password-dmysql/mysql-server:latest

Meaning: the name of the container is mysql. Port 3306 of the container is mapped to port 3306 of the machine. The password of the mysql database is password, and the running image is mysql/mysql-server:latest.

4.docker ps

-a view the containers that have been created

-s to view containers that have been started

5.docker start con_name starts the container with the name con_name.

6.docker stop con_name stops the container named con_name.

7.docker rm con_name deletes the container named con_name.

8.docker rmi img_name deletes the mirror named img_name.

9.docker rename old_name new_name renames a container.

two。 Actual combat operation:

1. Pull the official image:

Docker pull mysql/mysql-server:latest

two。 View the image:

Docker images

3. Create a container

The copy code is as follows:

Docker run-name mysql- p 3306 MYSQL_ROOT_PASSWORD=password 3306-e MYSQL_ROOT_PASSWORD=password-d mysql/mysql-server:latest

4. View containers that have been created

Docker ps-a

5. View running containers

Docker ps-s

6. Start the container

88dab2f338c6 is the CONTAINER ID in figure 2.

Docker start 88dab2f338c6

Execute the docker ps-s command again, and the result is shown in figure 4, indicating that mysql started successfully.

7. Connect to Mysql database

(1)。 Client tool connection

I use mysql's visualization tool workbench to connect to db here.

Workbench download address: http://dev.mysql.com/downloads/workbench/

(2) Command line connection under docker

1)。 First, go to CMD and execute the following command

Docker exec-it 88dab2f338c6 bash

2)。 Then, enter the following command and enter the password password

Is it helpful for mysql-uroot-p-h localhost to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 272

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report