MySQL Docker Container
2022/4/28 19:12:42
本文主要是介绍MySQL Docker Container,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Official Document
MySQL - Official Image | Docker Hub
MySQL :: MySQL 8.0 Reference Manual :: 4.5.4 mysqldump — A Database Backup Program
MySQL——mysqldump参数大全
Practice In Action
Use MySQL Image
[ ~ Approach I ~ ]
Start MySQL Server Instance
version: '3.1' services: mysql: image: mysql:8.0 restart: unless-stopped volumes: - ./{some/path/on/your/host}/datadir /var/lib/mysql ports: - {mapping_port}: 3306 environment: MYSQL_ROOT_PASSWORD: {MYSQL_ROOT_PASSWORD} MYSQL_DATABASE: {database} MYSQL_USER: {username} MYSQL_PASSWORD: {MYSQL_PASSWORD}
docker compose -f stack.yml up/down
Connect to MySQL
docker compose -f stack.yml start/restart/stop docker compose -f stack.yml images/logs
[ ~ Approach II ~ ]
docker run -p {mapping_port}:3306 --name mysql -v ./{some/path/on/your/host}/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD={MYSQL_ROOT_PASSWORD} -d mysql:{tag}
Manage Image/Container
docker image ls -a
docker container ls -a docker container create/run {IMAGE_ID/REPOSITORY} docker container start/restart/stop/stats {CONTAINER_ID/NAMES} docker container logs/rm {CONTAINER_ID/NAMES} docker container prune -- Remove unused containers
docker image history/rm {IMAGE_ID/REPOSITORY} docker image prune -- Remove unused images
Container Shell Access MySQL
docker logs {CONTAINER_ID/NAMES} docker exec -it {CONTAINER_ID/NAMES} bash root@{CONTAINER_ID}:/# mysqldump -u root -p {databasename} {tablename1} {tablename2} {...} {tablenameN} --no-create-info --complete-insert > /var/lib/mysql/{database}.sql root@{CONTAINER_ID}:/# mysql -u root -p mysql> use {databasename} mysql> source /var/lib/mysql/{databasename}.sql
docker exec {CONTAINER_ID/NAMES} sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > ./{some/path/on/your/host}/all-databases.sql docker exec -i {CONTAINER_ID/NAMES} sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD"' < ./{some/path/on/your/host}/all-databases.sql
MySQL
- Turn Off SQL_MODE - ONLY_FULL_GROUP_BY
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
- Get TABLE_ROWS/AUTO_INCREMENT
SELECT TABLE_NAME, TABLE_ROWS FROM information_schema.TABLES WHERE TABLE_SCHEMA = '{tablename}' and TABLE_ROWS > 0 ORDER BY TABLE_NAME; SELECT TABLE_NAME, sum(TableA) TableA, sum(TableB) TableB FROM (SELECT TABLE_NAME, case when TABLE_SCHEMA='{tablenameA}' then AUTO_INCREMENT else 0 end TableA, case when TABLE_SCHEMA='{tablenameB}' then AUTO_INCREMENT else 0 end TableB FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA in ('{tablenameA}', '{tablenameB}') AND AUTO_INCREMENT > 1 group by TABLE_SCHEMA, TABLE_NAME) w group by TABLE_NAME order by TABLE_NAME;
这篇关于MySQL Docker Container的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-02MySQL 3主集群搭建
- 2024-12-25如何部署MySQL集群资料:新手入门教程
- 2024-12-24MySQL集群部署资料:新手入门教程
- 2024-12-24MySQL集群资料详解:新手入门教程
- 2024-12-24MySQL集群部署入门教程
- 2024-12-24部署MySQL集群学习:新手入门教程
- 2024-12-24部署MySQL集群入门:一步一步搭建指南
- 2024-12-07MySQL读写分离入门:轻松掌握数据库读写分离技术
- 2024-12-07MySQL读写分离入门教程
- 2024-12-07MySQL分库分表入门详解