Traffic playback lets you run comprehensive compatibility and performance tests on a target database before migration to minimize potential threats. This topic describes how to use the MySQL database traffic playback feature, using the migration of a database from MySQL to PolarDB for MySQL as an example.
Step 1: Prepare the data
You can use the mysqlsniffer tool provided by Cloud Migration Hub (CMH) to capture SQL execution records from a MySQL database. You can then play back these records on the target database. The following sections describe the required steps and parameters in detail.
1. Install mysqlsniffer
Create a folder to store the mysqlsniffer tool. You can contact CMH to obtain the tool.
bash
Copy code
mkdir -p /home/frodo/collector2. Configure and run mysqlsniffer
mysqlsniffer supports two methods to capture SQL traffic: capturing network packets (net_capture) and reading from the general log (general_log). The following list describes the common parameters:
--capture-method: The method to capture SQL statements.net_capture: Captures SQL statements by sniffing network packets.general_log: Reads SQL statements from the MySQL general log file.
--replay-to: The playback destination.file: Outputs SQL statements in JSON format to a file.stdout: Outputs to the console.
--port: The source database port.--username: The source database username.--password: The source database password.--network-device: The network interface card (NIC) for packet sniffing, such aseth0.--concurrency: The number of concurrent connections.--time: The runtime duration in seconds.--log-level: The log level. Valid values areinfo,debug, anderror.
For example, if your MySQL database uses the eth0 NIC, the port is 3306, the username is root, and the password is password123, you can run the following command to save the SQL records to a file:
bash
Copy code
/home/frodo/collector/mysqlsniffer \
--capture-method net_capture \
--replay-to file \
--port 3306 \
--username root \
--password password123 \
--network-device eth0 \
--concurrency 10 \
--time 3600 \
--log-level info3. Upload the SQL file
Upload the generated SQL file to a bucket in Alibaba Cloud Object Storage Service (OSS). Ensure that you have created an OSS bucket and have the required permissions to access it.
If mysqlsniffer does not meet your requirements, you can use the open-source tool Tshark to collect traffic.
Step 2: Go to the CMH console
Log on to your Alibaba Cloud account and go to the CMH console.
Step 3: Create a new playback plan
In the CMH console, choose Migration Capability > Traffic Playback. For more information, see Create a playback plan.
Click Create Playback Plan to start configuring your playback task.

1. Enter basic information
Task Name: Enter a name for your playback task.
Replay Type: Select "Traffic Replay" because this is the scenario for performance testing.
Source Data Source: Select your source database type. This example uses MySQL.
Destination Data Source: Select PolarDB for MySQL, and then enter the required instance information, such as the region and instance ID. Acquisition Method: For Alibaba Cloud services, we recommend that you select "Instance Acquisition" to directly associate your database instance. Database Name/Username/Password: Enter the required information to complete the connection settings.
SQL File Type: If you used
mysqlsnifferto collect traffic, select Standard Format. If you used Tshark, select Tshark Format.Replay Instance: To create a new instance, select "Create New Instance". Otherwise, select an existing instance.
Playback File Bucket Address: Select the OSS bucket where you uploaded the SQL file.

2. Set playback parameters
Number Of Simulated Clients: Set the number of concurrent users. This setting directly affects the amount of load that is generated.
Playback Speed Factor: Adjust the playback speed multiplier. The default value is 1, which indicates that the playback runs at the original speed.
Step 4: Run the playback task
After you complete the configuration, save the settings.
On the playback plan details page, click Create Task. Then, select the playback instance and playback file.
Select Playback Instance | You can select multiple playback instances. If you select multiple instances, the task runs the playback file on all selected instances at the same time. If you select N instances, the pressure on the database increases by N times. |
Select Playback File | Select the playback file that you uploaded to the OSS bucket associated with the playback plan. This file is refreshed to the playback instance each time you create a playback task. |
Confirm the other configuration parameters and then submit the task.
On the task list page, start the playback task. The system then executes the SQL statements on the PolarDB for MySQL database and monitors its performance based on your configuration.
