×

使用Docker安装MySQL

hqy hqy 发表于2026-01-08 23:12:04 浏览19 评论0

抢沙发发表评论

1、安装Docker









# 安装Dockerhttps://docs.docker.com/get-docker/
# 安装Docker Composehttps://docs.docker.com/compose/install/
# CentOS安装Dockerhttps://mp.weixin.qq.com/s/nHNPbCmdQs3E5x1QBP-ueA
2、安装MySQL
创建目录:


mkdir mysqlcd mysql
2.1、方式1

创建docker-compose.yaml文件:












services:  mysql:    image: mysql:latest    container_name: mysql    environment:      MYSQL_ROOT_PASSWORD: "root"    ports:      - 3306:3306    volumes:      #- ./mysql.cnf:/etc/mysql/conf.d/mysql.cnf      - ./data:/var/lib/mysql
创建并启动容器:

docker-compose up -d
查看容器列表:

docker ps
停止并销毁容器:

docker-compose down
删除镜像:

docker rmi mysql:latest
删除目录:

rm -rf ./data
2.2、方式2
拉取镜像:

docker pull mysql:latest
运行容器:






docker run -d \  --name mysql \  -e MYSQL_ROOT_PASSWORD=root \  -p 3306:3306 \  -v ./data:/var/lib/mysql \  mysql:latest
查看容器列表:

docker ps
停止容器:

docker stop mysql
删除容器:

docker rm mysql
删除镜像:

docker rmi mysql:latest
删除目录:

rm -rf ./data
2.3、方式3








详见:https://dev.mysql.com/downloads/mysql/https://downloads.mysql.com/archives/community/https://dev.mysql.com/doc/refman/9.2/en/installing.htmlhttps://dev.mysql.com/doc/refman/9.2/en/binary-installation.htmlhttps://dev.mysql.com/doc/refman/9.2/en/linux-installation.htmlhttps://dev.mysql.com/doc/refman/9.2/en/source-installation.htmlhttps://github.com/docker-library/mysql

2.2 Installing MySQL on Unix/Linux Using Generic Binaries”:


详见:https://dev.mysql.com/doc/refman/9.2/en/binary-installation.html
图片
2.5.6.1 Basic Steps for MySQL Server Deployment with Docker”:

详见:https://dev.mysql.com/doc/refman/9.2/en/docker-mysql-getting-started.html
图片
图片
图片
2.8.4 Installing MySQL Using a Standard Source Distribution”:

详见:https://dev.mysql.com/doc/refman/9.2/en/installing-source-distribution.html
图片
3、测试





# 进入容器:docker exec -it mysql bash
# mysql客户端:mysql -uroot -proot
4、详见



https://www.mysql.com/https://github.com/mysql/mysql-serverhttps://github.com/docker-library/mysql


打赏

本文链接:https://kinber.cn/post/6139.html 转载需授权!

分享到:


推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

 您阅读本篇文章共花了: 

群贤毕至

访客