文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 6 个 MySQL 程序 / 6.6 管理和实用程序 / 6.6.9 mysqlbinlog — 处理二进制日志文件的实用程序
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 89%

6.6.9 mysqlbinlog — 用于处理二进制日志文件的工具6.6.9 mysqlbinlog — Utility for Processing Binary Log Files

服务器的二进制日志由包含描述数据库内容修改的“事件”的文件组成。服务器以二进制格式写入这些文件。要以文本格式显示其内容,请使用 mysqlbinlog 工具。您还可以使用 mysqlbinlog 来显示复制设置中副本服务器写入的中继日志文件的内容,因为中继日志与二进制日志具有相同的格式。二进制日志和中继日志将在 第 7.4.4 节,“二进制日志” 和 第 19.2.4 节,“中继日志和复制元数据存储” 中进一步讨论。The server's binary log consists of files containing “events” that describe modifications to database contents. The server writes these files in binary format. To display their contents in text format, use the mysqlbinlog utility. You can also use mysqlbinlog to display the contents of relay log files written by a replica server in a replication setup because relay logs have the same format as binary logs. The binary log and relay log are discussed further in Section 7.4.4, “The Binary Log”, and Section 19.2.4, “Relay Log and Replication Metadata Repositories”.

像这样调用 mysqlbinlog:Invoke mysqlbinlog like this:

mysqlbinlog [options] log_file ...

例如,要显示名为 binlog.000003 的二进制日志文件内容,请使用以下命令:For example, to display the contents of the binary log file named binlog.000003, use this command:

mysqlbinlog binlog.000003

输出包括 binlog.000003 中包含的事件。对于基于语句的日志记录,事件信息包括 SQL 语句、执行语句的服务器 ID、语句执行时间戳、执行所花费的时间等。对于基于行的日志记录,事件表示行的变化而不是 SQL 语句。有关日志模式的信息,请参见 第 19.2.1 节,“复制格式”。The output includes events contained in binlog.000003. For statement-based logging, event information includes the SQL statement, the ID of the server on which it was executed, the timestamp when the statement was executed, how much time it took, and so forth. For row-based logging, the event indicates a row change rather than an SQL statement. See Section 19.2.1, “Replication Formats”, for information about logging modes.

事件前会有标题注释提供附加信息。例如:Events are preceded by header comments that provide additional information. For example:

# at 141
#100309  9:28:36 server id 123  end_log_pos 245
  Query thread_id=3350  exec_time=11  error_code=0

在第一行中,紧随 at 之后的数字表示事件在二进制日志文件中的文件偏移量或起始位置。In the first line, the number following at indicates the file offset, or starting position, of the event in the binary log file.

第二行以日期和时间开头,指示事件在其源服务器上何时开始。对于复制,这个时间戳会传播到副本服务器。server id 是事件源服务器的 server_id 值。end_log_pos 指示下一个事件开始的位置(即当前事件的结束位置 1)。thread_id 表示哪个线程执行了该事件。exec_time 是在复制源服务器上执行事件所花费的时间。在副本上,它是副本的结束执行时间减去源的开始执行时间。这个差值用作复制滞后源的指标。error_code 表示执行事件的结果。零表示没有发生错误。The second line starts with a date and time indicating when the statement started on the server where the event originated. For replication, this timestamp is propagated to replica servers. server id is the server_id value of the server where the event originated. end_log_pos indicates where the next event starts (that is, it is the end position of the current event + 1). thread_id indicates which thread executed the event. exec_time is the time spent executing the event, on a replication source server. On a replica, it is the difference of the end execution time on the replica minus the beginning execution time on the source. The difference serves as an indicator of how much replication lags behind the source. error_code indicates the result from executing the event. Zero means that no error occurred.

Note

在使用事件组时,事件的文件偏移量可能会被分组,事件的注释也可能会被分组。不要将这些分组的事件误认为是空白的文件偏移量。When using event groups, the file offsets of events may be grouped together and the comments of events may be grouped together. Do not mistake these grouped events for blank file offsets.

来自 mysqlbinlog 的输出可以重新执行(例如,通过将其作为 mysql 的输入)来重做日志中的语句。这在服务器意外退出后的恢复操作中非常有用。有关其他使用示例,请参见本节后续讨论以及 第 9.5 节,“时间点(增量)恢复”。要执行 BINLOG 语句(这些语句供 mysqlbinlog 内部使用),用户需要 BINLOG_ADMIN 权限(或已废弃的 SUPER 权限),或者需要 REPLICATION_APPLIER 权限加上执行每个日志事件所需的相应权限。The output from mysqlbinlog can be re-executed (for example, by using it as input to mysql) to redo the statements in the log. This is useful for recovery operations after an unexpected server exit. For other usage examples, see the discussion later in this section and in Section 9.5, “Point-in-Time (Incremental) Recovery”. To execute the internal-use BINLOG statements used by mysqlbinlog, the user requires the BINLOG_ADMIN privilege (or the deprecated SUPER privilege), or the REPLICATION_APPLIER privilege plus the appropriate privileges to execute each log event.

您可以使用 mysqlbinlog 直接读取二进制日志文件并将其应用到本地 MySQL 服务器。您也可以通过使用 --read-from-remote-server 选项从远程服务器读取二进制日志。要读取远程二进制日志,可以提供连接参数选项来指示如何连接服务器。这些选项包括 --host、--password、--port、--protocol、--socket 和 --user。You can use mysqlbinlog to read binary log files directly and apply them to the local MySQL server. You can also read binary logs from a remote server by using the --read-from-remote-server option. To read remote binary logs, the connection parameter options can be given to indicate how to connect to the server. These options are --host, --password, --port, --protocol, --socket, and --user.

当二进制日志文件被加密时,mysqlbinlog 无法直接读取它们,但可以使用 --read-from-remote-server 选项从服务器读取它们。当服务器的 binlog_encryption 系统变量设置为 ON 时,二进制日志文件将被加密。SHOW BINARY LOGS 语句显示特定的二进制日志文件是加密的还是未加密的。通过加密日志文件文件头开始处的魔术数字(0xFD62696E),也可以区分加密和未加密的二进制日志文件,该魔术数字与未加密日志文件使用的魔术数字(0xFE62696E)不同。请注意,如果尝试直接读取加密的二进制日志文件,mysqlbinlog 会返回适当的错误,但较早版本的 mysqlbinlog 根本无法识别该文件为二进制日志文件。有关二进制日志加密的更多信息,请参见 第 19.3.2 节 “加密二进制日志文件和中继日志文件”。When binary log files have been encrypted, mysqlbinlog cannot read them directly, but can read them from the server using the --read-from-remote-server option. Binary log files are encrypted when the server's binlog_encryption system variable is set to ON. The SHOW BINARY LOGS statement shows whether a particular binary log file is encrypted or unencrypted. Encrypted and unencrypted binary log files can also be distinguished using the magic number at the start of the file header for encrypted log files (0xFD62696E), which differs from that used for unencrypted log files (0xFE62696E). Note that mysqlbinlog returns a suitable error if you attempt to read an encrypted binary log file directly, but older versions of mysqlbinlog do not recognise the file as a binary log file at all. For more information on binary log encryption, see Section 19.3.2, “Encrypting Binary Log Files and Relay Log Files”.

当二进制日志事务负载被压缩时,mysqlbinlog 会自动解压缩并解码事务负载,并将其打印出来,就像打印未压缩事件一样。当 binlog_transaction_compression 设置为 ON 时,事务负载会被压缩,然后作为单个事件(一个 Transaction_payload_event)写入服务器的二进制日志文件。使用 --verbose 选项时,mysqlbinlog 会添加注释,说明所使用的压缩算法、原始接收的压缩负载大小,以及解压后得到的负载大小。When binary log transaction payloads have been compressed, mysqlbinlog automatically decompresses and decodes the transaction payloads, and prints them as it would uncompressed events. When binlog_transaction_compression is set to ON, transaction payloads are compressed and then written to the server's binary log file as a single event (a Transaction_payload_event). With the --verbose option, mysqlbinlog adds comments stating the compression algorithm used, the compressed payload size that was originally received, and the resulting payload size after decompression.

Note

对于属于压缩事务负载的单个事件,mysqlbinlog 指定的结束位置(end_log_pos)与原始压缩负载的结束位置相同。因此,多个解压后的事件可能具有相同的结束位置。The end position (end_log_pos) that mysqlbinlog states for an individual event that was part of a compressed transaction payload is the same as the end position of the original compressed payload. Multiple decompressed events can therefore have the same end position.

mysqlbinlog 自身的连接压缩在事务负载已经被压缩的情况下效果较小,但仍然会对未压缩的事务和头部进行操作。mysqlbinlog's own connection compression does less if transaction payloads are already compressed, but still operates on uncompressed transactions and headers.

有关二进制日志事务压缩的更多信息,请参见 第 7.4.4.5 节,“二进制日志事务压缩”。For more information on binary log transaction compression, see Section 7.4.4.5, “Binary Log Transaction Compression”.

在对大型二进制日志运行 mysqlbinlog 时,请注意文件系统是否有足够空间存放生成的文件。要配置 mysqlbinlog 用于临时文件的目录,请使用 TMPDIR 环境变量。When running mysqlbinlog against a large binary log, be careful that the filesystem has enough space for the resulting files. To configure the directory that mysqlbinlog uses for temporary files, use the TMPDIR environment variable.

mysqlbinlog 在执行任何 SQL 语句之前将 pseudo_replica_mode 的值设置为 true。该系统变量影响 XA 事务的处理、original_commit_timestamp 复制延迟时间戳以及 original_server_version 系统变量和不受支持的 SQL 模式。mysqlbinlog sets the value of pseudo_replica_mode to true before executing any SQL statements. This system variable affects the handling of XA transactions, the original_commit_timestamp replication delay timestamp and the original_server_version system variable, and unsupported SQL modes.

mysqlbinlog 支持以下选项,这些选项可以在命令行中指定,也可以在选项文件的 [mysqlbinlog] 和 [client] 组中指定。有关 MySQL 程序使用的选项文件的信息,请参见 第 6.2.2.2 节,“使用选项文件”。mysqlbinlog supports the following options, which can be specified on the command line or in the [mysqlbinlog] and [client] groups of an option file. For information about option files used by MySQL programs, see Section 6.2.2.2, “Using Option Files”.

表 6.20 mysqlbinlog 选项Table 6.20 mysqlbinlog Options

