Home  >  Article  >  Database  >  How to use docker to enable mysql binlog to solve data volume problems

How to use docker to enable mysql binlog to solve data volume problems

PHPz
PHPzforward
2023-05-27 13:34:121482browse

    Preface

    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

    1. Open a mysql image through the data volume

    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

    2. Connect to mysql and test

    Use the client connection tool to connect to mysql and try to observe the opening of mysql_binlog

    How to use docker to enable mysql binlog to solve data volume problems

    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,

    How to use docker to enable mysql binlog to solve data volume problems

    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 the mysql mirror

    docker restart myMysql

    5. Create a database and create a table in it and add a piece of data

    How to use docker to enable mysql binlog to solve data volume problems

    At this time, we will observe the changes in bin_log again, indicating that the bin_log log has been generated at this time.

    How to use docker to enable mysql binlog to solve data volume problems

    Also You can enter the host directory to observe. At this time, the log file has been generated under the host

    How to use docker to enable mysql binlog to solve data volume problems

    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!

    Statement:
    This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete