时间:2021-07-01 10:21:17 帮助过:10人阅读
docker拉取mysql之后,我们来启动它:
先建好本地目录,以便跟docker做映射:
[mall@VM_0_7_centos ~]$ mkdir -p mydata/mysql/{log,lib,conf}
再执行启动命令,使用参数进行映射:
[mall@VM_0_7_centos ~]$ sudo docker run -p 3306:3306 --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 2 Server version: 5.7.28 MySQL Community Server (GPL) Copyright (c) 2000, 2019, 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 ? 100% 185 KB 185 KB/s 00:00:01 0 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 ‘123456‘; Query OK, 0 rows affected, 1 warning (0.00 sec)
docker安装并运行mysql
标签:安装 exe waiting 本地 complete ade community with 日志文件