访问 MySQL 镜像库地址:https://hub.docker.com/_/mysql?tab=tags 。
可以通过 Sort by 查看其他版本的 MySQL,默认是最新版本 mysql:latest 。
此外,我们还可以用 docker search mysql 命令来查看可用版本:
root@localhost ~]# docker search mysql INDEX NAME DEscriptION STARS OFFICIAL AUTOMATED docker.io docker.io/mysql MySQL is a widely used, open-source relati... 11480 [OK] docker.io docker.io/mariadb MariaDB Server is a high performing open s... 4356 [OK] docker.io docker.io/mysql/mysql-server Optimized MySQL Server Docker images. Crea... 849 [OK] docker.io docker.io/percona Percona Server is a fork of the MySQL rela... 557 [OK] docker.io docker.io/phpmyadmin phpMyAdmin - A web interface for MySQL and... 332 [OK] docker.io docker.io/centos/mysql-57-centos7 MySQL 5.7 SQL database server 91 docker.io docker.io/mysql/mysql-cluster Experimental MySQL Cluster Docker images. ... 88 docker.io docker.io/centurylink/mysql Image containing mysql. Optimized to be li... 59 [OK] docker.io docker.io/databack/mysql-backup Back up mysql databases to... anywhere! 51 docker.io docker.io/prom/mysqld-exporter 42 [OK] docker.io docker.io/deitch/mysql-backup REPLACeD! Please use http://hub.docker.com... 41 [OK] ......拉取 MySQL 镜像
这里我们拉取官方的最新版本的镜像:
docker pull mysql:latest
Trying to pull repository docker.io/library/mysql ... latest: Pulling from docker.io/library/mysql 07aded7c29c6: Pulling fs layer f68b8cbd22de: Download complete 30c1754a28c4: Downloading [===============> ] 1.265 MB/4.179 MB 1b7cb4d6fe05: Waiting 79a41dc56b9a: Waiting 00a75e3842fb: Waiting b36a6919c217: Waiting 635b0b84d686: Waiting 6d24c7242d02: Waiting 5be6c5edf16f: Waiting cb35eac1242c: Waiting a573d4e1c407: Waiting查看本地镜像
docker images
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/mysql latest 2fe463762680 22 hours ago 514 MB docker.io/java 8 d23bdf5b1b1b 4 years ago 643 MB docker.io/ubuntu 15.10 9b9cb95443b5 5 years ago 137 MB运行容器
安装完成后,我们可以使用以下命令来运行 mysql 容器:
docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
参数说明:
-p 3306:3306 :映射容器服务的 3306 端口到宿主机的 3306 端口,外部主机可以直接通过 宿主机ip:3306 访问到 MySQL 的服务。
MYSQL_ROOT_PASSWORD=123456:设置 MySQL 服务 root 用户的密码。
通过 docker ps 命令查看是否安装成功:
[root@localhost ~]# docker ps ConTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e5f364c8eea5 mysql "docker-entrypoint..." 13 seconds ago Up 11 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql 4b567ab8009e docker.io/java:8 "/bin/bash" 27 minutes ago Up 27 minutes java-jdk8
本机可以通过 root 和密码 123456 访问 MySQL 服务。
root@e5f364c8eea5:/# mysql -h localhost -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 8 Server version: 8.0.26 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>
问题:
[root@localhost ~]# mysql -h localhost -u root -p -bash: mysql: 未找到命令 [root@localhost ~]# docker exec -itd mysql "docker exec" requires at least 2 argument(s). See 'docker exec --help'. Usage: docker exec [OPTIONS] ConTAINER COMMAND [ARG...] Run a command in a running container
办法
[root@localhost ~]# docker exec -it e5f364c8eea5 bash用客户端navicat测试连接提示
navicat for mysql 链接时报错:1251-Client does not support authentication protocol requested by server
查看更多: 我的博客.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)