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 install mysql in docker

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces how to install mysql in docker, which is very detailed and has certain reference value. Friends who are interested must finish it!

1. Find mysql image on docker hub

[root@t-docker tomcatlogs] # docker search mysqlNAME DESCRIPTION STARS OFFICIAL AUTOMATEDmysql MySQL is a widely used, open-source relation... 6845 [OK] mariadb MariaDB is a community-developed fork of MyS... 2185 [OK] mysql/mysql-server Optimized MySQL Server Docker images. Create... [OK] percona Percona Server is a fork of the MySQL relati... 365 [OK] zabbix/zabbix-server-mysql Zabbix Server with MySQL database support 120

2. Pull the mysql image from the docker hub (or Aliyun Accelerator) to the local

[root@t-docker tomcatlogs] # docker pull mysql:5.65.6: Pulling from library/mysqlbe8881be8156: Already exists c3995dabd1d7: Pulling fs layer 9931fdda3586: Pulling fs layer bb1b6b6eff6a: Pulling fs layer a65f125fa718: Pulling fs layer 62fa8db7a5dc: Pulling fs layer a65f125fa718: Waiting 0f5681d76128: Pull complete 56d3348c5742: Pull complete b93f67de42c4: Pull complete 5adba6c10127: Pull complete Digest: sha256:2e48836690b8416e4890c369aa174fc1f73c125363d94d99cfd08115f4513ec9Status: Downloaded newer image for mysql:5.6 [root@t-docker tomcatlogs] # docker images mysqlREPOSITORY TAG IMAGE ID CREATED SIZEmysql 5.6 7edb93321b06 4 weeks ago 256MB

3. Use mysql image to create a container (also known as running image)

[root@t-docker chenzx] # docker run-p 12345 volume/mysql/logs:/logs 3306-- name mysql-v / volume/mysql/conf:/etc/mysql/conf.d-v / volume/mysql/logs:/logs-v / volume/mysql/data:/var/lib/mysql-e MYSQL_ROOT_PASSWORD=123456-d mysql:5.6

Command description:

-p 12345 3306: map port 12345 of the host to port 3306 of the docker container

-- name mysql: name of the running container

-v Mount the data volume on the host to the container

-e MYSQL_ROOT_PASSWORD=123456: password for initializing root

-d mysql:5.6: running mysql5.6 in the background

[root@t-docker chenzx] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES6dc80df5e339 mysql:5.6 "docker-entrypoint.s..." About a minute ago Up About a minute 0.0.0.0 About a minute ago Up About a minute 12345-> 3306/tcp mysql [root@t-docker chenzx] # docker exec-it 6dc80df5e339 / bin/bashroot@6dc80df5e339:/# mysql-uroot-p123456Warning: 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 1Server version: 5.6.41 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.mysql > status;-mysql Ver 14.14 Distrib 5.6.41, for Linux (x86 / 64) using EditLine wrapperConnection id:1Current database:Current user:root@localhostSSL:Not in useCurrent pager:stdoutUsing outfile:''Using delimiter:;Server version:5.6.41 MySQL Community Server (GPL) Protocol version:10Connection:Localhost via UNIX socketServer characterset:latin1Db characterset:latin1Client characterset:latin1Conn. Characterset:latin1UNIX socket:/var/run/mysqld/mysqld.sockUptime:5 min 10 secThreads: 1 Questions: 5 Slow queries: 0 Opens: 67 Flush tables: 1 Open tables: 60 Queries per second avg: 0.016-

4. Backup the MySQL in the docker container

[root@t-docker chenzx] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES6dc80df5e339 mysql:5.6 "docker-entrypoint.s..." 16 minutes ago Up 16 minutes 0.0.0.0 3306/tcp mysql 12345-> 3306/tcp mysql [root@t-docker chenzx] # docker exec 6dc80df5e339 sh-c 'exec mysqldump-uroot-p123456-B mysql' > mysql.sql is all the contents of this article "how to install mysql in docker". Thank you for reading! Hope to share the content to help you, more related knowledge, 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.

Share To

Development

Wechat

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

12
Report