选项名称Option Name 说明Description
--base64 输出--base64-output 使用 Base-64 编码打印二进制日志条目Print binary log entries using base-64 encoding
--绑定地址--bind-address 使用指定的网络接口连接到 MySQL 服务器Use specified network interface to connect to MySQL Server
--binlog 行事件最大大小--binlog-row-event-max-size 二进制日志最大事件大小Binary log max event size
--字符集目录--character-sets-dir 安装字符集的目录Directory where character sets are installed
--压缩--compress 压缩客户端和服务器之间发送的所有信息Compress all information sent between client and server
--压缩算法--compression-algorithms 允许用于连接服务器的压缩算法Permitted compression algorithms for connections to server
--连接服务器 ID--connection-server-id 用于测试和调试。有关适用的默认值和其他详细信息,请参阅文本Used for testing and debugging. See text for applicable default values and other particulars
--数据库--database 仅此数据库的列表项List entries for just this database
--调试--debug 写调试日志Write debugging log
--调试检查--debug-check 程序退出时打印调试信息Print debugging information when program exits
--调试信息--debug-info 在程序退出时打印调试信息、内存和 CPU 统计信息Print debugging information, memory, and CPU statistics when program exits
--默认认证--default-auth 要使用的身份验证插件Authentication plugin to use
--额外默认文件--defaults-extra-file 除了常规选项文件外,读取指定名称的选项文件Read named option file in addition to usual option files
--默认文件--defaults-file 仅读取指定的选项文件Read only named option file
--默认组后缀--defaults-group-suffix 选项组后缀值Option group suffix value
--禁用二进制日志--disable-log-bin 禁用二进制日志Disable binary logging
--排除 GTID--exclude-gtids 不要显示提供的 GTID 集中的任何组Do not show any of the groups in the GTID set provided
--如果打开则强制--force-if-open 即使二进制日志文件未正确打开或关闭,也能读取Read binary log files even if open or not closed properly
--强制读取--force-read 如果 mysqlbinlog 读取一个它不识别的二进制日志事件,它会打印一个警告If mysqlbinlog reads a binary log event that it does not recognize, it prints a warning
--获取服务器公钥--get-server-public-key 从服务器请求 RSA 公钥Request RSA public key from server
--帮助--help 显示帮助信息并退出Display help message and exit
--十六进制转储--hexdump 显示日志的十六进制转储在注释中Display a hex dump of the log in comments
--主机--host MySQL 服务器所在的主机Host on which MySQL server is located
--幂等--idempotent 使服务器在处理来自此会话的二进制日志更新时使用幂等模式Cause the server to use idempotent mode while processing binary log updates from this session only
--include-gtids 仅显示所提供 GTID 集中的组Show only the groups in the GTID set provided
--本地加载--local-load 在指定目录中为 LOAD DATA 准备本地临时文件Prepare local temporary files for LOAD DATA in the specified directory
--登录路径--login-path 从 .mylogin.cnf 读取登录路径选项Read login path options from .mylogin.cnf
--无默认值--no-defaults 不读取任何选项文件Read no option files
--无登录路径--no-login-paths 不要从登录路径文件中读取登录路径Do not read login paths from the login path file
--偏移量--offset 跳过日志中的前 N 条条目Skip the first N entries in the log
--密码--password 连接服务器时使用的密码Password to use when connecting to server
--插件目录--plugin-dir 插件安装的目录Directory where plugins are installed
--端口--port 连接的 TCP/IP 端口号TCP/IP port number for connection
--打印默认值--print-defaults 打印默认选项Print default options
--打印表元数据--print-table-metadata 打印表格元数据Print table metadata
--协议--protocol 要使用的传输协议Transport protocol to use
--原始--raw 将事件以原始(二进制)格式写入输出文件Write events in raw (binary) format to output files
--从远程主机读取--read-from-remote-master 从 MySQL 复制源服务器读取二进制日志,而不是读取本地日志文件Read the binary log from a MySQL replication source server rather than reading a local log file
--从远程服务器读取--read-from-remote-server 从 MySQL 服务器读取二进制日志,而不是本地日志文件Read binary log from MySQL server rather than local log file
--从远程源读取--read-from-remote-source 从 MySQL 复制源服务器读取二进制日志,而不是读取本地日志文件Read the binary log from a MySQL replication source server rather than reading a local log file
--要求行格式--require-row-format 需要基于行的二进制日志格式Require row-based binary logging format
--结果文件--result-file 直接输出到指定文件Direct output to named file
--重写-数据库--rewrite-db 为从基于行格式编写的日志回放时的数据库创建重写规则。可以多次使用Create rewrite rules for databases when playing back from logs written in row-based format. Can be used multiple times
--服务器 ID--server-id 仅提取由具有指定服务器 ID 的服务器创建的事件Extract only those events created by the server having the given server ID
--服务器 ID 位数--server-id-bits 告诉 mysqlbinlog 当日志由其 server-id-bits 设置低于最大值的 mysqld 写入时,如何解释二进制日志中的服务器 ID;仅 mysqlbinlog 的 MySQL Cluster 版本支持Tell mysqlbinlog how to interpret server IDs in binary log when log was written by a mysqld having its server-id-bits set to less than the maximum; supported only by MySQL Cluster version of mysqlbinlog
--服务器公钥路径--server-public-key-path 包含 RSA 公钥的文件路径名称Path name to file containing RSA public key
--设置字符集--set-charset 在输出中添加一个 SET NAMES charset_name 语句Add a SET NAMES charset_name statement to the output
--共享内存基本名称--shared-memory-base-name 共享内存连接的共享内存名称(仅限 Windows)Shared-memory name for shared-memory connections (Windows only)
--简短形式--short-form 仅显示日志中包含的语句Display only the statements contained in the log
--跳过 GTID--skip-gtids 不要在输出转储文件中包含二进制日志文件的 GTIDDo not include the GTIDs from the binary log files in the output dump file
--套接字--socket 要使用的 Unix 套接字文件或 Windows 命名管道Unix socket file or Windows named pipe to use
--ssl-ca 包含受信任的 SSL 证书颁发机构列表的文件File that contains list of trusted SSL Certificate Authorities
--SSL CA 路径--ssl-capath 包含受信任的 SSL 证书颁发机构证书文件的目录Directory that contains trusted SSL Certificate Authority certificate files
--SSL 证书--ssl-cert 包含 X.509 证书的文件File that contains X.509 certificate
--SSL 加密算法--ssl-cipher 连接加密的允许密码Permissible ciphers for connection encryption
--ssl-crl 包含证书吊销列表的文件File that contains certificate revocation lists
--SSL CRL 路径--ssl-crlpath 包含证书吊销列表文件的目录Directory that contains certificate revocation-list files
--ssl-fips-模式--ssl-fips-mode 是否在客户端启用 FIPS 模式Whether to enable FIPS mode on client side
--ssl-密钥--ssl-key 包含 X.509 密钥的文件File that contains X.509 key
--ssl-模式--ssl-mode 与服务器连接的期望安全状态Desired security state of connection to server
--ssl-会话数据--ssl-session-data 包含 SSL 会话数据的文件File that contains SSL session data
--ssl-会话数据-在重用失败时继续--ssl-session-data-continue-on-failed-reuse 如果会话重用失败,是否建立连接Whether to establish connections if session reuse fails
--开始日期时间--start-datetime 从第一个时间戳等于或晚于日期时间参数的事件开始读取二进制日志Read binary log from first event with timestamp equal to or later than datetime argument
--起始位置--start-position 从第一个位置等于或大于参数的事件开始解码二进制日志Decode binary log from first event with position equal to or greater than argument
--停止时间--stop-datetime 在二进制日志中,当事件的时间戳等于或大于 datetime 参数时停止读取Stop reading binary log at first event with timestamp equal to or greater than datetime argument
--永不停止--stop-never 在读取最后一个二进制日志文件后保持与服务器的连接Stay connected to server after reading last binary log file
--永不停止-从服务器 ID--stop-never-slave-server-id 连接到服务器时要报告的从服务器 IDSlave server ID to report when connecting to server
--停止位置--stop-position 在第一个位置等于或大于参数的事件处停止解码二进制日志Stop decoding binary log at first event with position equal to or greater than argument
--tls-密码套件--tls-ciphersuites 允许的用于加密连接的 TLSv1.3 加密套件Permissible TLSv1.3 ciphersuites for encrypted connections
--tls-SNI 服务器名--tls-sni-servername 由客户端提供的服务器名称Server name supplied by the client
--tls-版本--tls-version 允许用于加密连接的 TLS 协议Permissible TLS protocols for encrypted connections
--到最后日志--to-last-log 不要在 MySQL 服务器请求的二进制日志结束时停止,而应继续打印直到最后一个二进制日志的结尾Do not stop at the end of requested binary log from a MySQL server, but rather continue printing to end of last binary log
--用户--user 连接服务器时使用的 MySQL 用户名MySQL user name to use when connecting to server
--详细--verbose 将行事件重新构建为 SQL 语句Reconstruct row events as SQL statements
--验证二进制日志校验和--verify-binlog-checksum 验证二进制日志中的校验和Verify checksums in binary log
--版本--version 显示版本信息并退出Display version information and exit
--zstd-压缩等级--zstd-compression-level 用于与服务器进行 zstd 压缩连接的压缩级别Compression level for connections to server that use zstd compression

  • --help, -? --help, -?

    命令行格式Command-Line Format --help--help

    显示帮助信息并退出。Display a help message and exit.

  • --base64-output=value --base64-output=value

    命令行格式Command-Line Format --base64-output=value--base64-output=value
    类型Type 字符串String
    默认值Default Value AUTOAUTO
    有效值Valid Values

    AUTOAUTO

    NEVERNEVER

    DECODE-ROWSDECODE-ROWS

    此选项决定何时将事件显示为使用 BINLOG 语句的 base-64 编码字符串。该选项具有以下允许值(不区分大小写):This option determines when events should be displayed encoded as base-64 strings using BINLOG statements. The option has these permissible values (not case-sensitive):

    • AUTO(“自动”)或 UNSPEC(“未指定”)在必要时自动显示 BINLOG 语句(即,用于格式描述事件和行事件)。如果未指定 --base64-output 选项,其效果与 --base64-output=AUTO 相同。AUTO ("automatic") or UNSPEC ("unspecified") displays BINLOG statements automatically when necessary (that is, for format description events and row events). If no --base64-output option is given, the effect is the same as --base64-output=AUTO.

      Note

      如果您打算使用 mysqlbinlog 的输出重新执行二进制日志文件内容,那么自动显示 BINLOG 是唯一安全的行为。其他选项值仅用于调试或测试目的,因为它们可能生成不包含所有事件的可执行输出。Automatic BINLOG display is the only safe behavior if you intend to use the output of mysqlbinlog to re-execute binary log file contents. The other option values are intended only for debugging or testing purposes because they may produce output that does not include all events in executable form.

    • NEVER 不会导致 BINLOG 语句不显示。mysqlbinlog 如果发现必须使用 BINLOG 显示的行事件,则会以错误退出。NEVER causes BINLOG statements not to be displayed. mysqlbinlog exits with an error if a row event is found that must be displayed using BINLOG.

    • DECODE-ROWS 指定 mysqlbinlog 将行事件解码并作为带注释的 SQL 语句显示,同时也需要指定 --verbose 选项。类似于 NEVER,DECODE-ROWS 会抑制显示 BINLOG 语句,但与 NEVER 不同的是,如果发现行事件,它不会以错误结束。DECODE-ROWS specifies to mysqlbinlog that you intend for row events to be decoded and displayed as commented SQL statements by also specifying the --verbose option. Like NEVER, DECODE-ROWS suppresses display of BINLOG statements, but unlike NEVER, it does not exit with an error if a row event is found.

    有关显示 --base64-output 和 --verbose 对行事件输出影响的示例,请参见 第 6.6.9.2 节,“mysqlbinlog 行事件显示”。For examples that show the effect of --base64-output and --verbose on row event output, see Section 6.6.9.2, “mysqlbinlog Row Event Display”.

  • --bind-address=ip_address --bind-address=ip_address

    命令行格式Command-Line Format --bind-address=ip_address--bind-address=ip_address

    在具有多个网络接口的计算机上,使用此选项选择用于连接到 MySQL 服务器的接口。On a computer having multiple network interfaces, use this option to select which interface to use for connecting to the MySQL server.

  • --binlog-row-event-max-size=N

    命令行格式Command-Line Format --binlog-row-event-max-size=#
    类型Type 数字Numeric
    默认值Default Value 4294967040
    最小值Minimum Value 256
    最大值Maximum Value 18446744073709547520

    指定基于行的二进制日志事件的最大大小,以字节为单位。如果可能,行会被分组到小于此大小的事件中。该值应为 256 的倍数。默认值为 4GB。Specify the maximum size of a row-based binary log event, in bytes. Rows are grouped into events smaller than this size if possible. The value should be a multiple of 256. The default is 4GB.

  • --character-sets-dir=dir_name --character-sets-dir=dir_name

    命令行格式Command-Line Format --character-sets-dir=dir_name--character-sets-dir=dir_name
    类型Type 目录名称Directory name

    安装字符集的目录。请参见第 12.15 节,“字符集配置”。The directory where character sets are installed. See Section 12.15, “Character Set Configuration”.

  • --compress

    命令行格式Command-Line Format --compress[={OFF|ON}]--compress[={OFF|ON}]
    已弃用Deprecated 是Yes
    类型Type 布尔Boolean
    默认值Default Value OFFOFF

    如果可能,压缩客户端与服务器之间发送的所有信息。参见 第 6.2.8 节,“连接压缩控制”。Compress all information sent between the client and the server if possible. See Section 6.2.8, “Connection Compression Control”.

    此选项已被弃用。预计将在 MySQL 的未来版本中移除。请参阅 配置遗留连接压缩。This option is deprecated. Expect it to be removed in a future version of MySQL. See Configuring Legacy Connection Compression.

  • --compression-algorithms=value --compression-algorithms=value

    命令行格式Command-Line Format --compression-algorithms=value--compression-algorithms=value
    类型Type 设置Set
    默认值Default Value uncompresseduncompressed
    有效值Valid Values

    zlib

    zstd

    uncompresseduncompressed

    允许用于与服务器连接的压缩算法。可用算法与 protocol_compression_algorithms 系统变量的算法相同。默认值为 uncompressed。The permitted compression algorithms for connections to the server. The available algorithms are the same as for the protocol_compression_algorithms system variable. The default value is uncompressed.

    更多信息,请参阅 第 6.2.8 节,“连接压缩控制”。For more information, see Section 6.2.8, “Connection Compression Control”.

  • --connection-server-id=server_id

    命令行格式Command-Line Format --connection-server-id=#]
    类型Type 整数Integer
    默认值Default Value 0 (1)
    最小值Minimum Value 0 (1)
    最大值Maximum Value 4294967295

    --connection-server-id 指定 mysqlbinlog 连接到服务器时报告的服务器 ID。它可以用来避免与复制服务器或另一个 mysqlbinlog 进程的 ID 冲突。--connection-server-id specifies the server ID that mysqlbinlog reports when it connects to the server. It can be used to avoid a conflict with the ID of a replica server or another mysqlbinlog process.

    如果指定了--read-from-remote-server 选项,mysqlbinlog 将报告服务器 ID 为 0,这会告诉服务器在发送最后一个日志文件后断开连接(非阻塞行为)。如果同时指定了--stop-never 选项以保持与服务器的连接,mysqlbinlog 默认报告服务器 ID 为 1 而不是 0,并且可以使用--connection-server-id 来替换该服务器 ID(如有需要)。请参阅 第 6.6.9.4 节,“指定 mysqlbinlog 服务器 ID”。If the --read-from-remote-server option is specified, mysqlbinlog reports a server ID of 0, which tells the server to disconnect after sending the last log file (nonblocking behavior). If the --stop-never option is also specified to maintain the connection to the server, mysqlbinlog reports a server ID of 1 by default instead of 0, and --connection-server-id can be used to replace that server ID if required. See Section 6.6.9.4, “Specifying the mysqlbinlog Server ID”.

  • --database=db_name, -d db_name

    命令行格式Command-Line Format --database=db_name
    类型Type 字符串String

    此选项使 mysqlbinlog 输出从二进制日志(仅本地日志)中发生的条目,这些条目是在通过 USE 选择 db_name 作为默认数据库时发生的。This option causes mysqlbinlog to output entries from the binary log (local log only) that occur while db_name is been selected as the default database by USE.

    --database 选项用于 mysqlbinlog,类似于 --binlog-do-db 选项用于 mysqld,但只能用于指定一个数据库。如果多次使用 --database,则只使用最后一次。The --database option for mysqlbinlog is similar to the --binlog-do-db option for mysqld, but can be used to specify only one database. If --database is given multiple times, only the last instance is used.

    此选项的效果取决于使用的是基于语句还是基于行的日志格式,就像--binlog-do-db的效果取决于使用的是基于语句还是基于行的日志格式一样。The effects of this option depend on whether the statement-based or row-based logging format is in use, in the same way that the effects of --binlog-do-db depend on whether statement-based or row-based logging is in use.

    基于语句的日志记录。 --database选项的工作方式如下:Statement-based logging.  The --database option works as follows:

    • 当db_name为默认数据库时,无论语句修改的是db_name还是其他数据库中的表,语句都会被输出。While db_name is the default database, statements are output whether they modify tables in db_name or a different database.

    • 除非db_name被选为默认数据库,否则语句不会被输出,即使它们修改的是db_name中的表。Unless db_name is selected as the default database, statements are not output, even if they modify tables in db_name.

    • 对于CREATE DATABASE、ALTER DATABASE和DROP DATABASE有一个例外。在确定是否输出语句时,被创建、修改或删除的数据库被视为默认数据库。There is an exception for CREATE DATABASE, ALTER DATABASE, and DROP DATABASE. The database being created, altered, or dropped is considered to be the default database when determining whether to output the statement.

    假设二进制日志是通过使用基于语句的日志记录执行这些语句创建的:Suppose that the binary log was created by executing these statements using statement-based-logging:

    INSERT INTO test.t1 (i) VALUES(100);
    INSERT INTO db2.t2 (j)  VALUES(200);
    USE test;
    INSERT INTO test.t1 (i) VALUES(101);
    INSERT INTO t1 (i)      VALUES(102);
    INSERT INTO db2.t2 (j)  VALUES(201);
    USE db2;
    INSERT INTO test.t1 (i) VALUES(103);
    INSERT INTO db2.t2 (j)  VALUES(202);
    INSERT INTO t2 (j)      VALUES(203);
    

    mysqlbinlog --database=test 不会输出前两个 INSERT 语句,因为没有默认数据库。它会输出紧跟在 INSERT 后面的三个 INSERT 语句,但不会输出紧跟在 USE db2 后面的三个 USE test 语句。mysqlbinlog --database=test does not output the first two INSERT statements because there is no default database. It outputs the three INSERT statements following USE test, but not the three INSERT statements following USE db2.

    mysqlbinlog --database=db2 不会输出前两个 INSERT 语句,因为没有默认数据库。它不会输出 USE test 之后的三个 INSERT 语句,但会输出 USE db2 之后的三个 INSERT 语句。mysqlbinlog --database=db2 does not output the first two INSERT statements because there is no default database. It does not output the three INSERT statements following USE test, but does output the three INSERT statements following USE db2.

    基于行的日志记录。 mysqlbinlog 只输出更改属于 db_name 表的条目。默认数据库对此没有影响。假设刚描述的二进制日志是使用基于行的日志记录而不是基于语句的日志记录创建的。mysqlbinlog --database=test 仅输出修改测试数据库中 t1 的条目,而不考虑是否已执行 USE 或默认数据库是什么。Row-based logging.  mysqlbinlog outputs only entries that change tables belonging to db_name. The default database has no effect on this. Suppose that the binary log just described was created using row-based logging rather than statement-based logging. mysqlbinlog --database=test outputs only those entries that modify t1 in the test database, regardless of whether USE was issued or what the default database is.

    如果服务器的 binlog_format 设置为 MIXED,并且您希望能够使用带有 --database 选项的 mysqlbinlog,则必须确保被修改的表位于 USE 选择的数据库中。(特别是,不应使用跨数据库更新。)If a server is running with binlog_format set to MIXED and you want it to be possible to use mysqlbinlog with the --database option, you must ensure that tables that are modified are in the database selected by USE. (In particular, no cross-database updates should be used.)

    当与--rewrite-db选项一起使用时,会先应用--rewrite-db选项;然后应用--database选项,使用重写后的数据库名称。在这方面,选项提供的顺序没有区别。When used together with the --rewrite-db option, the --rewrite-db option is applied first; then the --database option is applied, using the rewritten database name. The order in which the options are provided makes no difference in this regard.

  • --debug[=debug_options], -# [debug_options]

    命令行格式Command-Line Format --debug[=debug_options]--debug[=debug_options]
    类型Type 字符串String
    默认值Default Value d:t:o,/tmp/mysqlbinlog.trace

    编写调试日志。典型的 debug_options 字符串是 d:t:o,file_name。默认值是 d:t:o,/tmp/mysqlbinlog.trace。Write a debugging log. A typical debug_options string is d:t:o,file_name. The default is d:t:o,/tmp/mysqlbinlog.trace.

    此选项仅在 MySQL 使用 WITH_DEBUG 构建时可用。Oracle 提供的 MySQL 发行版二进制文件 未 使用此选项构建。This option is available only if MySQL was built using WITH_DEBUG. MySQL release binaries provided by Oracle are not built using this option.

  • --debug-check

    命令行格式Command-Line Format --debug-check
    类型Type 布尔Boolean
    默认值Default Value FALSE

    程序退出时打印一些调试信息。Print some debugging information when the program exits.

    此选项仅在 MySQL 使用 WITH_DEBUG 构建时可用。Oracle 提供的 MySQL 发行版二进制文件 未 使用此选项构建。This option is available only if MySQL was built using WITH_DEBUG. MySQL release binaries provided by Oracle are not built using this option.

  • --debug-info

    命令行格式Command-Line Format --debug-info
    类型Type 布尔Boolean
    默认值Default Value FALSE

    在程序退出时打印调试信息以及内存和 CPU 使用情况统计。Print debugging information and memory and CPU usage statistics when the program exits.

    此选项仅在 MySQL 使用 WITH_DEBUG 构建时可用。Oracle 提供的 MySQL 发行版二进制文件 未 使用此选项构建。This option is available only if MySQL was built using WITH_DEBUG. MySQL release binaries provided by Oracle are not built using this option.

  • --default-auth=plugin --default-auth=plugin

    命令行格式Command-Line Format --default-auth=plugin--default-auth=plugin
    类型Type 字符串String

    关于使用哪种客户端身份验证插件的提示。请参见 第 8.2.17 节,“可插拔身份验证”。A hint about which client-side authentication plugin to use. See Section 8.2.17, “Pluggable Authentication”.

  • --defaults-extra-file=file_name --defaults-extra-file=file_name

    命令行格式Command-Line Format --defaults-extra-file=file_name--defaults-extra-file=file_name
    类型Type 文件名File name

    在全局选项文件之后读取此选项文件,但(在 Unix 系统上)在用户选项文件之前。如果该文件不存在或无法访问,将发生错误。如果 file_name 不是绝对路径名,则相对于当前目录解释。Read this option file after the global option file but (on Unix) before the user option file. If the file does not exist or is otherwise inaccessible, an error occurs. If file_name is not an absolute path name, it is interpreted relative to the current directory.

    有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.

  • --defaults-file=file_name --defaults-file=file_name

    命令行格式Command-Line Format --defaults-file=file_name--defaults-file=file_name
    类型Type 文件名File name

    仅使用指定的选项文件。如果文件不存在或无法访问,将会发生错误。如果file_name不是绝对路径名,则将其相对于当前目录解释。Use only the given option file. If the file does not exist or is otherwise inaccessible, an error occurs. If file_name is not an absolute path name, it is interpreted relative to the current directory.

    例外:即使使用--defaults-file,客户端程序仍会读取.mylogin.cnf。Exception: Even with --defaults-file, client programs read .mylogin.cnf.

    有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.

  • --defaults-group-suffix=str --defaults-group-suffix=str

    命令行格式Command-Line Format --defaults-group-suffix=str--defaults-group-suffix=str
    类型Type 字符串String

    不仅要读取常规的选项组,还要读取带有常规名称并以str为后缀的组。例如,mysqlbinlog 通常读取 [client] 和 [mysqlbinlog] 组。如果将此选项设置为 --defaults-group-suffix=_other,mysqlbinlog 还会读取 [client_other] 和 [mysqlbinlog_other] 组。Read not only the usual option groups, but also groups with the usual names and a suffix of str. For example, mysqlbinlog normally reads the [client] and [mysqlbinlog] groups. If this option is given as --defaults-group-suffix=_other, mysqlbinlog also reads the [client_other] and [mysqlbinlog_other] groups.

    有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.

  • --disable-log-bin, -D

    命令行格式Command-Line Format --disable-log-bin

    禁用二进制日志。这在使用 --to-last-log 选项并将输出发送到同一个 MySQL 服务器时非常有用,可以避免无限循环。此选项在意外退出后进行恢复时也很有用,以避免重复已记录的语句。Disable binary logging. This is useful for avoiding an endless loop if you use the --to-last-log option and are sending the output to the same MySQL server. This option also is useful when restoring after an unexpected exit to avoid duplication of the statements you have logged.

    此选项会导致 mysqlbinlog 在其输出中包含一条 SET sql_log_bin = 0 语句,以禁用剩余输出的二进制日志记录。操作 sql_log_bin 系统变量的会话值属于受限操作,因此此选项要求您拥有设置受限会话变量的足够权限。参见 第 7.1.9.1 节,“系统变量权限”。This option causes mysqlbinlog to include a SET sql_log_bin = 0 statement in its output to disable binary logging of the remaining output. Manipulating the session value of the sql_log_bin system variable is a restricted operation, so this option requires that you have privileges sufficient to set restricted session variables. See Section 7.1.9.1, “System Variable Privileges”.

  • --exclude-gtids=gtid_set

    命令行格式Command-Line Format --exclude-gtids=gtid_set
    类型Type 字符串String
    默认值Default Value

    不要显示gtid_set中列出的任何组。Do not display any of the groups listed in the gtid_set.

  • --force-if-open, -F

    命令行格式Command-Line Format --force-if-open

    即使二进制日志文件正在使用中或未正确关闭(IN_USE 标志已设置),也要读取它们;如果文件以截断事件结尾,不要出错。Read binary log files even if they are open or were not closed properly (IN_USE flag is set); do not fail if the file ends with a truncated event.

    IN_USE 标记仅针对当前由服务器写入的二进制日志设置;如果服务器崩溃,该标记会保持设置状态,直到服务器重新启动并恢复二进制日志。没有此选项时,mysqlbinlog 会拒绝处理具有此标记的文件。由于服务器可能正在写入文件,最后一个事件的截断被认为是正常情况。The IN_USE flag is set only for the binary log that is currently written by the server; if the server has crashed, the flag remains set until the server is started up again and recovers the binary log. Without this option, mysqlbinlog refuses to process a file with this flag set. Since the server may be in the process of writing the file, truncation of the last event is considered normal.

  • --force-read, -f

    命令行格式Command-Line Format --force-read

    使用此选项时,如果 mysqlbinlog 读取了一个它无法识别的二进制日志事件,它会打印警告、忽略该事件并继续。没有此选项时,如果 mysqlbinlog 读取到这样的事件,它将停止。With this option, if mysqlbinlog reads a binary log event that it does not recognize, it prints a warning, ignores the event, and continues. Without this option, mysqlbinlog stops if it reads such an event.

  • --get-server-public-key

    命令行格式Command-Line Format --get-server-public-key--get-server-public-key
    类型Type 布尔Boolean

    向服务器请求用于基于 RSA 密钥对的密码交换所需的公钥。此选项适用于使用 caching_sha2_password 身份验证插件进行身份验证的客户端。对于该插件,服务器不会发送公钥,除非被请求。对于未使用该插件进行身份验证的账户,此选项将被忽略。当未使用基于 RSA 的密码交换时(例如客户端使用安全连接连接服务器时),此选项也将被忽略。Request from the server the public key required for RSA key pair-based password exchange. This option applies to clients that authenticate with the caching_sha2_password authentication plugin. For that plugin, the server does not send the public key unless requested. This option is ignored for accounts that do not authenticate with that plugin. It is also ignored if RSA-based password exchange is not used, as is the case when the client connects to the server using a secure connection.

    如果提供了 --server-public-key-path=file_name 并指定了一个有效的公钥文件,则它优先于 --get-server-public-key。If --server-public-key-path=file_name is given and specifies a valid public key file, it takes precedence over --get-server-public-key.

    有关 caching_sha2_password 插件的信息,请参见 第 8.4.1.2 节,“缓存 SHA-2 可插拔认证”。For information about the caching_sha2_password plugin, see Section 8.4.1.2, “Caching SHA-2 Pluggable Authentication”.

  • --hexdump, -H

    命令行格式Command-Line Format --hexdump

    以注释形式显示日志的十六进制转储,如 第 6.6.9.1 节,“mysqlbinlog 十六进制转储格式” 中所述。十六进制输出对于复制调试非常有用。Display a hex dump of the log in comments, as described in Section 6.6.9.1, “mysqlbinlog Hex Dump Format”. The hex output can be helpful for replication debugging.

  • --host=host_name, -h host_name --host=host_name, -h host_name

    命令行格式Command-Line Format --host=host_name--host=host_name
    类型Type 字符串String
    默认值Default Value localhostlocalhost

    从指定主机上的 MySQL 服务器获取二进制日志。Get the binary log from the MySQL server on the given host.

  • --idempotent --idempotent

    命令行格式Command-Line Format --idempotent--idempotent
    类型Type 布尔Boolean
    默认值Default Value truetrue

    告诉 MySQL 服务器在处理更新时使用幂等模式;这会抑制服务器在当前会话中处理更新时遇到的任何重复键或找不到键的错误。每当希望或需要将一个或多个二进制日志重播放到可能不包含日志所引用的所有数据的 MySQL 服务器时,这个选项可能会非常有用。Tell the MySQL Server to use idempotent mode while processing updates; this causes suppression of any duplicate-key or key-not-found errors that the server encounters in the current session while processing updates. This option may prove useful whenever it is desirable or necessary to replay one or more binary logs to a MySQL Server which may not contain all of the data to which the logs refer.

    此选项的影响范围仅包括当前的 mysqlbinlog 客户端和会话。The scope of effect for this option includes the current mysqlbinlog client and session only.

  • --include-gtids=gtid_set

    命令行格式Command-Line Format --include-gtids=gtid_set
    类型Type 字符串String
    默认值Default Value

    仅显示 gtid_set 中列出的组。Display only the groups listed in the gtid_set.

  • --local-load=dir_name, -l dir_name

    命令行格式Command-Line Format --local-load=dir_name
    类型Type 目录名称Directory name

    对于与 LOAD DATA 语句对应的数据加载操作,mysqlbinlog 会从二进制日志事件中提取文件,将它们作为临时文件写入本地文件系统,并写入 LOAD DATA LOCAL 语句以加载这些文件。默认情况下,mysqlbinlog 会将这些临时文件写入操作系统特定的目录。可以使用 --local-load 选项明确指定 mysqlbinlog 应准备本地临时文件的目录。For data loading operations corresponding to LOAD DATA statements, mysqlbinlog extracts the files from the binary log events, writes them as temporary files to the local file system, and writes LOAD DATA LOCAL statements to cause the files to be loaded. By default, mysqlbinlog writes these temporary files to an operating system-specific directory. The --local-load option can be used to explicitly specify the directory where mysqlbinlog should prepare local temporary files.

    由于其他进程可以向默认的系统特定目录写入文件,建议指定--local-load选项mysqlbinlog为数据文件指定不同的目录,然后在处理来自--load-data-local-dir选项mysql的输出时,通过指定mysqlbinlog来指定相同的目录。例如:Because other processes can write files to the default system-specific directory, it is advisable to specify the --local-load option to mysqlbinlog to designate a different directory for data files, and then designate that same directory by specifying the --load-data-local-dir option to mysql when processing the output from mysqlbinlog. For example:

    mysqlbinlog --local-load=/my/local/data ...
        | mysql --load-data-local-dir=/my/local/data ...
    
    Important

    这些临时文件不会被 mysqlbinlog 或任何其他 MySQL 程序自动删除。These temporary files are not automatically removed by mysqlbinlog or any other MySQL program.

  • --login-path=name

    命令行格式Command-Line Format --login-path=name--login-path=name
    类型Type 字符串String

    从名为登录路径的 .mylogin.cnf 登录路径文件中读取选项。“登录路径” 是一个选项组,包含指定要连接哪个 MySQL 服务器以及以哪个帐户进行身份验证的选项。要创建或修改登录路径文件,请使用 mysql_config_editor 工具。参见 第 6.6.7 节,“mysql_config_editor — MySQL 配置工具”。Read options from the named login path in the .mylogin.cnf login path file. A “login path” is an option group containing options that specify which MySQL server to connect to and which account to authenticate as. To create or modify a login path file, use the mysql_config_editor utility. See Section 6.6.7, “mysql_config_editor — MySQL Configuration Utility”.

    有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.

  • --no-login-paths --no-login-paths

    命令行格式Command-Line Format --no-login-paths

    跳过从登录路径文件读取选项。Skips reading options from the login path file.

    有关相关信息,请参见 --login-path。See --login-path for related information.

    有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.

  • --no-defaults --no-defaults

    命令行格式Command-Line Format --no-defaults--no-defaults

    不要读取任何选项文件。如果程序启动因从选项文件读取未知选项而失败,可以使用 --no-defaults 来防止读取这些选项。Do not read any option files. If program startup fails due to reading unknown options from an option file, --no-defaults can be used to prevent them from being read.

    例外情况是,如果存在,.mylogin.cnf 文件在所有情况下都会被读取。这允许以比在命令行上更安全的方式指定密码,即使使用了 --no-defaults。要创建 .mylogin.cnf,请使用 mysql_config_editor 工具。请参见 第 6.6.7 节,“mysql_config_editor — MySQL 配置工具”。The exception is that the .mylogin.cnf file is read in all cases, if it exists. This permits passwords to be specified in a safer way than on the command line even when --no-defaults is used. To create .mylogin.cnf, use the mysql_config_editor utility. See Section 6.6.7, “mysql_config_editor — MySQL Configuration Utility”.

    有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.

  • --offset=N, -o N

    命令行格式Command-Line Format --offset=#
    类型Type 数字Numeric

    跳过日志中的前 N 条记录。Skip the first N entries in the log.

  • --open-files-limit=N

    命令行格式Command-Line Format --open-files-limit=#
    类型Type 数字Numeric
    默认值Default Value 8
    最小值Minimum Value 1
    最大值Maximum Value [platform dependent][platform dependent]

    指定要保留的打开文件描述符数量。Specify the number of open file descriptors to reserve.

  • --password[=password], -p[password] --password[=password], -p[password]

    命令行格式Command-Line Format --password[=password]--password[=password]
    类型Type 字符串String

    用于连接服务器的 MySQL 账户密码。密码值是可选的。如果未提供,mysqlbinlog 会提示输入。如果提供,--password= 或 -p 与后面的密码之间 不能有空格。如果未指定密码选项,默认情况下不发送密码。The password of the MySQL account used for connecting to the server. The password value is optional. If not given, mysqlbinlog prompts for one. If given, there must be no space between --password= or -p and the password following it. If no password option is specified, the default is to send no password.

    在命令行中指定密码应被视为不安全。为了避免在命令行中输入密码,请使用选项文件。请参阅 第 8.1.2.1 节,“终端用户密码安全指南”。Specifying a password on the command line should be considered insecure. To avoid giving the password on the command line, use an option file. See Section 8.1.2.1, “End-User Guidelines for Password Security”.

    要明确指定没有密码,并且 mysqlbinlog 不应提示输入密码,请使用 --skip-password 选项。To explicitly specify that there is no password and that mysqlbinlog should not prompt for one, use the --skip-password option.

  • --plugin-dir=dir_name --plugin-dir=dir_name

    命令行格式Command-Line Format --plugin-dir=dir_name--plugin-dir=dir_name
    类型Type 目录名称Directory name

    查找插件的目录。如果使用 --default-auth 选项来指定身份验证插件,但 mysqlbinlog 未找到它,请指定此选项。参见 第 8.2.17 节,“可插拔身份验证”。The directory in which to look for plugins. Specify this option if the --default-auth option is used to specify an authentication plugin but mysqlbinlog does not find it. See Section 8.2.17, “Pluggable Authentication”.

  • --port=port_num, -P port_num

    命令行格式Command-Line Format --port=port_num--port=port_num
    类型Type 数字Numeric
    默认值Default Value 3306

    用于连接远程服务器的 TCP/IP 端口号。The TCP/IP port number to use for connecting to a remote server.

  • --print-defaults

    命令行格式Command-Line Format --print-defaults

    打印程序名称以及它从选项文件中获取的所有选项。Print the program name and all options that it gets from option files.

    有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.

  • --print-table-metadata

    命令行格式Command-Line Format --print-table-metadata

    从二进制日志中打印表相关元数据。使用 binlog-row-metadata 配置二进制日志中记录的表相关元数据量。Print table related metadata from the binary log. Configure the amount of table related metadata binary logged using binlog-row-metadata.

  • --protocol={TCP|SOCKET|PIPE|MEMORY}

    命令行格式Command-Line Format --protocol=type--protocol=type
    类型Type 字符串String
    默认值Default Value [see text][see text]
    有效值Valid Values

    TCP

    SOCKETSOCKET

    PIPEPIPE

    MEMORYMEMORY

    用于连接服务器的传输协议。当其他连接参数通常导致使用的协议不是您想要的协议时,这很有用。有关允许值的详细信息,请参阅第 6.2.7 节,“连接传输协议”。The transport protocol to use for connecting to the server. It is useful when the other connection parameters normally result in use of a protocol other than the one you want. For details on the permissible values, see Section 6.2.7, “Connection Transport Protocols”.

  • --raw

    命令行格式Command-Line Format --raw
    类型Type 布尔Boolean
    默认值Default Value FALSE

    默认情况下,mysqlbinlog 读取二进制日志文件并以文本格式写入事件。--raw 选项告诉 mysqlbinlog 将其写入原始二进制格式。其使用要求同时使用 --read-from-remote-server,因为文件是从服务器请求的。mysqlbinlog 为从服务器读取的每个文件写入一个输出文件。--raw 选项可以用来备份服务器的二进制日志。使用 --stop-never 选项时,备份是 “实时” 的,因为 mysqlbinlog 保持与服务器的连接。默认情况下,输出文件写入当前目录,并使用与原始日志文件相同的名称。可以使用 --result-file 选项修改输出文件的名称。更多信息,请参见 第 6.6.9.3 节,“使用 mysqlbinlog 备份二进制日志文件”。By default, mysqlbinlog reads binary log files and writes events in text format. The --raw option tells mysqlbinlog to write them in their original binary format. Its use requires that --read-from-remote-server also be used because the files are requested from a server. mysqlbinlog writes one output file for each file read from the server. The --raw option can be used to make a backup of a server's binary log. With the --stop-never option, the backup is “live” because mysqlbinlog stays connected to the server. By default, output files are written in the current directory with the same names as the original log files. Output file names can be modified using the --result-file option. For more information, see Section 6.6.9.3, “Using mysqlbinlog to Back Up Binary Log Files”.

  • --read-from-remote-source=type --read-from-remote-source=type

    命令行格式Command-Line Format --read-from-remote-source=type--read-from-remote-source=type

    此选项通过设置选项值为 BINLOG-DUMP-NON-GTIDS 或 BINLOG-DUMP-GTIDS,分别使用 COM_BINLOG_DUMP 或 COM_BINLOG_DUMP_GTID 命令从 MySQL 服务器读取二进制日志。如果将 --read-from-remote-source=BINLOG-DUMP-GTIDS 与 --exclude-gtids 结合使用,可以在源端筛选事务,避免不必要的网络流量。This option reads binary logs from a MySQL server with the COM_BINLOG_DUMP or COM_BINLOG_DUMP_GTID commands by setting the option value to either BINLOG-DUMP-NON-GTIDS or BINLOG-DUMP-GTIDS, respectively. If --read-from-remote-source=BINLOG-DUMP-GTIDS is combined with --exclude-gtids, transactions can be filtered out on the source, avoiding unnecessary network traffic.

    连接参数选项与这些选项或 --read-from-remote-server 选项一起使用。这些选项包括 --host、--password、--port、--protocol、--socket 和 --user。如果未指定任何远程选项,则忽略连接参数选项。The connection parameter options are used with these options or the --read-from-remote-server option. These options are --host, --password, --port, --protocol, --socket, and --user. If none of the remote options is specified, the connection parameter options are ignored.

    使用这些选项需要REPLICATION SLAVE权限。The REPLICATION SLAVE privilege is required to use these options.

  • --read-from-remote-master=type --read-from-remote-master=type

    命令行格式Command-Line Format --read-from-remote-master=type--read-from-remote-master=type
    已弃用Deprecated 是Yes

    是--read-from-remote-source的弃用同义词。Deprecated synonym for --read-from-remote-source.

  • --read-from-remote-server=file_name, -R --read-from-remote-server=file_name, -R

    命令行格式Command-Line Format --read-from-remote-server=file_name--read-from-remote-server=file_name

    从 MySQL 服务器读取二进制日志,而不是读取本地日志文件。此选项要求远程服务器正在运行。它仅适用于远程服务器上的二进制日志文件,而不适用于中继日志文件。此选项接受二进制日志文件名(包括数字后缀),不包括文件路径。Read the binary log from a MySQL server rather than reading a local log file. This option requires that the remote server be running. It works only for binary log files on the remote server and not relay log files. This accepts the binary log file name (including the numeric suffix) without the file path.

    连接参数选项用于此选项或 --read-from-remote-source 选项。这些选项包括 --host、--password、--port、--protocol、--socket 和 --user。如果未指定任何远程选项,则连接参数选项将被忽略。The connection parameter options are used with this option or the --read-from-remote-source option. These options are --host, --password, --port, --protocol, --socket, and --user. If neither of the remote options is specified, the connection parameter options are ignored.

    使用此选项需要 REPLICATION SLAVE 权限。The REPLICATION SLAVE privilege is required to use this option.

    此选项类似于 --read-from-remote-source=BINLOG-DUMP-NON-GTIDS。This option is like --read-from-remote-source=BINLOG-DUMP-NON-GTIDS.

  • --result-file=name, -r name --result-file=name, -r name

    命令行格式Command-Line Format --result-file=name--result-file=name

    如果不使用 --raw 选项,这个选项表示 mysqlbinlog 写入文本输出的文件。使用 --raw 时,mysqlbinlog 为从服务器传输的每个日志文件写入一个二进制输出文件,默认情况下将它们写入当前目录,并使用与原始日志文件相同的名称。在这种情况下,--result-file 选项的值被视为修改输出文件名的前缀。Without the --raw option, this option indicates the file to which mysqlbinlog writes text output. With --raw, mysqlbinlog writes one binary output file for each log file transferred from the server, writing them by default in the current directory using the same names as the original log file. In this case, the --result-file option value is treated as a prefix that modifies output file names.

  • --require-row-format

    命令行格式Command-Line Format --require-row-format
    类型Type 布尔Boolean
    默认值Default Value falsefalse

    要求事件采用基于行的二进制日志格式。此选项会强制 mysqlbinlog 输出的复制事件为基于行的。使用此选项生成的事件流将被使用 CHANGE REPLICATION SOURCE TO 语句的 REQUIRE_ROW_FORMAT 选项保护的复制通道接受。用于写入二进制日志的服务器上必须设置 binlog_format=ROW。当您指定此选项时,如果 mysqlbinlog 遇到在 REQUIRE_ROW_FORMAT 限制下不允许的任何事件时,它会停止并显示错误消息,包括 LOAD DATA INFILE 指令、创建或删除临时表、INTVAR、RAND 或 USER_VAR 事件,以及 DML 事务中的非基于行事件。mysqlbinlog 还会在其输出开始时打印 SET @@session.require_row_format 语句,以在执行输出时应用这些限制,并且不会打印 SET @@session.pseudo_thread_id 语句。Require row-based binary logging format for events. This option enforces row-based replication events for mysqlbinlog output. The stream of events produced with this option would be accepted by a replication channel that is secured using the REQUIRE_ROW_FORMAT option of the CHANGE REPLICATION SOURCE TO statement. binlog_format=ROW must be set on the server where the binary log was written. When you specify this option, mysqlbinlog stops with an error message if it encounters any events that are disallowed under the REQUIRE_ROW_FORMAT restrictions, including LOAD DATA INFILE instructions, creating or dropping temporary tables, INTVAR, RAND, or USER_VAR events, and non-row-based events within a DML transaction. mysqlbinlog also prints a SET @@session.require_row_format statement at the start of its output to apply the restrictions when the output is executed, and does not print the SET @@session.pseudo_thread_id statement.

  • --rewrite-db='from_name->to_name'

    命令行格式Command-Line Format --rewrite-db='oldname->newname'
    类型Type 字符串String
    默认值Default Value [none][none]

    当从基于行或基于语句的日志读取时,将所有出现的 from_name 重写为 to_name。对于基于行的日志,重写发生在行上;对于基于语句的日志,重写发生在 USE 子句上。When reading from a row-based or statement-based log, rewrite all occurrences of from_name to to_name. Rewriting is done on the rows, for row-based logs, as well as on the USE clauses, for statement-based logs.

    Warning

    在使用此选项时,用数据库名称限定表名的语句不会被重写为使用新名称。Statements in which table names are qualified with database names are not rewritten to use the new name when using this option.

    作为此选项值使用的重写规则是一个形式为'from_name->to_name'的字符串,如前所示,因此必须用引号括起来。The rewrite rule employed as a value for this option is a string having the form 'from_name->to_name', as shown previously, and for this reason must be enclosed by quotation marks.

    要使用多个重写规则,请多次指定该选项,如下所示:To employ multiple rewrite rules, specify the option multiple times, as shown here:

    mysqlbinlog --rewrite-db='dbcurrent->dbold' --rewrite-db='dbtest->dbcurrent' \
        binlog.00001 > /tmp/statements.sql
    

    当与 --database 选项一起使用时,--rewrite-db 选项先应用;然后应用 --database 选项,使用重写后的数据库名称。在这方面,选项提供的顺序没有差别。When used together with the --database option, the --rewrite-db option is applied first; then --database option is applied, using the rewritten database name. The order in which the options are provided makes no difference in this regard.

    这意味着,例如,如果 mysqlbinlog 使用 --rewrite-db='mydb->yourdb' --database=yourdb 启动,那么数据库 mydb 和 yourdb 中的所有表的更新都会被包含在输出中。另一方面,如果它使用 --rewrite-db='mydb->yourdb' --database=mydb 启动,那么 mysqlbinlog 将不输出任何语句:因为在应用 --database 选项之前,所有对 mydb 的更新首先被重写为对 yourdb 的更新,因此不再有任何更新与 --database=mydb 相匹配。This means that, for example, if mysqlbinlog is started with --rewrite-db='mydb->yourdb' --database=yourdb, then all updates to any tables in databases mydb and yourdb are included in the output. On the other hand, if it is started with --rewrite-db='mydb->yourdb' --database=mydb, then mysqlbinlog outputs no statements at all: since all updates to mydb are first rewritten as updates to yourdb before applying the --database option, there remain no updates that match --database=mydb.

  • --server-id=id

    命令行格式Command-Line Format --server-id=id
    类型Type 数字Numeric

    仅显示由具有给定服务器 ID 的服务器创建的事件。Display only those events created by the server having the given server ID.

  • --server-id-bits=N

    命令行格式Command-Line Format --server-id-bits=#
    类型Type 数字Numeric
    默认值Default Value 32
    最小值Minimum Value 7
    最大值Maximum Value 32

    仅使用 N 位的 server_id 来识别服务器。如果二进制日志是由设置了少于 32 个 server-id-bit 并且用户数据存储在最高有效位的 mysqld 写入的,使用 mysqlbinlog 并将 --server-id-bits 设置为 32 就可以看到这些数据。Use only the first N bits of the server_id to identify the server. If the binary log was written by a mysqld with server-id-bits set to less than 32 and user data stored in the most significant bit, running mysqlbinlog with --server-id-bits set to 32 enables this data to be seen.

    此选项仅受随 NDB Cluster 发行版提供的 mysqlbinlog 版本支持,或支持 NDB Cluster 构建的版本。This option is supported only by the version of mysqlbinlog supplied with the NDB Cluster distribution, or built with NDB Cluster support.

  • --server-public-key-path=file_name --server-public-key-path=file_name

    命令行格式Command-Line Format --server-public-key-path=file_name--server-public-key-path=file_name
    类型Type 文件名File name

    包含服务器所需的 RSA 密钥对密码交换的客户端副本公钥的 PEM 格式文件的路径名。此选项适用于使用 sha256_password(已弃用)或 caching_sha2_password 身份验证插件进行身份验证的客户端。对于不使用这些插件之一进行身份验证的帐户,将忽略此选项。如果未使用基于 RSA 的密码交换(例如客户端使用安全连接连接到服务器的情况),此选项也将被忽略。The path name to a file in PEM format containing a client-side copy of the public key required by the server for RSA key pair-based password exchange. This option applies to clients that authenticate with the sha256_password (deprecated) or caching_sha2_password authentication plugin. This option is ignored for accounts that do not authenticate with one of those plugins. It is also ignored if RSA-based password exchange is not used, as is the case when the client connects to the server using a secure connection.

    如果提供了 --server-public-key-path=file_name 并指定了一个有效的公钥文件,则它优先于 --get-server-public-key。If --server-public-key-path=file_name is given and specifies a valid public key file, it takes precedence over --get-server-public-key.

    对于 sha256_password(已弃用),此选项仅在 MySQL 使用 OpenSSL 构建时才适用。For sha256_password (deprecated), this option applies only if MySQL was built using OpenSSL.

    有关 sha256_password 和 caching_sha2_password 插件的信息,请参见 第 8.4.1.3 节,“SHA-256 可插拔认证” 和 第 8.4.1.2 节,“缓存 SHA-2 可插拔认证”。For information about the sha256_password and caching_sha2_password plugins, see Section 8.4.1.3, “SHA-256 Pluggable Authentication”, and Section 8.4.1.2, “Caching SHA-2 Pluggable Authentication”.

  • --set-charset=charset_name --set-charset=charset_name

    命令行格式Command-Line Format --set-charset=charset_name--set-charset=charset_name
    类型Type 字符串String

    在输出中添加一个 SET NAMES charset_name 语句,以指定用于处理日志文件的字符集。Add a SET NAMES charset_name statement to the output to specify the character set to be used for processing log files.

  • --shared-memory-base-name=name --shared-memory-base-name=name

    命令行格式Command-Line Format --shared-memory-base-name=name--shared-memory-base-name=name
    特定平台Platform Specific 窗口Windows

    在 Windows 上,通过共享内存连接到本地服务器时使用的共享内存名称。默认值是 MYSQL。共享内存名称区分大小写。On Windows, the shared-memory name to use for connections made using shared memory to a local server. The default value is MYSQL. The shared-memory name is case-sensitive.

    此选项仅在服务器启用了 shared_memory 系统变量以支持共享内存连接时适用。This option applies only if the server was started with the shared_memory system variable enabled to support shared-memory connections.

  • --short-form, -s

    命令行格式Command-Line Format --short-form

    仅显示日志中包含的语句,不包含任何额外信息或基于行的事件。这仅用于测试,不应在生产系统中使用。它已被弃用,您应该预计在未来的版本中将其移除。Display only the statements contained in the log, without any extra information or row-based events. This is for testing only, and should not be used in production systems. It is deprecated, and you should expect it to be removed in a future release.

  • --skip-gtids[=(true|false)]

    命令行格式Command-Line Format --skip-gtids[=true|false]
    类型Type 布尔Boolean
    默认值Default Value falsefalse

    不要在输出转储文件中包含二进制日志文件的 GTID。例如:Do not include the GTIDs from the binary log files in the output dump file. For example:

    mysqlbinlog --skip-gtids binlog.000001 >  /tmp/dump.sql
    mysql -u root -p -e "source /tmp/dump.sql"
    

    通常情况下,你不应在生产环境或恢复环境中使用此选项,除非在特定且罕见的情况下,GTID 是不需要的。例如,管理员可能希望将选定的事务(如表定义)从一个部署复制到另一个不相关的部署,而后者不会与原部署进行复制。在这种情况下,可以使用 --skip-gtids 来使管理员能够像应用新事务一样应用这些事务,并确保这些部署保持不相关。然而,只有在 GTID 的包含会对你的使用情况造成已知问题时,你才应使用此选项。You should not normally use this option in production or in recovery, except in the specific, and rare, scenarios where the GTIDs are actively unwanted. For example, an administrator might want to duplicate selected transactions (such as table definitions) from a deployment to another, unrelated, deployment that will not replicate to or from the original. In that scenario, --skip-gtids can be used to enable the administrator to apply the transactions as if they were new, and ensure that the deployments remain unrelated. However, you should only use this option if the inclusion of the GTIDs causes a known issue for your use case.

  • --socket=path, -S path --socket=path, -S path

    命令行格式Command-Line Format --socket={file_name|pipe_name}--socket={file_name|pipe_name}
    类型Type 字符串String

    用于连接localhost时,使用的 Unix 套接字文件,或者在 Windows 上使用的命名管道的名称。For connections to localhost, the Unix socket file to use, or, on Windows, the name of the named pipe to use.

    在 Windows 上,此选项仅在服务器启用支持命名管道连接的 named_pipe 系统变量启动时才适用。此外,进行连接的用户必须是由 named_pipe_full_access_group 系统变量指定的 Windows 组的成员。On Windows, this option applies only if the server was started with the named_pipe system variable enabled to support named-pipe connections. In addition, the user making the connection must be a member of the Windows group specified by the named_pipe_full_access_group system variable.

  • --ssl*

    以--ssl开头的选项指定是否使用加密连接到服务器,并指示在哪里可以找到 SSL 密钥和证书。请参阅 加密连接的命令选项。Options that begin with --ssl specify whether to connect to the server using encryption and indicate where to find SSL keys and certificates. See Command Options for Encrypted Connections.

  • --ssl-fips-mode={OFF|ON|STRICT} --ssl-fips-mode={OFF|ON|STRICT}

    命令行格式Command-Line Format --ssl-fips-mode={OFF|ON|STRICT}--ssl-fips-mode={OFF|ON|STRICT}
    已弃用Deprecated 是Yes
    类型Type 枚举Enumeration
    默认值Default Value OFFOFF
    有效值Valid Values

    OFFOFF

    ONON

    STRICTSTRICT

    控制是否在客户端启用 FIPS 模式。--ssl-fips-mode 选项不同于其他 --ssl-xxx 选项,它不是用于建立加密连接,而是影响允许哪些加密操作。请参见 第 8.8 节,“FIPS 支持”。Controls whether to enable FIPS mode on the client side. The --ssl-fips-mode option differs from other --ssl-xxx options in that it is not used to establish encrypted connections, but rather to affect which cryptographic operations to permit. See Section 8.8, “FIPS Support”.

    允许使用的 --ssl-fips-mode 值如下:These --ssl-fips-mode values are permitted:

    • OFF:禁用 FIPS 模式。OFF: Disable FIPS mode.

    • ON:启用 FIPS 模式。ON: Enable FIPS mode.

    • STRICT:启用“严格” FIPS 模式。STRICT: Enable “strict” FIPS mode.

    Note

    如果 OpenSSL FIPS 对象模块不可用,--ssl-fips-mode 的唯一允许值是 OFF。在这种情况下,将 --ssl-fips-mode 设置为 ON 或 STRICT 会导致客户端在启动时产生警告,并以非 FIPS 模式运行。If the OpenSSL FIPS Object Module is not available, the only permitted value for --ssl-fips-mode is OFF. In this case, setting --ssl-fips-mode to ON or STRICT causes the client to produce a warning at startup and to operate in non-FIPS mode.

    此选项已弃用。预计将在未来的 MySQL 版本中移除。This option is deprecated. Expect it to be removed in a future version of MySQL.

  • --start-datetime=datetime

    命令行格式Command-Line Format --start-datetime=datetime--start-datetime=datetime
    类型Type 日期时间Datetime

    从具有时间戳等于或晚于datetime参数的第一个事件开始读取二进制日志。datetime的值是相对于运行mysqlbinlog的机器的本地时区。该值应采用DATETIME或TIMESTAMP数据类型接受的格式。例如:Start reading the binary log at the first event having a timestamp equal to or later than the datetime argument. The datetime value is relative to the local time zone on the machine where you run mysqlbinlog. The value should be in a format accepted for the DATETIME or TIMESTAMP data types. For example:

    mysqlbinlog --start-datetime="2005-12-25 11:25:56" binlog.000003
    

    此选项对于时间点恢复非常有用。参见 第 9.5 节,“时间点(增量)恢复”。This option is useful for point-in-time recovery. See Section 9.5, “Point-in-Time (Incremental) Recovery”.

  • --start-position=N, -j N

    命令行格式Command-Line Format --start-position=#
    类型Type 数字Numeric

    从日志位置 N 开始解码二进制日志,包括从位置 N 开始或之后的任何事件输出。该位置是日志文件中的字节点,而不是事件计数器;它需要指向事件的起始位置,以生成有用的输出。此选项适用于命令行中指定的第一个日志文件。Start decoding the binary log at the log position N, including in the output any events that begin at position N or after. The position is a byte point in the log file, not an event counter; it needs to point to the starting position of an event to generate useful output. This option applies to the first log file named on the command line.

    此选项支持的最大值为 18446744073709551616 (264-1),除非同时使用 --read-from-remote-server 或 --read-from-remote-source,在这种情况下最大值为 4294967295。The maximum value supported for this option is 18446744073709551616 (264-1), unless --read-from-remote-server or --read-from-remote-source is also used, in which case the maximum is 4294967295.

    此选项对于时间点恢复非常有用。参见 第 9.5 节,“时间点(增量)恢复”。This option is useful for point-in-time recovery. See Section 9.5, “Point-in-Time (Incremental) Recovery”.

  • --stop-datetime=datetime --stop-datetime=datetime

    命令行格式Command-Line Format --stop-datetime=datetime--stop-datetime=datetime

    在读取到第一个时间戳等于或晚于 datetime 参数的事件时停止读取二进制日志。有关 datetime 值的信息,请参阅 --start-datetime 选项的描述。Stop reading the binary log at the first event having a timestamp equal to or later than the datetime argument. See the description of the --start-datetime option for information about the datetime value.

    此选项对于时间点恢复非常有用。参见 第 9.5 节,“时间点(增量)恢复”。This option is useful for point-in-time recovery. See Section 9.5, “Point-in-Time (Incremental) Recovery”.

  • --stop-never

    命令行格式Command-Line Format --stop-never
    类型Type 布尔Boolean
    默认值Default Value FALSE

    此选项与 --read-from-remote-server 一起使用。它告诉 mysqlbinlog 保持与服务器的连接。否则,当服务器传输完最后一个日志文件时,mysqlbinlog 将退出。--stop-never 意味着 --to-last-log,因此命令行上只需指定要传输的第一个日志文件。This option is used with --read-from-remote-server. It tells mysqlbinlog to remain connected to the server. Otherwise mysqlbinlog exits when the last log file has been transferred from the server. --stop-never implies --to-last-log, so only the first log file to transfer need be named on the command line.

    --stop-never 通常与 --raw 一起使用,以进行实时二进制日志备份,但也可以不使用 --raw,以在服务器生成日志事件时持续显示日志文本。--stop-never is commonly used with --raw to make a live binary log backup, but also can be used without --raw to maintain a continuous text display of log events as the server generates them.

    使用 --stop-never 时,默认情况下,mysqlbinlog 在连接到服务器时会报告服务器 ID 为 1。使用 --connection-server-id 可以明确指定要报告的备用 ID。它可用于避免与副本服务器的 ID 或另一个 mysqlbinlog 进程发生冲突。参见 第 6.6.9.4 节,“指定 mysqlbinlog 服务器 ID”。With --stop-never, by default, mysqlbinlog reports a server ID of 1 when it connects to the server. Use --connection-server-id to explicitly specify an alternative ID to report. It can be used to avoid a conflict with the ID of a replica server or another mysqlbinlog process. See Section 6.6.9.4, “Specifying the mysqlbinlog Server ID”.

  • --stop-never-slave-server-id=id --stop-never-slave-server-id=id

    命令行格式Command-Line Format --stop-never-slave-server-id=#
    类型Type 数字Numeric
    默认值Default Value 65535
    最小值Minimum Value 1

    此选项已被弃用;预计将在未来的版本中移除。请改用 --connection-server-id 选项来为 mysqlbinlog 指定服务器 ID。This option is deprecated; expect it to be removed in a future release. Use the --connection-server-id option instead to specify a server ID for mysqlbinlog to report.

  • --stop-position=N

    命令行格式Command-Line Format --stop-position=#
    类型Type 数字Numeric

    在日志位置 N 停止解码二进制日志,输出中不包括从位置 N 开始或之后的任何事件。该位置是日志文件中的字节点,而不是事件计数器;它需要指向最后一个你希望包含在输出中的事件的起始位置之后的点。在位置 N 之前开始并在该位置或之后结束的事件是要处理的最后一个事件。此选项适用于命令行中指定的最后一个日志文件。Stop decoding the binary log at the log position N, excluding from the output any events that begin at position N or after. The position is a byte point in the log file, not an event counter; it needs to point to a spot after the starting position of the last event you want to include in the output. The event starting before position N and finishing at or after the position is the last event to be processed. This option applies to the last log file named on the command line.

    此选项对于时间点恢复非常有用。参见 第 9.5 节,“时间点(增量)恢复”。This option is useful for point-in-time recovery. See Section 9.5, “Point-in-Time (Incremental) Recovery”.

  • --tls-ciphersuites=ciphersuite_list --tls-ciphersuites=ciphersuite_list

    命令行格式Command-Line Format --tls-ciphersuites=ciphersuite_list--tls-ciphersuites=ciphersuite_list
    类型Type 字符串String

    用于 TLSv1.3 加密连接的允许密码套件。该值是一个或多个用冒号分隔的密码套件名称的列表。此选项可指定的密码套件取决于用于编译 MySQL 的 SSL 库。有关详细信息,请参见 第 8.3.2 节,“加密连接的 TLS 协议和密码”。The permissible ciphersuites for encrypted connections that use TLSv1.3. The value is a list of one or more colon-separated ciphersuite names. The ciphersuites that can be named for this option depend on the SSL library used to compile MySQL. For details, see Section 8.3.2, “Encrypted Connection TLS Protocols and Ciphers”.

  • --tls-sni-servername=server_name --tls-sni-servername=server_name

    命令行格式Command-Line Format --tls-sni-servername=server_name--tls-sni-servername=server_name
    类型Type 字符串String

    如果指定了名称,该名称将通过 mysql_options() 的 MYSQL_OPT_TLS_SNI_SERVERNAME 选项传递给 libmysqlclient C API 库。服务器名称不区分大小写。要显示客户端为当前会话指定的服务器名称(如果有),请检查 Tls_sni_server_name 状态变量。When specified, the name is passed to the libmysqlclient C API library using the MYSQL_OPT_TLS_SNI_SERVERNAME option of mysql_options(). The server name is not case-sensitive. To show which server name the client specified for the current session, if any, check the Tls_sni_server_name status variable.

    服务器名称指示(SNI)是 TLS 协议的一个扩展(必须使用支持 TLS 扩展的 OpenSSL 编译此选项才能生效)。MySQL 对 SNI 的实现仅代表客户端。Server Name Indication (SNI) is an extension to the TLS protocol (OpenSSL must be compiled using TLS extensions for this option to function). The MySQL implementation of SNI represents the client-side only.

  • --tls-version=protocol_list --tls-version=protocol_list

    命令行格式Command-Line Format --tls-version=protocol_list--tls-version=protocol_list
    类型Type 字符串String
    默认值Default Value

    TLSv1,TLSv1.1,TLSv1.2,TLSv1.3(OpenSSL 1.1.1 或更高版本)TLSv1,TLSv1.1,TLSv1.2,TLSv1.3 (OpenSSL 1.1.1 or higher)

    TLSv1,TLSv1.1,TLSv1.2(否则)TLSv1,TLSv1.1,TLSv1.2 (otherwise)

    用于加密连接的允许 TLS 协议。值是一个或多个以逗号分隔的协议名称列表。此选项可指定的协议取决于用于编译 MySQL 的 SSL 库。详情请参见 第 8.3.2 节,“加密连接 TLS 协议和密码”。The permissible TLS protocols for encrypted connections. The value is a list of one or more comma-separated protocol names. The protocols that can be named for this option depend on the SSL library used to compile MySQL. For details, see Section 8.3.2, “Encrypted Connection TLS Protocols and Ciphers”.

  • --to-last-log, -t

    命令行格式Command-Line Format --to-last-log

    不要在请求的 MySQL 服务器二进制日志结束时停止,而是继续打印直到最后一个二进制日志的结尾。如果将输出发送到同一 MySQL 服务器,这可能导致无限循环。此选项需要 --read-from-remote-server。Do not stop at the end of the requested binary log from a MySQL server, but rather continue printing until the end of the last binary log. If you send the output to the same MySQL server, this may lead to an endless loop. This option requires --read-from-remote-server.

  • --user=user_name, -u user_name

    命令行格式Command-Line Format --user=user_name,--user=user_name,
    类型Type 字符串String

    用于连接远程服务器时的 MySQL 帐户用户名。The user name of the MySQL account to use when connecting to a remote server.

    如果您使用 Rewriter 插件,则应授予此用户 SKIP_QUERY_REWRITE 权限。If you are using the Rewriter plugin, you should grant this user the SKIP_QUERY_REWRITE privilege.

  • --verbose, -v

    命令行格式Command-Line Format --verbose--verbose

    重建行事件并将其显示为带注释的 SQL 语句,并在适用的情况下显示表分区信息。如果此选项被使用两次(通过输入“-vv”或“--verbose --verbose”),输出将包括注释以指示列数据类型和一些元数据,以及信息性日志事件,例如行查询日志事件,如果 binlog_rows_query_log_events 系统变量设置为 TRUE。Reconstruct row events and display them as commented SQL statements, with table partition information where applicable. If this option is given twice (by passing in either "-vv" or "--verbose --verbose"), the output includes comments to indicate column data types and some metadata, and informational log events such as row query log events if the binlog_rows_query_log_events system variable is set to TRUE.

    有关显示 --base64-output 和 --verbose 对行事件输出影响的示例,请参见 第 6.6.9.2 节,“mysqlbinlog 行事件显示”。For examples that show the effect of --base64-output and --verbose on row event output, see Section 6.6.9.2, “mysqlbinlog Row Event Display”.

  • --verify-binlog-checksum, -c

    命令行格式Command-Line Format --verify-binlog-checksum

    验证二进制日志文件中的校验和。Verify checksums in binary log files.

  • --version, -V

    命令行格式Command-Line Format --version

    显示版本信息并退出。Display version information and exit.

  • --zstd-compression-level=level --zstd-compression-level=level

    命令行格式Command-Line Format --zstd-compression-level=#
    类型Type 整数Integer

    用于与服务器连接时使用 zstd 压缩算法的压缩级别。允许的级别从 1 到 22,数值越大表示压缩级别越高。默认的 zstd 压缩级别为 3。对于不使用 zstd 压缩的连接,压缩级别设置没有效果。The compression level to use for connections to the server that use the zstd compression algorithm. The permitted levels are from 1 to 22, with larger values indicating increasing levels of compression. The default zstd compression level is 3. The compression level setting has no effect on connections that do not use zstd compression.

    更多信息,请参阅 第 6.2.8 节,“连接压缩控制”。For more information, see Section 6.2.8, “Connection Compression Control”.

