Docker安装MySQL
docker search mysql
#搜索MySQL可用版本
代码语言:javascript复制[root@localhost ~]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11940 [OK]
mariadb MariaDB Server is a high performing open sou… 4562 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 896 [OK]
percona Percona Server is a fork of the MySQL relati… 567 [OK]
phpmyadmin phpMyAdmin - A web interface for MySQL and M… 419 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 92
mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 90
centurylink/mysql Image containing mysql. Optimized to be link… 59 [OK]
databack/mysql-backup Back up mysql databases to... anywhere! 54
prom/mysqld-exporter 46 [OK]
deitch/mysql-backup REPLACED! Please use http://hub.docker.com/r… 41 [OK]
tutum/mysql Base docker image to run a MySQL database se… 35
linuxserver/mysql A Mysql container, brought to you by LinuxSe… 34
schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup… 31 [OK]
mysql/mysql-router MySQL Router provides transparent routing be… 23
centos/mysql-56-centos7 MySQL 5.6 SQL database server 21
arey/mysql-client Run a MySQL client from a docker container 20 [OK]
fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron tas… 18 [OK]
openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6
ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 3 [OK]
idoall/mysql MySQL is a widely used, open-source relation… 3 [OK]
devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offici… 3
jelastic/mysql An image of the MySQL database server mainta… 2
centos/mysql-80-centos7 MySQL 8.0 SQL database server 2
widdpim/mysql-client Dockerized MySQL Client (5.7) including Curl… 1 [OK]
根据自己需要的版本进行下载镜像
如果使用最新镜像
代码语言:javascript复制docker pull mysql:latest
如果使用MySQL5.6版本
代码语言:javascript复制docker pull mysql:5.6
查看镜像
代码语言:javascript复制[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.6 dd3b2a5dcb48 2 weeks ago 303MB
mysql latest 3218b38490ce 2 weeks ago 516MB
运行容器
代码语言:javascript复制docker run -itd --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6
# -p 端口映射 3306(宿主机):3306(容器)
# -e 设置MySQL-root用户密码
查看容器运行情况
代码语言:javascript复制[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7494de6b0200 mysql:5.6 "docker-entrypoint.s…" 39 seconds ago Up 39 seconds 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp mysql
测试MySQL是否可以正常使用
代码语言:javascript复制[root@localhost ~]# docker exec -it mysql bash
root@7494de6b0200:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.6.51 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
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> show databases;
--------------------
| Database |
--------------------
| information_schema |
| mysql |
| performance_schema |
--------------------
3 rows in set (0.00 sec)
mysql>