Home > Database > Mysql Tutorial > body text

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

PHPz
Release: 2023-05-27 13:34:12
forward
1483 people have browsed it

    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
    Copy after login

    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"
    Copy after login
    docker exec myMysql bash -c "echo 'server-id=123454' >> /etc/mysql/mysql.conf.d/mysqld.cnf"
    Copy after login

    4. Restart the mysql mirror

    docker restart myMysql
    Copy after login

    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!

    Related labels:
    source:yisu.com
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template