您可以将 mysqlbinlog 的输出传输到 mysql 客户端,以执行二进制日志中包含的事件。当您有一个旧备份时,这种技术用于从意外退出中恢复(参见 第 9.5 节,“时间点(增量)恢复”)。例如:You can pipe the output of mysqlbinlog into the mysql client to execute the events contained in the binary log. This technique is used to recover from an unexpected exit when you have an old backup (see Section 9.5, “Point-in-Time (Incremental) Recovery”). For example:

mysqlbinlog binlog.000001 | mysql -u root -p

或者:Or:

mysqlbinlog binlog.[0-9]* | mysql -u root -p

如果 mysqlbinlog 生成的语句可能包含 BLOB 值,这些值在 mysql 处理时可能会引起问题。在这种情况下,可使用 mysql 并加上 --binary-mode 选项。If the statements produced by mysqlbinlog may contain BLOB values, these may cause problems when mysql processes them. In this case, invoke mysql with the --binary-mode option.

如果你需要先修改语句日志(例如,删除因某些原因不想执行的语句),你也可以将 mysqlbinlog 的输出重定向到一个文本文件中。编辑文件后,可以将其内容作为输入,通过 mysql 程序执行这些语句:You can also redirect the output of mysqlbinlog to a text file instead, if you need to modify the statement log first (for example, to remove statements that you do not want to execute for some reason). After editing the file, execute the statements that it contains by using it as input to the mysql program:

