In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "the download, installation and configuration process of mysql image generation container". In daily operation, I believe many people have doubts about the download, installation and configuration process of mysql image generation container. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "download, installation and configuration process of mysql image generation container". Next, please follow the editor to study!
Download the official mysql image
[root@localhost ~] # docker pull mysql
View the image after the download:
[root@localhost ~] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/mysql latest 1195b21c3a45 10 weeks ago 380.2 MB
Second, generate the container
When the container is generated, the startup script called is / entrypoint.sh;. By viewing the contents of the / entrypoint.sh script, the summary parameters are as follows
Mysqld # to start the mysql service, you must use MYSQL_ROOT_PASSWORD # to set the root password for mysql. You must use the following two parameters to add a user other than root and set the password. Optional. MYSQL_USER MYSQL_PASSWORD# sets the new database that needs to be created when the container is generated. The default save path for the mysql database of the optional MYSQL_DATABASE# container is: / var/lib/mysql# container configuration file my.cnf path: / etc/mysql/my.cnf
Generate a new container using the parameters you want on:
[root@localhost mysql_data] # docker run-d-p 3307 name mysql-P-e mysqld-e MYSQL_ROOT_PASSWORD=123456-e MYSQL_USER=yope-e MYSQL_PASSWORD=yope-e MYSQL_DATABASE=testDb-v / mysql_data:/var/lib/mysql mysql 492ffa26d8653561208aed28eb62c61e9bae0de91ef911769c35f9e4eae6b272 [root@localhost mysql_data] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES492ffa26d865 mysql "docker-entrypoint.sh" 10 seconds ago Up 7 seconds 0.0.0.0 seconds ago Up 3307-> 3306/tcp mysql
Important parameters description:
-- name mysql
Specify the container name as mysql
-p 3307 purl 3306
Specifies the mapping port to map host port 3307 to container 3306 port
-v / mysql_data:/var/lib/mysql
Map the location of the database. Map the host directory "/ mysql_data" to the container's "/ var/lib/mysql" directory; this is because the database files and log files of the database are stored in the container's AUFS file layer by default, which not only does not make the container become more and more bloated and is not easy to manage such as migration and backup, but also affects the performance of the database. Therefore, it is recommended to mount it to the host directory and into the container.
Check to see if the local mysql_data generates the database in the container:
[root@localhost /] # ll / mysql_data/ Total usage 188452 Murray r-1 systemd-bus-proxy ssh_keys 56 August 20 22:25 auto.cnf-rw-r- 1 systemd-bus-proxy ssh_keys 1329 August 20 22:25 ib_buffer_pool-rw-r- 1 systemd-bus-proxy ssh_keys 79691776 August 20 22:25 ibdata1-rw-r- 1 systemd -bus-proxy ssh_keys 50331648 August 20 22:25 ib_logfile0-rw-r- 1 systemd-bus-proxy ssh_keys 50331648 August 20 22:25 ib_logfile1-rw-r- 1 systemd-bus-proxy ssh_keys 12582912 August 20 22:25 ibtmp1drwxr-x--- 2 systemd-bus-proxy ssh_keys 4096 August 20 22:25 mysqldrwxr-x--- 2 systemd-bus-proxy ssh_keys 8192 August 20 22:25 performance_schemadrwxr-x--- 2 systemd-bus-proxy ssh_keys 8192 August 20 22:25 sysdrwxr-x--- 2 systemd-bus-proxy ssh_keys 19 August 20 22:25 testDb [root@localhost /] #
Relevant files and default database have been generated, and a new testDb database has been created.
Test scenario 1:
Access the mysql service in the container through the port on the host
[root@localhost /] # yum-y install mysql
Test login:
[root@localhost mysql_data] # mysql-u root-p-h 127.0.0.1-P 3307Enter password: Welcome to the MariaDB monitor. Commands end with; or\ g.Your MySQL connection id is 2Server version: 5.7.13 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.MySQL [(none)] >
Test scenario 2:
Use mysql connection tools (eg:Navicat, etc.) to connect locally, and note that the real port mapped is not necessarily 3306.
It is important to note that the UID and GID on the host are 999. This is the UID and GID of the user mysql in the container. Do not change permissions, otherwise there will be problems for the container to read and write to this directory. If you feel uncomfortable, you can create a new mysql_docker locally. The user-specified UID and GID are 999.
(I have not verified this idea. If there is anything wrong with the description, please point it out.)
Enter the newly generated container (the container named mysql)
Use exec to enter the container and perform related operations:
[root@localhost /] # docker exec-it mysql / bin/bash
View the process:
Root@492ffa26d865:/# ps-auxUSER PID% CPU% MEM VSZ RSS TTY STAT START TIME COMMANDmysql 1 0.2 9.7 1262696 182200? Ssl 14:52 0:00 mysqldroot 127 0.2 0.1 20216 1884? Ss 14:57 0:00 / bin/bashroot 133 0.0 0.0 17492 1148? R + 14:58 0:00 ps-aux
View the folder where the database is located:
Root@492ffa26d865:/# ls-1 / var/lib/mysql/total 188452 root@492ffa26d865:/# ls-1 mysql mysql 56 Aug 20 14:52 auto.cnf-rw-r- 1 mysql mysql 1329 Aug 20 14:52 ib_buffer_pool-rw-r- 1 mysql mysql 50331648 Aug 20 14:52 ib_logfile0-rw-r- 1 mysql mysql 50331648 Aug 20 14:52 ib_logfile1-rw-r- 1 mysql Mysql 79691776 Aug 20 14:52 ibdata1-rw-r- 1 mysql mysql 12582912 Aug 20 14:52 ibtmp1drwxr-x--- 2 mysql mysql 4096 Aug 20 14:52 mysqldrwxr-x--- 2 mysql mysql 8192 Aug 20 14:52 performance_schemadrwxr-x--- 2 mysql mysql 8192 Aug 20 14:52 sysdrwxr-x--- 2 mysql mysql 19 Aug 20 14:52 testDb
Enter mysql:
Root@492ffa26d865:/# mysql-u root-pEnter password: Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 3Server version: 5.7.13 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.mysql >
4. Modify the configuration file of mysql in the container
Vi or vim is not installed in the default image. It needs to be installed manually.
Root@492ffa26d865:/# apt-get update & & apt-get-yq install vim
You can then use vim to modify the configuration file of mysql:
Root@492ffa26d865:/# vim / etc/mysql/my.cnf
The vim editor will not elaborate here.
If you already have a mature my.cnf configuration scheme, you can create a new folder on the host and put the two files my.cnf and conf.d that have been set in it.
Then when you create a new container, just use the parameter "- v" to map this folder to the container's "/ etc/mysql" directory.
At this point, the study on the "download, installation and configuration process of the mysql image generation container" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.