illustrate
Continuing from [Part 1] Docker Compose builds mysql master-slave replication , this article introduces how to build `mycat middleware`, and use `mycat` to do `read-write separation`.
Configuration file and document address: [mycat-rw](http://git.oschina.net/wangjingj/mycat-rw)
system environment
-
docker 1.12.3
-
mysql5.7.17
-
deepin 15.3 desktop version (this does not matter, because we use docker)
-
mycat1.6
Key points
-
See the detailed introduction of the previous article
-
Expose `mysql` `mycat` port number for easy management
-
This article starts directly from `docker-compose.yml`
docker-compose.yml文件
For convenience, let's post them all together.
mycat configuration
This is just a successful configuration, please refer to the mycat authoritative guide for detailed configuration rules.
-
schema.xml placement
-
server.xml configuration
-
log4j2.xml configuration
This changes the log level to debug, which is convenient for us to observe the test.
-
mycat的Dockerfile
start up
Run in the `docker-compose.yml` file directory
If there is no image file corresponding to the container, `docker-compose` will automatically build the image.
Command to build images manually using `docker-compose`: `docker-compose build mycat`
If the command is executed successfully, the containers mycat, m1, s1, and s2 have been started successfully.
Let's take a look with `docker ps -a`.
test
-
Enter the mycat client
-
execute select statement
Because the master-slave replication test has been done in the previous article, we will not repeat this place. We directly execute the `select` statement to see if the read-write separation has been achieved.
Result set:
Then we open mycat's log mycat.log to see
Pay attention to the places marked in the picture.
Well, from the log we can see that the `select` statement we executed was executed from the library s1.
-
Execute the insert statement
Open the log mycat.log of mycat and take a look
This time we found that executing the `insert` statement is the main library m1.
Summarize
In short, an instance of using `mycat middleware` to build mysql 1 master 2 slave master-slave replication and read-write separation is completed.
It is very simple to say why `mycat database middleware` is used, because it basically has no impact on developers and will not invade into the code.
If you support it, please like it, if you don't like it, please give it a thumbs up.
A little bit every day, grow a little bit more.