mysqlbinlog binlog.000001 > tmpfile
... edit tmpfile ...
mysql -u root -p < tmpfile

当mysqlbinlog使用--start-position选项调用时,它仅显示二进制日志中偏移量大于或等于指定位置的事件(指定的位置必须与某个事件的开始位置匹配)。它还具有在看到具有特定日期和时间的事件时停止和启动的选项。这使您能够使用--stop-datetime选项执行时间点恢复(例如,可以说“将我的数据库回滚到今天上午 10:30 的状态”)。When mysqlbinlog is invoked with the --start-position option, it displays only those events with an offset in the binary log greater than or equal to a given position (the given position must match the start of one event). It also has options to stop and start when it sees an event with a given date and time. This enables you to perform point-in-time recovery using the --stop-datetime option (to be able to say, for example, “roll forward my databases to how they were today at 10:30 a.m.”).

处理多个文件。 如果您有多个二进制日志需要在 MySQL 服务器上执行,安全的方法是使用单个连接处理所有日志。以下是一个示例,展示了可能是不安全的做法:Processing multiple files.  If you have more than one binary log to execute on the MySQL server, the safe method is to process them all using a single connection to the server. Here is an example that demonstrates what may be unsafe:

mysqlbinlog binlog.000001 | mysql -u root -p # DANGER!!
mysqlbinlog binlog.000002 | mysql -u root -p # DANGER!!

