• Docker中运行mysql


    一.下载镜像

    docker pull mysql:5.7

    二.使用镜像创建容器

    docker run --name HTMysql -p 8088:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
    #--name 设置容器的名称
    #-p        设置端口映射
    #-e        设置环境变量
    #-d        后台执行

    三.查看容器

    [root@oracle /]# docker ps 
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
    ea97399ff943        mysql:5.7           "docker-entrypoint..."   37 minutes ago      Up 15 minutes       33060/tcp, 0.0.0.0:8088->3306/tcp   HTMysql

    四.进入容器

    docker exec -it HTMysql /bin/bash

    五.连接mysql

    [root@oracle ~]# mysql -h 192.168.254.133 -P 8088 -u root -proot
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 6
    Server version: 5.7.29 MySQL Community Server (GPL)
    Copyright (c) 2000, 2020, 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> 

     六.把数据存储在本地目录

    docker run -d -e MYSQL_ROOT_PASSWORD=root --name HTMysql -v /data/mysql/my.cnf:/etc/mysql/my.cnf -v /data/mysql/data:/var/lib/mysql -p 8088:3306 mysql:5.7
    #-v:映射容器目录到本地
  • 相关阅读:
    JAVA web数据库登录界面
    JAVA web之相关名词大调查
    继承与多态课后
    第六周课后作业 02
    凯撒密文问题
    定义一个类,使用静态和构造随时知道定义了几个变量(第五周课后01)
    NAIPC2018
    [学习笔记]网络流
    Rikka with Prefix Sum
    Traffic Network in Numazu
  • 原文地址:https://www.cnblogs.com/HTLucky/p/12304895.html
Copyright © 2020-2023  润新知