Preface This article records how I use docker-compose and dockerfile to build a MySQL master-slave environment based on binlog. If you strictly follow the steps in this article, I believe you can quickly build a basic MySQL master-slave environment. introduce MySQL master-slave synchronization is divided into 3 steps:
Configuration Create the Directory Structure First, let's get the directory structure. My directory structure is as follows. If you want to build the directory according to your own ideas, pay attention to modifying the file path in the docker-compose.yaml file and Dockerfile file below. Configure the docker-compose template file version: "3" services: mysql-master: build: context: ./ dockerfile:mysql/master/Dockerfile container_name: mysql-master volumes: - ./mysql/master/data:/var/lib/mysql restart: always ports: - 3305:3306 links: -mysql-slave mysql-slave: build: context: ./ dockerfile:mysql/slave/Dockerfile container_name: mysql-slave volumes: - ./mysql/slave/data:/var/lib/mysql restart: always ports: -3306:3306 Configure the cluster.cnf file and Dockerfile file of the master node [mysqld] server_id=100 binlog-ignore-db=mysql log-bin=replicas-mysql-bin binlog_cache_size=1M binlog_format=mixed slave_skip_errors=1062 # My MySQL is 8.x, so I need to configure default_authentication_plugin=mysql_native_password as follows character-set-server=utf8mb4 collation-server=utf8mb4_unicode_ci FROM mysql:latest ADD ./mysql/master/cluster.cnf /etc/mysql/conf.d/cluster.cnf ENV MYSQL_ROOT_PASSWORD=password Configure the cluster.cnf file and Dockerfile file of the slave node [mysqld] server_id=101 binlog-ignore-db=mysql binlog_cache_size=1M binlog_format=mixed slave_skip_errors=1062 relay_log=replicas-mysql-relay-bin log_slave_updates=1 read_only=1 # My MySQL is 8.x, so I need to configure default_authentication_plugin=mysql_native_password as follows character-set-server=utf8mb4 collation-server=utf8mb4_unicode_ci FROM mysql:latest ADD ./mysql/slave/cluster.cnf /etc/mysql/conf.d/cluster.cnf ENV MYSQL_ROOT_PASSWORD=password Create a container docker-compose up -d mysql-master mysql-slave Run the above command to create a container. If the build time is too long, you can consider changing the image source, such as the following domestic high-quality image sources: NetEase: http://hub-mirror.c.163.com Alibaba Cloud: http://< ;your ID>.mirror.aliyuncs.com University of Science and Technology of China: http://docker.mirrors.ustc.ed... After the build is complete, use the Configuring slave nodes First, use the docker command to enter the mysql-master container, then log in to mysql and enter the Next, use the docker command to enter the mysql-slave container, then log in to mysql and enter the following statement to connect to mysql-master. CHANGE MASTER TO MASTER_HOST='mysql-master', MASTER_USER='root', MASTER_PASSWORD=the password you set, MASTER_LOG_FILE=File parameter obtained in the previous step, MASTER_LOG_POS=Position parameter obtained in the previous step; After entering the command, type the Test the master-slave node synchronization status Log in to the mysql-master node and create a new database. After the database is created successfully, switch to the mysql-slave node and enter Summarize These are the steps I recorded when I tried to build a MySQL master-slave architecture. This is the end of this article about using Docker to build a MySQL master-slave environment. For more information about using Docker to build a MySQL master-slave environment, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: A brief discussion on the datetime format when exporting table data from MySQL to Excel
>>: Detailed explanation of the differences and applications of {{}}, v-text and v-html in Vue
This article shares 3 methods to achieve the spec...
<br />Introduction: This idea came to me whe...
1.17.9 More delicious, really Nginx download addr...
1. Introduction to Linux .NET Core Microsoft has ...
This article is based on the Windows 10 system en...
Preface Starting from React 16, the concept of Er...
Background - Online Alert An online server issued...
Some projects have relatively simple business, bu...
This article example shares the specific code of ...
MySQL replace and replace into are both frequentl...
Table of contents Event Loop miscroTask (microtas...
Table of contents What is async? Why do we need a...
1. Click Terminal below in IDEA and enter mvn cle...
Everyone must be familiar with table. We often en...
User table, ID number must be unique, mobile phon...