使用多个连接方式处理二进制日志时,如果第一个日志文件包含CREATE TEMPORARY TABLE语句,而第二个日志包含使用该临时表的语句,就会产生问题。当第一个mysql进程终止时,服务器会删除临时表。当第二个mysql进程尝试使用该表时,服务器会报告“未知表。”Processing binary logs this way using multiple connections to the server causes problems if the first log file contains a CREATE TEMPORARY TABLE statement and the second log contains a statement that uses the temporary table. When the first mysql process terminates, the server drops the temporary table. When the second mysql process attempts to use the table, the server reports “unknown table.”

为了避免此类问题,使用一个 单一 mysql 进程来执行所有你想处理的二进制日志的内容。以下是实现这一点的一种方法:To avoid problems like this, use a single mysql process to execute the contents of all binary logs that you want to process. Here is one way to do so:

mysqlbinlog binlog.000001 binlog.000002 | mysql -u root -p

另一种方法是将所有日志写入单个文件,然后处理该文件:Another approach is to write all the logs to a single file and then process the file:

mysqlbinlog binlog.000001 >  /tmp/statements.sql
mysqlbinlog binlog.000002 >> /tmp/statements.sql
mysql -u root -p -e "source /tmp/statements.sql"

您也可以通过使用 shell 管道,将多个二进制日志文件作为流输入提供给 mysqlbinlog。压缩的二进制日志文件归档可以解压后直接提供给 mysqlbinlog。在此示例中,binlog-files_1.gz 包含多个用于处理的二进制日志文件。该管道会提取 binlog-files_1.gz 的内容,将二进制日志文件通过管道传输到 mysqlbinlog 作为标准输入,并将 mysqlbinlog 的输出管道传输到 mysql 客户端进行执行:You can also supply multiple binary log files to mysqlbinlog as streamed input using a shell pipe. An archive of compressed binary log files can be decompressed and provided directly to mysqlbinlog. In this example, binlog-files_1.gz contains multiple binary log files for processing. The pipeline extracts the contents of binlog-files_1.gz, pipes the binary log files to mysqlbinlog as standard input, and pipes the output of mysqlbinlog into the mysql client for execution:

