MySQL 何时保存新的二进制日志文件?

huangapple go评论51阅读模式
英文:

When are mysql save a new binlog file?

问题

我正在开发一个Java应用程序来读取binlog文件以捕获查询事件。一切都会很顺利,没有异常。但是,如果我的应用程序崩溃了,我会错过很多来自我的数据库的事件。所以我想知道当MySQL保存新的binlog文件中的新binlog位置时会发生什么?这样我就可以保存一个检查点,以便不错过来自我的数据库的任何事件。

我用于读取MySQL binlog的外部库是:

<dependency>
    <groupId>com.github.shyiko</groupId>
    <artifactId>mysql-binlog-connector-java</artifactId>
    <version>0.21.0</version>
</dependency>
英文:

I'm developing 1 java application to reading a binlog file to catch query event. Everything would be fine without exception. But what will happen if my application was crashed, i will miss many event to from my database. So i wondering when mysql save new bin log position in a new binlog file? So i can save a checkpoint so as not to miss any event from my database.

My external library use to read binlog mysql :

&lt;dependency&gt;
    &lt;groupId&gt;com.github.shyiko&lt;/groupId&gt;
    &lt;artifactId&gt;mysql-binlog-connector-java&lt;/artifactId&gt;
    &lt;version&gt;0.21.0&lt;/version&gt;
&lt;/dependency&gt;

答案1

得分: 1

MySQL 在三种情况下会打开一个新的二进制日志文件:

  1. 当前的二进制日志文件超过了 max_binlog_size。文件可以略微超过这个大小,以允许当前事件完成写入。

  2. 一些客户端运行了 FLUSH LOGS 命令。例如,如果你使用了 --flush-logs 命令选项,mysqldump 会执行这个操作。

  3. MySQL 服务器重新启动。

英文:

MySQL opens a new binary log file in three cases:

  • The current binary log file exceeds max_binlog_size. The file can go over that size slightly, to allow the current event to finish writing.

  • Some client runs the command FLUSH LOGS. For example, mysqldump does this if you use the --flush-logs command option.

  • The MySQL Server restarts.

huangapple
  • 本文由 发表于 2023年6月12日 16:06:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76454661.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定