基于docker的mysql8的主从复制
version: '3.7' services: db: # images 8.x image: mysql restart: always environment: MYSQL_ROOT_PASSWORD: 456123 command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp=true --lower_case_table_names=1 ports: - 3309:3306 volumes: - ./data:/var/lib/mysql - ./my.cnf:/etc/my.cnf
配置mysql的主库
-
更新配置文件
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # The MySQL Server configuration file. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html [mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql secure-file-priv= NULL # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Custom config should go here # [必须]启用二进制日志 log-bin=mysql-bin # [必须]服务器唯一ID,默认是1 1~255 server-id=1 sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
-
配置操作
-
启动mysql
docker-compose up -d
-
更新配置
-
查看容器
docker ps

-
进入mysql交互
docker exec -it 518a92715f6f /bin/bash
-
登录mysql
mysql -u root -p

-
配置
version: '3.7' services: db: # images 8.x image: mysql restart: always environment: MYSQL_ROOT_PASSWORD: 456123 command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp=true --lower_case_table_names=1 ports: - 3309:3306 volumes: - ./data:/var/lib/mysql - ./my.cnf:/etc/my.cnf
更新配置文件
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # The MySQL Server configuration file. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html [mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql secure-file-priv= NULL # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Custom config should go here # [必须]启用二进制日志 log-bin=mysql-bin # [必须]服务器唯一ID,默认是1 1~255 server-id=1 sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
配置操作
-
启动mysql
docker-compose up -d
-
更新配置
-
查看容器
docker ps
-
进入mysql交互
docker exec -it 518a92715f6f /bin/bash
-
登录mysql
mysql -u root -p
-
配置
-
-