首页 > 数据库 >44_docker-compose_mysql5.7

44_docker-compose_mysql5.7

时间:2024-03-13 11:01:41浏览次数:24  
标签:bin compose log mysql5.7 mysql var docker 44

1. 安装 Docker-compose
curl -L "https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-\$(uname -s)-\$(uname -m)" -o /usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
2.拉取镜像
docker pull registry.cn-hangzhou.aliyuncs.com/ns-2023/lib-2023:mysql-5.7
3. 配置文件 my.conf
[mysqld]
user=mysql                     # MySQL启动用户
default-storage-engine=INNODB  # 创建新表时将使用的默认存储引擎
character-set-server=utf8mb4      # 设置mysql服务端默认字符集
pid-file        = /var/run/mysqld/mysqld.pid  # pid文件所在目录
socket          = /var/run/mysqld/mysqld.sock # 用于本地连接的socket套接字
datadir         = /var/lib/mysql              # 数据文件存放的目录
#log-error      = /var/log/mysql/error.log
#bind-address   = 127.0.0.1                   # MySQL绑定IP
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION # 定义mysql应该支持的sql语法,数据校验等!

# 允许最大连接数
max_connections=200

# ================= ↓↓↓ mysql主从同步配置start ↓↓↓ =================

# 同一局域网内注意要唯一
server-id=3306
# 开启二进制日志功能 & 日志位置存放位置`/var/lib/mysql`
#log-bin=mysql-bin
log-bin=/var/lib/mysql/mysql-bin
# binlog格式
# 1. STATEMENT:基于SQL语句的模式,binlog 数据量小,但是某些语句和函数在复制过程可能导致数据不一致甚至出错;
# 2. MIXED:混合模式,根据语句来选用是 STATEMENT 还是 ROW 模式;
# 3. ROW:基于行的模式,记录的是行的完整变化。安全,但 binlog 会比其他两种模式大很多;
binlog_format=ROW
# FULL:binlog记录每一行的完整变更 MINIMAL:只记录影响后的行
binlog_row_image=FULL
# 日志文件大小
# max_binlog_size=1G
max_binlog_size=100M
# 定义清除过期日志的时间(这里设置为7天)
expire_logs_days=7

# ================= ↑↑↑ mysql主从同步配置end ↑↑↑ =================

[mysql]
default-character-set=utf8mb4

[client]
default-character-set=utf8mb4  # 设置mysql客户端默认字符集
4. docker-compose.yml
version: "3"
services:
  mysql:
    image: registry.cn-hangzhou.aliyuncs.com/ns-2023/lib-2023:mysql-5.7 # 原镜像`mysql:5.7`
    container_name: mysql_3306 # 容器名为'mysql_3306'
    restart: unless-stopped # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器
    volumes: # 数据卷挂载路径设置,将本机目录映射到容器目录
      - "./mysql/my.cnf:/etc/mysql/my.cnf"
      - "./mysql/data:/var/lib/mysql"
      #      - "./mysql/conf.d:/etc/mysql/conf.d"
      - "./mysql/log/mysql/error.log:/var/log/mysql/error.log"
      - "./mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d" # 可执行初始化sql脚本的目录 -- tips:`/var/lib/mysql`目录下无数据的时候才会执行(即第一次启动的时候才会执行)
    environment: # 设置环境变量,相当于docker run命令中的-e
      TZ: Asia/Shanghai
      LANG: en_US.UTF-8
      MYSQL_ROOT_PASSWORD: root # 设置root用户密码
      MYSQL_DATABASE: demo # 初始化的数据库名称
    ports: # 映射端口
      - "3306:3306"
mysql/docker-entrypoint-initdb.d/init.sql
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
create database zq;
SET FOREIGN_KEY_CHECKS = 1;
5. 运行
docker-compose -f docker-compose.yml -p mysql57 up -d
docker exec -it mysql_3306 /bin/bash
  mysql -uroot -proot

标签:bin,compose,log,mysql5.7,mysql,var,docker,44
From: https://www.cnblogs.com/ckh2023/p/18070158

相关文章

  • 46_docker-compose_nginx
    1.安装Docker-composecurl-L"https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-$(uname-s)-$(uname-m)"-o/usr/local/bin/docker-composechmod+x/usr/local/bin/docker-composeln-s/usr/local/bin/docker-compose/usr/b......
  • docker-compose 部署gitlab
    主机ip:192.168.1.139[root@localhostgitlab_docker]#catdocker-compose.ymlversion:'3.1'services:gitlab:image:'gitlab/gitlab-ce:latest'container_name:gitlab#随着docker重启自动启动restart:alwaysenvironment:......
  • windwos下mysql5.7安装connection_control插件,限制多次登录失败,限定用户重试时间
    启动时加载插件,在配置文件中修改后重启服务[mysqld]plugin-load-add=connection_control.dll运行时加载插件INSTALLPLUGINCONNECTION_CONTROLSONAME'connection_control.dll';INSTALLPLUGINCONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTSSONAME'connection_control.dl......
  • docker-compose 部署apollo
    apollo-1.9.2docker-compose.yamlversion:'3'services:#模拟一个正常的mysql数据库mysql8:image:mysql:5.7restart:alwayscontainer_name:mysqlports:-3306:3306volumes:-./databases/mysql/logs:/var/log/mysql......
  • docker-compose 部署nacos
    version:'3'services:#模拟一个正常的mysql数据库mysql8:image:mysql:5.7restart:alwayscontainer_name:mysqlports:-3306:3306volumes:-./databases/mysql/logs:/var/log/mysql-./databases/mysql/data:/v......
  • 844. 比较含退格的字符串c
    boolbackspaceCompare(char*s,char*t){intns=strlen(s),nt=strlen(t);inthead=0,tail=0;intn1=0,n2=0;while(tail<ns){if(head==0&&s[tail]=='#'){tail++;}elseif(s[tail]=='#')......
  • hadoop报错:is running 446528000B beyond the 'VIRTUAL' memory limit
    发现问题今天在配置hadoop文件时,报错:isrunning446528000Bbeyondthe'VIRTUAL'memorylimit.Currentusage:73.9MBof1GBphysicalmemoryused;2.5GBof2.1GBvirtualmemoryused.Killingcontainer.意思是虚拟内存,超出了限制。然后将虚拟机内存改为3G关闭集群......
  • CentOS 安装 Docker Compose(curl 方式)
    CentOS安装DockerCompose(curl方式)下载运行此命令下载最新版本的DockerCompose:sudocurl-Lhttps://github.com/docker/compose/releases/download/v2.20.0/docker-compose-`uname-s`-`uname-m`-o/usr/local/bin/docker-composedocker-compose2.20.0Linux64位版......
  • AtCoder Beginner Contest 344 A-G 题解
    AtCoderBeginnerContest344A-SpoilerQuestion删除两个|之间的字符Solution按照题意模拟即可Code#include<bits/stdc++.h>usingnamespacestd;intmain(){strings;cin>>s;stringp1,p2;for(inti=0;i<s.size();i++){......
  • windows安装composer并更换国内镜像
    windows安装composer并更换国内镜像第一步、官网下载下载地址Composer安装https://getcomposer.org/Composer-Setup.exe第二步、双击安装即可 第三步选择php安装路径并配置path 第四步、composer-v查看安装是否成功,出现成功界面 第五步、查看镜像地址并更换(comp......