配置简述
/etc/mysql/my.cnf #用于存储默认配置(有具体默认配置信息),mysq5.7这个配置文件里面引用了2个目录,用于配置默认配置和自定义配置
/etc/mysql/conf.d # 自定义添加修改配置信息配置
/var/lib/mysql #数据存放目录
- 创建挂载目录
mkdir -p /app/mysql/data
mkdir -p /app/mysql/conf
mkdir
- 赋予目录权限
chmod -R 777
- 创建mysql容器
docker run --name mysql-8.0.27 \
-d \
-p 3306:3306 \
-v /app/mysql/data:/var/lib/mysql \
-v /app/mysql/conf:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=123456 \
--restart always \
--privileged=true \
- 创建mysql容器并指定mysql容器编码
docker run --name mysql-8.0.27 \
-d \
-p 3306:3306 \
-v /app/mysql/data:/var/lib/mysql \
-v /app/mysql/conf:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=123456 \
--restart always \
--privileged=true \
mysql:8.0.27 \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci
- 启动容器过程中创建指定数据库
docker run --name mysql-8.0.27 \
-d \
-p 3306:3306 \
-v /app/mysql/data:/var/lib/mysql \
-v /app/mysql/conf:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=123456 \
-e MYSQL_DATABASE=gblfy \
--restart always \
--privileged=true \
mysql:8.0.27 \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci
- 启动容器过程中创建指定数据库,执行对应的sql文件
容器中执行sq的脚本目录:/docker-entrypoint-initdb.d
docker run --name mysql-8.0.27 \
-d \
-p 3306:3306 \
-v /app/mysql/data:/var/lib/mysql \
-v /app/mysql/conf:/etc/mysql/conf.d \
-v /app/mysql/sql/sys_user.sql:/docker-entrypoint-initdb.d/sys_user.sql \
-e MYSQL_ROOT_PASSWORD=123456 \
-e MYSQL_DATABASE=gblfy \
--restart always \
--privileged=true \
mysql:8.0.27 \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci
- 初始化表结构
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for sys_user
-- ----------------------------
DROP TABLE IF EXISTS `sys_user`;
CREATE TABLE `sys_user` (
`user_id` bigint NOT NULL AUTO_INCREMENT COMMENT '用户ID',
`dept_id` bigint NULL DEFAULT NULL COMMENT '部门ID',
`user_name` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '用户账号',
`nick_name` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '用户昵称',
`user_type` varchar(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '00' COMMENT '用户类型(00系统用户)',
`email` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '用户邮箱',
`phonenumber` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '手机号码',
`sex` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '0' COMMENT '用户性别(0男 1女 2未知)',
`avatar` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '头像地址',
`password` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '密码',
`status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '0' COMMENT '帐号状态(0正常 1停用)',
`del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)',
`login_ip` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '最后登录IP',
`login_date` datetime NULL DEFAULT NULL COMMENT '最后登录时间',
`create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '备注',
PRIMARY KEY (`user_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 100 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '用户信息表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of sys_user
-- ----------------------------
INSERT INTO `sys_user` VALUES (1, 1, 'gblfy专家', 'gblfy', '00', 'gblfy@163.com', '', '0', '', '', '0', '0', '', NULL, '', NULL, '', NULL, NULL);
- 启动容器过程中创建指定数据库,指定root密码,创建指定mysql用户并指定密码,执行对应的sql文件
容器中执行sq的脚本目录:/docker-entrypoint-initdb.d
docker run --name mysql-8.0.27 \
-d \
-p 3306:3306 \
-v /app/mysql/data:/var/lib/mysql \
-v /app/mysql/conf:/etc/mysql/conf.d \
-v /app/mysql/sql/sys_user.sql:/docker-entrypoint-initdb.d/sys_user.sql \
-e MYSQL_ROOT_PASSWORD=123456 \
-e MYSQL_DATABASE=gblfy \
-e MYSQL_USER=gblfy \
-e MYSQL_PASSWORD=gblfy \
--restart always \
--privileged=true \
mysql:8.0.27 \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci
- mysql5.7
mkdir -p /app/mysql/conf
mkdir -p /app/mysql/logs
mkdir -p /app/mysql/data
chmod -R 777 /app/mysql/
docker run --name mysql5.7 -d \
-p 3306:3306 \
-v /app/mysql/conf:/etc/my.cnf.d \
-v /app/mysql/logs:/logs \
-v /app/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
--restart always \
--privileged=true \