Docker容器运行、连接MySQL镜像

本文介绍了在Win10专业版上使用Docker 19.03.2安装并运行MySQL镜像的详细步骤,包括拉取镜像、端口映射、设置root密码、允许远程登录及检查MySQL服务状态。同时,文章提到了通过本地客户端连接容器内MySQL服务时遇到的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Docker安装、运行MySql镜像

环境信息 :Win10专业版
Docker :19.03.2
在这里插入图片描述

操作步骤

1.拉取运行MySql

PS C:\Users\admin> docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
80369df48736: Pull complete 
e8f52315cb10: Pull complete 
cf2189b391fc: Pull complete 
cc98f645c682: Pull complete 
27a27ac83f74: Pull complete 
fa1f04453414: Pull complete 
d45bf7d22d33: Pull complete 
3dbac26e409c: Pull complete 
9017140fb8c1: Pull complete 
b76dda2673ae: Pull complete 
bea9eb46d12a: Pull complete 
e1f050a38d0f: Pull complete 
Digest: sha256:7345ce4ce6f0c1771d01fa333b8edb2c606ca59d385f69575f8e3e2ec6695eee
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest                            

2.后台运行一个名为myDockerMysql的mysql实例,使用Docker容器的3306端口映射我们本地3306端口,root密码为123123

PS C:\Users\admin> docker run --name myDockerMysql -e MYSQL_ROOT_PASSWORD=123123 -d -p 3306:3306 mysql
ce10ad37915dde92f04c4e95fb08eca2a4169e8b86d5485ebe32b5952f1fbb49

图示:
在这里插入图片描述
3.进入myDockerMysql的mysql实例的Docker容器,执行命令给root开启可远程登录

#进入myDockerMysql容器 windows下老版本powerShell执行要加winpty
$ docker exec -it myDockerMysql bash
root@84ec54033d15:/#
#在容器内登陆Mysql
root@84ec54033d15:/# mysql -u root -p
#查看用户信息
root@84ec54033d15:/# select host,user,plugin,authentication_string from mysql.user;
#更新root连接信息
root@84ec54033d15:/# ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123123';
root@84ec54033d15:/# FLUSH PRIVILEGES;
#查看用户信息
root@84ec54033d15:/# select host,user,plugin,authentication_string from mysql.user;
#退出
root@84ec54033d15:/# exit;

图示:
在这里插入图片描述
4.查看容器内MySQL运行状况

可通过命令docker ps或者Portainer工具查看容器内MySQL运行情况:
在这里插入图片描述
5.使用客户端连接容器内运行的MySQL

在这里插入图片描述随便找个表查一查:
在这里插入图片描述
通过虚拟出来的IP访问,连接不上:
在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值