<> preface

In development , Need to listen through mysql of binlog The log file can monitor the data table , because mysql Is deployed in docker In container , You also need to solve the problem of data volumes

1, Open a by way of data volume mysql image
docker run -p 3307:3306 --name myMysql -v
/usr/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d
mysql:5.7.25
remarks : You need to create a file in the host directory in advance for saving mysql Data set of , The directory I created here is /usr/docker/mysql/data

and /var/lib/mysql yes mysql Fixed directory after image opening , Generally, we don't need to interfere manually , Just keep the default

2, connect mysql And test

Connect using the client connection tool mysql, Try to observe mysql_binlog Opening of

You can see that the log function is not enabled at this time , At the same time, we can also go to the mount directory of the host to observe it ,

3, open bin_log

Execute the following commands in sequence
docker exec myMysql bash -c "echo 'log-bin=/var/lib/mysql/mysql-bin' >>
/etc/mysql/mysql.conf.d/mysqld.cnf" docker exec myMysql bash -c "echo
'server-id=123454' >> /etc/mysql/mysql.conf.d/mysqld.cnf"
4, restart mysql image
docker restart myMysql
5, Create a database and create a table and a piece of data in it

Then let's take another look bin_log Change of , Explain this time bin_log Your log has been generated

You can also enter the host directory for observation , At this time, a log file has been generated under the host computer

<> epilogue

The original intention of this article is to build it quickly mysql And find a way to detect it bin_log The log of is used later bin_log Purpose of detecting data changes in the table , So use docker Installation and startup mysql It's more convenient , But because it's the first attempt , When referring to relevant materials on the Internet, I found that the content of most blogs has not been verified , Or it is difficult to implement the effect , Finally, the above executable processes are summarized , Provide subsequent reference and use ! Friendly tips , Please refer to the information on the Internet carefully ! Finally, thanks for watching !

Technology
Daily Recommendation