Documentation Home
MySQL 8.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 38.5Mb
PDF (A4) - 38.6Mb
PDF (RPM) - 33.3Mb
HTML Download (TGZ) - 8.1Mb
HTML Download (Zip) - 8.2Mb
HTML Download (RPM) - 7.0Mb
Man Pages (TGZ) - 134.2Kb
Man Pages (Zip) - 190.2Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
Excerpts from this Manual

MySQL 8.0 Reference Manual  /  ...  /  C API Binary Log Function Descriptions

27.7.17 C API Binary Log Function Descriptions

The following sections provide detailed descriptions of the functions that enable reading the stream of replication events from a MySQL server binary log.

The following simple example program demonstrates the binary log C API functions. Program notes:

  • mysql is assumed to be a valid connection handler.

  • The initial SET statement sets the @master_binlog_checksum user-defined variable that the server takes as an indication that the client is checksum-aware. This client does nothing with checksums, but without this statement, a server that includes checksums in binary log events will return an error for the first attempt to read an event containing a checksum. The value assigned to the variable is immaterial; what matters is that the variable exist. existence.

if (mysql_query(mysql, "SET @master_binlog_checksum='ALL'"))
{
  fprintf(stderr, "mysql_query() failed\n");
  fprintf(stderr, "Error %u: %s\n",
           mysql_errno(mysql), mysql_error(mysql));
  exit(1);
}

MYSQL_RPL rpl;

rpl.file_name_length = 0;
rpl.file_name = NULL;
rpl.start_position = 4;
rpl.server_id = 0;
rpl.flags = 0;

if (mysql_binlog_open(mysql, &rpl))
{
  fprintf(stderr, "mysql_binlog_open() failed\n");
  fprintf(stderr, "Error %u: %s\n",
           mysql_errno(mysql), mysql_error(mysql));
  exit(1);
}
for (;;)  /* read events until error or EOF */
{
  if (mysql_binlog_fetch(mysql, &rpl))
  {
    fprintf(stderr, "mysql_binlog_fetch() failed\n");
    fprintf(stderr, "Error %u: %s\n",
             mysql_errno(mysql), mysql_error(mysql));
    break;
  }
  if (rpl.size == 0)  /* EOF */
  {
    fprintf(stderr, "EOF event received\n");
    break;
  }
  fprintf(stderr, "Event received of size %lu.\n", rpl.size);
}
mysql_binlog_close(mysql, &rpl);

For additional examples that show how to use these functions, look in a MySQL source distribution for these source files:

  • mysqlbinlog.cc in the client directory

  • mysql_client_test.c in the testclients directory


User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
Sign Up Login You must be logged in to post a comment.