In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to build MySQL database services in Docker. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
The official mysql image is used to build the database service. The current latest version corresponds to version 8.0.19. To prevent compatibility problems in the following steps after subsequent official updates, you can specify version 8.0.19 when using images.
1 create configuration and data directories
Create a directory locally to store mysql configuration and data.
Configuration file directory: ~ / docker/conf/mysql
Data file directory: ~ / docker/data/mysql
Docker pull mysql3 copies the configuration file from the image to the host
The internal configuration files of the image are stored in the / etc/mysql directory. Temporarily create a container copy configuration file directory to the local ~ / docker/conf/ directory.
# create a container docker run named mysql-- name mysql-e MYSQL_ROOT_PASSWORD=crane-d mysql# copy the configuration files within the docker container to the local ~ / docker/conf/mysql directory docker cp mysql:/etc/mysql / Users/crane/docker/conf/# stop and delete the temporary container docker stop mysqldocker rm mysql4 create and run the mysql container
Mount the host configuration and data file directory into the docker container, and the terminal executes the following command
# ~ / docker/conf/mysql directory for mysql configuration files # ~ / docker/data/mysql directory for mysql data files # Ports 3306 and 33060 of this machine are mapped to ports 3306 and 33060 inside docker, respectively # Database root password is crane#-d background run dockerdocker run-- name mysql-v ~ / docker/conf/mysql:/etc/mysql/conf.d-v ~ / docker/data/mysql:/var/lib/mysql-p 3306docker/data/mysql 306 -p 33060 33060-e MYSQL_ROOT_PASSWORD=crane-d mysql5 host connection database 5.1 terminal command connection
After the container starts successfully in the previous step, execute the following command at the host terminal to connect to the database
# enter the following command and enter the database password cranemysql-uroot-p-- protocol=tcp
The above command specifies that tcp is used to connect to the database. If you do not add-- protocol=tcp, the socket connection will be used by default, and the error will be reported as follows
5.2 Database tool connection
You can also use database tools to connect, such as DataGrip, for related data operations.
6 View mysql log
During the normal operation of the container, you can use the following command to view the log
Docker logs-f mysql
Externally mounted configurations and data are used to build the service to facilitate data backup and migration. If you start a container with the same version of docker image on another host and mount the backup configuration and data, you will get exactly the same database configuration and data.
This is how to build a MySQL database service in Docker shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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: 0
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.