当前位置:   article > 正文

使用docker容器创建MySQL数据库_docker启动mysql时加入创建库的语句

docker启动mysql时加入创建库的语句

常见docker

预习:

使用到的docker命令:

docker images   显示本地有的镜像

docker pull +镜像名称   从docker hub上面拉取镜像

docker run
   --name  定义容器的名称

   -d  让docker容器在后台运行到

   -a 查看已经创建的容器

   -s  查看启动的容器

docker start docker_name   启动名称为docker_name的容器

docker stop docker_name   关闭名称为docker_name的容器

docker rm docker_name     删除名称为docker_name的容器

docker rmi docker_name   删除名称为docker_name的镜像

docker rename old_name new_name 给容器重命名

操作:

[root@localhost ~]# docker pull mysql   拉取镜像

[root@localhost ~]# docker images|grep mysql   查看镜像
docker.io/mysql     latest              6a834f03bd02        2 weeks ago         484 MB
[root@localhost ~]# docker run -e MYSQL_ROOT_PASSWORD=123456 --name mysql -it mysql      启动一个容器

[root@localhost ~]# docker ps -s      查看正在运行的容器
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                 NAMES               SIZE
dc1c39266b16        mysql               "docker-entrypoint..."   3 days ago          Up 2 hours          3306/tcp, 33060/tcp   mysql               119 B (virtual 484 MB)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

连接MySQL数据库

[root@localhost ~]# docker exec -it dc1c39266b16 bash
root@dc1c39266b16:/# mysql -uroot -p         
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.12 MySQL Community Server - GPL
Copyright (c) 2000, 2018, 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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

已经连接上数据库了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/461468
推荐阅读
相关标签
  

闽ICP备14008679号