In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to install and use mysql docker". In daily operation, I believe many people have doubts about how to install and use mysql docker. 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 about "how to install and use mysql docker". Next, please follow the editor to study!
(1) https://hub.docker.com/ searches the mysql library from the library and selects mysql:5.7
$docker pull mysql:5.7
Pull the mysql image from docker, version 5.7. In fact, we can be more specific and write like this:
$docker pull docker.io/library/mysql:5.7, is it very much like the way you download a file?
[root@k8s-master nginx] # df-k
Filesystem 1K-blocks Used Available Use% Mounted on
/ dev/sda2 102877120 2973376 94654772 4%
[root@k8s-master nginx] # df-k
Filesystem 1K-blocks Used Available Use% Mounted on
/ dev/sda2 102877120 3355004 94273144 4%
At this time, I will think, where is the downloaded image? That's a good question. We used find to look for it, and found it here.
Put it: ls / var/lib/docker/overlay2/
A search will find this folder:
/ var/lib/docker/overlay2/91f7d56179ab4bfb0a795401b590d17d30dae97d70b02f24454d1b5b4339798b/diff/run/mysqld .
(2) take a look at the current images of the system.
[root@k8s-master nginx] # docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Centos 7 67fa590cfc1c 2 days ago 202MB
Mysql 5.7 e1e1680ac726 9 days ago 373MB
(3) start starting the image and use it.
Starting a MySQL instance is simple:
$docker run-- name some-mysql-e MYSQL_ROOT_PASSWORD=my-secret-pw-d mysql:tag
... Where some-mysql is the name you want to assign to your container, my-secret-pw is the password to be
Set for the MySQL root user and tag is the tag specifying the MySQL version you want. See the list above for
Relevant tags.
$mkdir / data/datadir
$docker run-- expose=3306-p 3306-- name docker_mysql-v / data/datadir:/var/lib/mysql\
-e MYSQL_ROOT_PASSWORD=123456-d mysql:5.7-- character-set-server=utf8mb4\
-- collation-server=utf8mb4_unicode_ci
-p 3306: development port
-- name docker_mysql:container name is docker_mysql
-v / data/datadir:/var/lib/mysql: host directory / data/datadir container directory / var/lib/mysql
-e MYSQL_ROOT_PASSWORD=123456: root password
-d: start in the background
-- character-set-server=utf8mb4-- collation-server=utf8mb4_unicode_ci: parameter passed to mysql
(4) which container has been started under the query?
[root@k8s-master nginx] # docker ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6a9ad568a182 mysql:5.7 "docker-entrypoint.s..." 5 seconds ago Up 4 seconds 33060/tcp, 0.0.0.014 32768-> 3306/tcp docker_mysql
In fact, at this time we thought, what is the difference between starting with docker and starting with ordinary mysql? First use ps to take a look.
# ps aux | grep mysql
Systemd+ 5438 0.2 9.7 1136232 194828? Ssl 15:41 0:00 mysqld
It is currently started with the systemd user.
(5) at this time, let's take a look at / data/datadir and find out what?
# ls / data/datadir
Auto.cnf ca.pem client-key.pem ibdata1 ib_logfile1 mysql private_key.pem server-cert.pem sys
Ca-key.pem client-cert.pem ib_buffer_pool ib_logfile0 ibtmp1 performance_schema public_key.pem server-key.pem
(6) what are the listening ports of the host?
[root@k8s-master nginx] # netstat-tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
Tcp 0 0 0.0.0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0
Tcp6 0 0: 32768: * LISTEN 8054/docker-proxy
32768 is to expose the address of the external access port.
(7) at this point, it's like connecting to a mysql database, then creating a database, and creating a table.
Mysql-uroot-p123456-h292.168.2.129-P32768
Mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with; or\ g.
Your MySQL connection id is 2
Server version: 5.7.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.
Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.
Mysql > create database test
Query OK, 1 row affected (0.00 sec)
Mysql > use test
Database changed
Mysql > create table stu (id number, name varchar (30))
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'number, name varchar (30))' at line 1
Mysql > create table stu (id integer, name varchar (30))
Query OK, 0 rows affected (0.01 sec)
Mysql >
Mysql > insert into stu values (1)
Query OK, 1 row affected (0.01sec)
Mysql > commit
Query OK, 0 rows affected (0.00 sec)
Under observation, it is found that the version of mysql is 5.7.27, using Community.
I created a table stu. I went to the host to take a look at the directory, and sure enough, I created a file test and table stu.frm.
[root@k8s-master nginx] # ls / data/datadir/test
Db.opt stu.frm stu.ibd
(8) do we have a great sense of achievement at this time? . Now I want to go into the container to see how many connections come in and how to do it?
Docker exec-it docker_mysql bash
-I-- interactive Keep STDIN open even if not attached
-t,-- tty Allocate a pseudo-TTY
[root@k8s-master nginx] # docker exec-it docker_mysql bash
Root@6a9ad568a182:/# mysql-uroot-p123456
Mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with; or\ g.
Your MySQL connection id is 3
Server version: 5.7.27 MySQL Community Server (GPL)
Mysql > show processlist
+-+ +
| | Id | User | Host | db | Command | Time | State | Info |
+-+ +
| | 3 | root | localhost | NULL | Query | 0 | starting | show processlist | |
| | 4 | root | 192.168.2.132 Sleep 50408 | NULL | Sleep | 4 | | NULL |
+-+ +
2 rows in set (0.00 sec)
Here, just like in an operating system, just do what you do. Try it for yourself.
(9) start and close, start the container, close the container, delete the container, create another container, and then connect to the mysql. What do you find?
[root@k8s-master nginx] # docker ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6a9ad568a182 mysql:5.7 "docker-entrypoint.s..." 24 minutes ago Up 24 minutes 33060/tcp, 0.0.0.015 32768-> 3306/tcp docker_mysql
[root@k8s-master nginx] # docker stop docker_mysql
Docker_mysql
[root@k8s-master nginx] # docker start docker_mysql
Docker_mysql
[root@k8s-master nginx] # docker ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6a9ad568a182 mysql:5.7 "docker-entrypoint.s..." 24 minutes ago Up 12 seconds 33060/tcp, 0.0.0.014 32769-> 3306/tcp docker_mysql
# docker rm 6a9ad568a182
# docker run-- expose=3306-p 3306-- name docker_mysql-v / data/datadir:/var/lib/mysql-e MYSQL_ROOT_PASSWORD=123456-d mysql:5.7-- character-set-server=utf8mb4-- collation-server=utf8mb4_unicode_ci
I connect to mysql again and find that the database test and table stu I just created are still there, and there is a piece of data. It feels like container, similar to a normal mysql process. Like a normal mysql process
You can start, close, delete, and load data files.
At this point, the study on "how to install and use mysql's docker" 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.