Build mysql master and slave based on Docker container
1. Download the Docker image, which is not described in detail here
2. Create a temporary image, map the file, and copy the configuration
Docker exec-it container id /bin/bash docker exec-it container id /bin/bash docker exec-it container id /bin/bash Because the app folder inside the container is mapped to the external app folder, the copied files will also appear in the external folder.
3. Delete the temporary image file to create our first Master1 node
docker run --privileged=true --name master1 -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -v / mydata/mysql/master1 / conf. D: / etc/mysql/conf., d - v/mydata/mysql/master1. / my CNF: / etc/mysql/my CNF - d mysql: 5.7Copy the code
After the first master node is successfully created, the other nodes are created.
4. Modify the configuration file
1. The first is the master node file
If not, restart the master node and enter the container to see if the mapping is successful
2. The slave node
2.1 Creating a Node
— link: the container is connected to the master1 node: alias master. If this parameter is not added, two containers of a docker network cannot communicate with each other
docker run --privileged=true --name slave1 --link master1:master -e MYSQL_ROOT_PASSWORD=123456 -p 3307:3306 -v / mydata/mysql/slave1 / conf. D: / etc/mysql/conf., d - v/mydata/mysql/slave1 / my CNF: / etc/mysql/my CNF - d mysql: 5.7Copy the code
2.2 Modifying the Configuration File
After startup, change the server- ID, remember not to be the same as the primary node, enable binary log (copy and paste to change the server- ID), there is no other description.
2.3 Specify master synchronization information on slvae
>master_log_file: specifies the name of the binary file to use for synchronization, which can be viewed on the primary node. Master_log_pos: indicates the starting position of binary log synchronization.Copy the code
3. Check whether the primary/secondary communication is successful
- Create a new Mall database on the primary node and create a new USR table
- Switch to the view from the library, the corresponding database and table also appear in the library, you can try the next wave.