Mysql-replay: Replicating MySQL Traffic to TiDB 6.X

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: mysql-replay复制mysql流量到Tidb6.X

| username: TiDBer_xuY2invl

Requirement Feedback
Please clearly and accurately describe the problem scenario, desired behavior, and background information to facilitate timely follow-up by the product team.
[Problem Scenario Involved in the Requirement]
Using the mysql-replay tool to replicate traffic accessing MySQL8 online to TiDB6
[Desired Behavior of the Requirement]
Using the mysql-replay tool to replicate MySQL8.0 traffic to TiDB6
The command used is as follows:
mysql-replay serve --ports 3306 --target-dsn=‘admin:admin@tcp(10.0.9.177:4000)/test’
[Alternative Solutions for the Requirement]
None
[Background Information]
Such as which users will benefit from it, and some usage scenarios, any API design, models, or diagrams would be more helpful.

| username: TammyLi | Original post link

There are no plans to develop new features for mysql-replay in the near future. You can use the existing features. Source code: GitHub - zyguan/mysql-replay: replay mysql traffics from tcpdump pcap file, like tcpcopy

| username: TiDBer_xuY2invl | Original post link

Execute on the source server:
mysql-replay serve --ports 3306 --target-dsn=‘admin:admin@tcp(10.0.9.177:4000)/test’
After inserting data into the source server MySQL, mysql-replay did not replicate the traffic to the target server.

Is there a usage example for this mysql-replay? Could you please provide one?

| username: TiDBer_xuY2invl | Original post link

Hello!
We are testing the performance and traffic of migrating MySQL 8.0 to TiDB 6, but we encountered an issue.
When using mysql-replay for online traffic replay, we encountered the following problem:
md5sum mismatch
How can this be resolved?
There are no examples for the mysql-replay tool on GitHub, so how are we supposed to figure this out? It’s frustrating to guess how to use a tool.

| username: TammyLi | Original post link

Instructions
Compilation and Installation

git clone https://github.com/zyguan/mysql-replay.git && cd mysql-replay
git checkout dev
go build

Offline Replay
First, use tcpdump to capture database traffic on the specified node to obtain a pcap file.
Tips: You can specify the capture time using the -G and -W parameters.
Replay the pcap files offline using the mysql-replay replay subcommand.

Replay pcap files

Usage:
mysql-replay replay [flags]

Flags:
–conn-cache-size uint packet cache size for each connection
–dry-run dry run mode (just print statements)
-h, --help help for replay
–ports ints ports to filter in (default [4000])
–speed float replay speed ratio (default 1)
–target-dsn string target dsn

Global Flags:
–log-level string log level (default “info”)
–log-output strings log output (default [stdout])


--dry-run and --target-dsn require one to be specified: dry-run outputs the SQL to be executed without actually connecting to the database for replay; target-dsn format must comply with go-sql-driver specifications.
--speed is used to control the replay speed, 1 means replay at original speed, 0.5 and 2 mean half speed and double speed respectively, 0 means full speed, i.e., as fast as possible (limited by the target db).
--ports specifies port filtering conditions, which can be understood as the bpf filter expression tcp port <port>.

Online Replay
Start the replay server using the mysql-replay serve subcommand.

Serve for replay requests

Usage:
  mysql-replay serve [flags]

Flags:
      --addr string            address to listen on (default ":5000")
      --archive-dir string     directory to save dumped files (default "archives")
      --conn-cache-size uint   packet cache size for each connection (default 128)
      --dry-run                dry run mode (just print statements)
  -h, --help                   help for serve
      --meta string            path to meta data (default "meta.db")
      --ports ints             ports to filter in (default [4000])
      --speed float            replay speed ratio (default 1)
      --target-dsn string      target dsn

Global Flags:
      --log-level string     log level (default "info")
      --log-output strings   log output (default [stdout])

Start tcpdump on the node where traffic needs to be captured, and set the post rotate action script. In the script, notify the replay server using the mysql-replay notify subcommand. Refer to the brief tcpdump instructions for more details.

Text Format Export and Replay
To facilitate exporting, anonymizing, and bringing user scenarios back for internal testing, the new version of mysql-replay supports text format export and replay (text format also supports prepared statements). Operations can be performed using text <dump|play>.

Text Format Definition
mysql-replay can parse MySQL packets in pcap into a series of logical events (MySQLEvent), currently mainly supporting Query, StmtPrepare, StmtExecute, etc., which can cover most application scenarios. The export format is: each session corresponds to a file, and each line in the file corresponds to an event. The event serialization format is similar to the following tsv:

1629093374259   0       "test"
1629093374283   3       1       "SELECT c_discount, c_last, c_credit, w_tax FROM customer, warehouse WHERE w_id = ? AND c_w_id = w_id AND c_d_id = ? AND c_id = ?"
1629093374706   2       "START TRANSACTION"
1629093374709   4       1       [iii    23      6       2255
1629093374755   2       "COMMIT"

Export Text

mysql-replay text dump [--force-start] -o <output-directory> <input-pcap-files>

Parameter Description:
–force-start By default, mysql-replay requires a session to start from the establishment of the TCP connection. If the connection already exists when capturing, it will be ignored. Specifying this option forces mysql-replay to process these connections (starting from the middle of the connection may produce some abnormal states).
The output directory, each session will generate a file, the file name is ...tsv.
The list of input pcap files. When specifying multiple files, ensure that these files are continuous.

Execute Text

mysql-replay text play [flags] <input-directory>

Flags:
–dry-run dry run mode (just print events)
–max-line-size int max line size (default 16777216)
–query-timeout duration timeout for a single query (default 1m0s)
–report-interval duration report interval (default 5s)
–speed float speed ratio (default 1)
–target-dsn string target dsn

Parameter Description:
The directory of the exported text.
dry-run Only print the SQL to be executed without actually executing it.
max-line-size By default, a single line in the input file cannot exceed 16M. Otherwise, set a larger value using this parameter.
query-timeout The timeout for a single query. mysql-replay will actively abandon queries that timeout.
report-interval The frequency of statistical output, default is one output every 5s.
speed Replay speed, 1 means original speed, 1.5 means 1.5 times speed, 0 means no speed limit.
target-dsn The target database address, see go-sql-driver for the format. Note that dbname needs to be specified.

| username: system | Original post link

This topic was automatically closed 1 minute after the last reply. No new replies are allowed.