扩展 MySQL 8.0  / 第 4 章 MySQL 插件 API  / 4.4 编写插件  / 4.4.11 编写协议跟踪插件  /  4.4.11.1 使用测试协议跟踪插件

4.4.11.1 使用测试协议跟踪插件

MySQL 包含一个测试协议跟踪插件,用于说明可从此类插件获得的信息,并作为编写其他协议跟踪插件的指南。要查看测试插件的工作原理,请使用 MySQL 源代码分发;二进制发行版是在禁用测试插件的情况下构建的。

通过在启用CMake选项 的情况下配置 MySQL 来启用测试协议跟踪插件 。这会导致构建测试跟踪插件并加载 MySQL 客户端程序,但默认情况下该插件无效。使用这些环境变量控制插件: WITH_TEST_TRACE_PLUGIN

  • MYSQL_TEST_TRACE_DEBUG:将此变量设置为 0 以外的值,以使测试插件在 上生成诊断输出 stderr

  • MYSQL_TEST_TRACE_CRASH: 将此变量设置为 0 以外的值,以导致测试插件在检测到无效跟踪事件时中止客户端程序。

警告

测试协议跟踪插件的诊断输出可能会泄露密码和其他敏感信息。

假设从源代码构建的 MySQL 安装启用了测试插件,您可以看到mysql客户端和 MySQL 服务器之间的通信轨迹,如下所示:

$> export MYSQL_TEST_TRACE_DEBUG=1
shqll> mysql
test_trace: Test trace plugin initialized
test_trace: Starting tracing in stage CONNECTING
test_trace: stage: CONNECTING, event: CONNECTING
test_trace: stage: CONNECTING, event: CONNECTED
test_trace: stage: WAIT_FOR_INIT_PACKET, event: READ_PACKET
test_trace: stage: WAIT_FOR_INIT_PACKET, event: PACKET_RECEIVED
test_trace: packet received: 87 bytes
  0A 35 2E 37 2E 33 2D 6D  31 33 2D 64 65 62 75 67   .5.7.3-m13-debug
  2D 6C 6F 67 00 04 00 00  00 2B 7C 4F 55 3F 79 67   -log.....+|OU?yg
test_trace: 004: stage: WAIT_FOR_INIT_PACKET, event: INIT_PACKET_RECEIVED
test_trace: 004: stage: AUTHENTICATE, event: AUTH_PLUGIN
test_trace: 004: Using authentication plugin: mysql_native_password
test_trace: 004: stage: AUTHENTICATE, event: SEND_AUTH_RESPONSE
test_trace: 004: sending packet: 188 bytes
  85 A6 7F 00 00 00 00 01  21 00 00 00 00 00 00 00   .?......!.......
  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
...
mysql> quit
test_trace: 008: stage: READY_FOR_COMMAND, event: SEND_COMMAND
test_trace: 008: QUIT
test_trace: 008: stage: READY_FOR_COMMAND, event: PACKET_SENT
test_trace: 008: packet sent: 0 bytes
test_trace: 008: stage: READY_FOR_COMMAND, event: DISCONNECTED
test_trace: 008: Connection  closed
test_trace: 008: Tracing connection has ended
Bye
test_trace: Test trace plugin de-initialized

要禁用跟踪输出,请执行以下操作:

$> MYSQL_TEST_TRACE_DEBUG=