In development, it is necessary to monitor the data table by monitoring the binlog log file of mysql. Since mysql It is deployed in a docker container and needs to solve the problem of data volumes
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
Note: A file needs to be created in the host directory in advance Used to save the mysql data set. The directory I created here is /usr/docker/mysql/data
and /var/lib/mysql is the fixed directory after the mysql mirror is opened. Generally, we do not need to manually To remove interference, just keep the default one
Use the client connection tool to connect to mysql and try to observe the opening of mysql_binlog
You can see that the logging function is not enabled at this time. At the same time, we can also go to the mounting directory of the host to observe,
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"
docker restart myMysql
At this time, we will observe the changes in bin_log again, indicating that the bin_log log has been generated at this time.
Also You can enter the host directory to observe. At this time, the log file has been generated under the host
The above is the detailed content of How to use docker to enable mysql binlog to solve data volume problems. For more information, please follow other related articles on the PHP Chinese website!