gzip -cd binlog-files_1.gz | ./mysqlbinlog - | ./mysql -uroot  -p

您可以指定多个归档文件,例如:You can specify more than one archive file, for example:

gzip -cd binlog-files_1.gz binlog-files_2.gz | ./mysqlbinlog - | ./mysql -uroot  -p

对于流式输入,请不要使用--stop-position,因为mysqlbinlog无法识别要应用此选项的最后一个日志文件。For streamed input, do not use --stop-position, because mysqlbinlog cannot identify the last log file to apply this option.

LOAD DATA 操作。 mysqlbinlog 可以生成输出,以重现没有原始数据文件的 LOAD DATA 操作。mysqlbinlog 会将数据复制到一个临时文件,并写入一个引用该文件的 LOAD DATA LOCAL 语句。写入这些文件的目录的默认位置是系统特定的。要明确指定目录,请使用 --local-load 选项。LOAD DATA operations.  mysqlbinlog can produce output that reproduces a LOAD DATA operation without the original data file. mysqlbinlog copies the data to a temporary file and writes a LOAD DATA LOCAL statement that refers to the file. The default location of the directory where these files are written is system-specific. To specify a directory explicitly, use the --local-load option.

因为mysqlbinlog将LOAD DATA语句转换为LOAD DATA LOCAL语句(即,它添加了LOCAL),因此用于处理这些语句的客户端和服务器都必须启用LOCAL功能。请参阅第 8.1.6 节,“LOAD DATA LOCAL 的安全性注意事项”。Because mysqlbinlog converts LOAD DATA statements to LOAD DATA LOCAL statements (that is, it adds LOCAL), both the client and the server that you use to process the statements must be configured with the LOCAL capability enabled. See Section 8.1.6, “Security Considerations for LOAD DATA LOCAL”.

Warning

为LOAD DATA LOCAL语句创建的临时文件不会自动删除,因为在实际执行这些语句之前,需要保留它们。在不再需要语句日志后,您应自行删除这些临时文件。这些文件可以在临时文件目录中找到,文件名类似于original_file_name-#-#。The temporary files created for LOAD DATA LOCAL statements are not automatically deleted because they are needed until you actually execute those statements. You should delete the temporary files yourself after you no longer need the statement log. The files can be found in the temporary file directory and have names like original_file_name-#-#.