docker安装mysql

简单介绍下使用docker安装mysql。

1、查找镜像,docker search mysql

[root@*** ~]# docker search mysql
NAME                              DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
mysql                             MySQL is a widely used, open-source relation…   8696                [OK]                
mariadb                           MariaDB is a community-developed fork of MyS…   3036                [OK]                
mysql/mysql-server                Optimized MySQL Server Docker images. Create…   643                                     [OK]
centos/mysql-57-centos7           MySQL 5.7 SQL database server                   63                                      
centurylink/mysql                 Image containing mysql. Optimized to be link…   61                                      [OK]
mysql/mysql-cluster               Experimental MySQL Cluster Docker images. Cr…   53                                      
deitch/mysql-backup               REPLACED! Please use http://hub.docker.com/r…   41                                      [OK]
bitnami/mysql                     Bitnami MySQL Docker Image                      36                                      [OK]
tutum/mysql                       Base docker image to run a MySQL database se…   34                                      
schickling/mysql-backup-s3        Backup MySQL to S3 (supports periodic backup…   28                                      [OK]
prom/mysqld-exporter                                                              23                                      [OK]
linuxserver/mysql                 A Mysql container, brought to you by LinuxSe…   22                                      
centos/mysql-56-centos7           MySQL 5.6 SQL database server                   16                                      
circleci/mysql                    MySQL is a widely used, open-source relation…   15                                      
mysql/mysql-router                MySQL Router provides transparent routing be…   13                                      
arey/mysql-client                 Run a MySQL client from a docker container      11                                      [OK]
imega/mysql-client                Size: 36 MB, alpine:3.5, Mysql client: 10.1.…   8                                       [OK]
openshift/mysql-55-centos7        DEPRECATED: A Centos7 based MySQL v5.5 image…   6                                       
yloeffler/mysql-backup            This image runs mysqldump to backup data usi…   6                                       [OK]
fradelg/mysql-cron-backup         MySQL/MariaDB database backup using cron tas…   4                                       [OK]
ansibleplaybookbundle/mysql-apb   An APB which deploys RHSCL MySQL                2                                       [OK]
genschsa/mysql-employees          MySQL Employee Sample Database                  2                                       [OK]
jelastic/mysql                    An image of the MySQL database server mainta…   1                                       
monasca/mysql-init                A minimal decoupled init container for mysql    0                                       
widdpim/mysql-client              Dockerized MySQL Client (5.7) including Curl…   0                                       [OK]

2、拉取5.7版本的mysql镜像,docker pull mysql:5.7

[root@*** ~]# docker pull mysql:5.7
5.7: 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 
c7d49ffebc56: Pull complete 
511a8052b204: Downloading 
5d5df4c12444: Download complete 
d482603a2922: Download complete 
5.7: 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 
c7d49ffebc56: Pull complete 
511a8052b204: Pull complete 
5d5df4c12444: Pull complete 
d482603a2922: Pull complete 
Digest: sha256:44b33224e3c406bf50b5a2ee4286ed0d7f2c5aec1f7fdb70291f7f7c570284dd
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
You have new mail in /var/spool/mail/root
[root@*** ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               5.7                 cd3ed0dfff7e        2 hours ago         437MB
hello-world         latest              fce289e99eb9        9 months ago        1.84kB

3、运行,docker run -d --name mysqltest -p 3306:3306 -e MYSQL_ROOT_PASSWORD=su123456 mysql:5.7

[root@*** ~]# docker run -d --name mysqltest -p 3306:3306 -e MYSQL_ROOT_PASSWORD=su123456 mysql:5.7
f4dd97812996f33900cecfaae888d09ca7c2cfd3237ebfc4a1a6e67a836e6198

 -d :后台运行;

--name mysqltest:容器名称;

-p 3306:3306:将主机的3306端口和容器的3306端口绑定在一起,前面的3306指的是主机的端口;

-e MYSQL_ROOT_PASSWORD=su123456:设置mysql的root密码;

mysql:5.7:使用5.7版本的mysql镜像。

4、使用工具(Navicat for Mysql)测试连接

如果不能连接,则需要设置下安全组或者关闭防火墙。

5、连接上就可以直接使用mysql。

 

 

如果有写的不对的地方,请大家多多批评指正,非常感谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值