0
点赞
收藏
分享

微信扫一扫

docker安装mysql

三分梦_0bc3 2022-02-14 阅读 50

docker安装mysql

1、首先安装好docker

2、拉取最新的mysql镜像版本

[root@mamba ~]# docker pull mysql:latest
latest: Pulling from library/mysql
72a69066d2fe: Pull complete 
93619dbc5b36: Pull complete 
99da31dd6142: Pull complete 
626033c43d70: Pull complete 
37d5d7efb64e: Pull complete 
ac563158d721: Pull complete 
d2ba16033dad: Pull complete 
688ba7d5c01a: Pull complete 
00e060b6d11d: Pull complete 
1c04857f594f: Pull complete 
4d7cfa90e6ea: Pull complete 
e0431212d27d: Pull complete 
Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709
Status: Downloaded newer image for mysql:latest

3、查看本地镜像

[root@mamba ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               latest              3218b38490ce        7 weeks ago         516MB

4、运行容器

[root@mamba ~]#  docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
b827facfe1926df7842f7a407d57e0458f26122a1576ba27203a676540f2c126

5、查看当前运行的容器

[root@mamba ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
b827facfe192        mysql               "docker-entrypoint.s…"   42 seconds ago      Up 40 seconds       0.0.0.0:3306->3306/tcp, 33060/tcp   mysql-test

6、进入到容器可以正常连接到mysql

[root@mamba ~]# docker exec -it mysql-test bash
root@b827facfe192:/# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
root@b827facfe192:/# mysql -h localhost -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> 
举报

相关推荐

Docker 安装 MySQL

Docker安装mysql

docker mysql安装

docker 安装 mysql

docker安装MySQL

0 条评论