docker拉取mysql镜像:

[mall@VM_0_7_centos ~]$ sudo 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: 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

  docker拉取mysql之后,我们来启动它:  

[mall@VM_0_7_centos ~]$ sudo   docker run -p : --name mysql \
> -v /mydata/mysql/log:/var/log/mysql \
> -v /mydata/mysql/data:/var/lib/mysql \
> -v /mydata/mysql/conf:/etc/mysql \
> -e MYSQL_ROOT_PASSWORD=root \
> -d mysql:5.7
[sudo] password for mall:
8030a830a7b8af46fefd197e37c91cccfce867eb3593b08a64050fc90fefb98f

  参数说明:

  --name mysql:自定义容器名为“mysql”

  -p 3306:3306:前者是你当前主机的3306端口,后者是当前容器中的3306端口,做了一个映射

  -v /mydata/mysql/conf:/etc/mysql:将容器的配置文件夹/etc/mysql挂在到当前主机/mydata/mysql/conf

  -v /mydata/mysql/log:/var/log/mysql:将容器的日志文件夹/var/log/mysql挂载到当前主机/mydata/mysql/log

  -v /mydata/mysql/data:/var/lib/mysql/:将容器的数据文件夹/var/lib/mysql挂载到当前主机/mydata/mysql/data

  -e MYSQL_ROOT_PASSWORD=root:初始化root用户的密码为root

  我们进入该容器,登入mysql并创建新数据库mall:

[mall@VM_0_7_centos ~]$ sudo docker exec -it mysql /bin/bash
[sudo] password for mall:
root@8030a830a7b8:/# mysql -uroot -proot --default-character-set=utf8
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
Server version: 5.7. MySQL Community Server (GPL) Copyright (c) , , 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> create database mall character set utf8;
Query OK, 1 row affected (0.00 sec)

  将sql文件上传至本地:

[mall@VM_0_7_centos ~]$ cd mydata
[mall@VM_0_7_centos mydata]$ rz -y
rz waiting to receive.
zmodem trl+C ȡ % KB KB/s :: Errors

  从本地复制sql文件到docker:

[mall@VM_0_7_centos ~]$ sudo docker cp mydata/mall.sql mysql:/
[sudo] password for mall:

  重新登入mysql,进入mall数据库,执行导入操作:

mysql> use mall;
mysql> source /mall.sql;

  创建新账号,赋予所有权限给其他ip访问:

mysql> grant all privileges on *.* to 'reader' @'%' identified by '';
Query OK, rows affected, warning (0.00 sec)

最新文章

  1. github fork后的pull和保持同步
  2. 2016中国大学生程序设计竞赛(长春) Ugly Problem 模拟+大数减法
  3. Index on DB2 for z/OS: DB2 for z/OS 的索引
  4. git提交报异常,fatal: The remote end hung up unexpectedly
  5. python2.7使用ansible
  6. UI2_ScrollView&UIPageControl
  7. Spark_Api_图解
  8. 动态调用DLL函数有时正常,有时报Access violation的异常
  9. .Net XML操作 <第二篇>
  10. node.js入门(三)调式
  11. ruby操作mongo DB
  12. Redux源码分析之applyMiddleware
  13. OFFICE2007软件打开word时出现SETUP ERROR的解决方法
  14. Spring Cloud 2-Hystrix DashBoard仪表盘(五)
  15. layui 表格内容显示更改
  16. 3分钟学会如何调度运营海量Redis系统
  17. Windows环境下利用anaconda3安装python版本的Xgboost
  18. 阿里云负载均衡SLB 七层https协议 nginx 获取真实IP
  19. 一篇入门 -- Scala
  20. Weighted Channel Dropout for Regularization of Deep Convolutional Neural Network

热门文章

  1. NPOI - .NET Excel & Word操作组件
  2. JUC-10-ReadWriteLock读写锁
  3. TortoiseGit-下载安装汉语语言包(汉化-方法)
  4. Codeforces Round #604 (Div. 2) A,B,C【D题待补】
  5. mysql5.7的手动安装
  6. HDP 大数据平台搭建
  7. Kylin 架构模块简介
  8. Xshell5 安装JDK
  9. mysqli扩展有一系列的优势,相对于mysql扩展的提升主要优势有哪些?
  10. 《挑战30天C++入门极限》c++中指针学习的两个绝好例子