When you accidentally run an INSERT, UPDATE, or DELETE statement in the DMS SQL Console, data tracking lets you parse the database binary logs to generate rollback SQL — without a full database restore.
Prerequisites
Before you begin, confirm all of the following:
MySQL 5.6 or later
Binary logging enabled on the database instance
The database instance connected to Data Management (DMS). Supported types:
ApsaraDB RDS for MySQL
PolarDB for MySQL
Self-managed MySQL on Elastic Compute Service (ECS) instances
Self-managed MySQL in on-premises data centers
MySQL databases from other cloud providers
Logged on to the database in DMS — except for Security Collaboration mode, which does not require a logon
Limitations
| Management mode | Trackable time range | Export rollback/rebuild scripts |
|---|---|---|
| Flexible Management | Last 30 minutes only | Not supported |
| Stable Change | Within the binary log retention period, up to 48 hours per ticket | Supported |
| Security Collaboration | Within the binary log retention period, up to 48 hours per ticket | Supported |
Additional constraints:
Only DML operations (INSERT, UPDATE, DELETE) can be tracked. DDL operations are not supported.
If binary logging is disabled or you have not logged on to the database, DMS cannot retrieve binary logs.
DMS cannot retrieve data for operations performed before the binary log retention period.
For time ranges exceeding 48 hours, submit multiple tickets — one per 48-hour window.
Track data changes
Log on to the DMS console V5.0.
In the top navigation bar, click Database Development > Data Tracking > Data Tracking Ticket.
In simple mode, hover over the
icon in the upper-left corner, then choose All Features > Database Development > Data Tracking > Data Tracking Ticket.On the Data Tracking Ticket page, click Data Tracking in the upper-right corner.
On the Data Tracking Tickets page, configure the following parameters, then click Submit. After you click Submit, DMS starts downloading the binary logs and the ticket moves to the Approval step.
Parameter Description Task Name Enter a name that identifies the ticket and helps approvers understand its purpose. Database Name Select the database to track. You must have DMS management permissions for the database. Type a prefix to filter results. Table Name Select one or more tables to track. Track Type Select the operation types to track: Insert, Update, or Delete. INSERTstatements are generated to roll back INSERT operations,UPDATEstatements are generated to roll back UPDATE operations, andDELETEstatements are generated to roll back DELETE operations.Time Range Specify the time window. Flexible Management: last 30 minutes. Stable Change or Security Collaboration: any window within the binary log retention period, up to 48 hours per ticket. Change Stakeholder Select stakeholders for this ticket. Only selected stakeholders and approvers can view ticket details. Wait for the ticket to be approved.
By default, the database administrator (DBA) of the selected database approves data tracking tickets. For approval rule details, see Data tracking.
After approval, wait for DMS to download and parse the binary logs.
After parsing is complete, use the Track Type, Table Name, and Column Name filters to locate the records to roll back. Select the records, then click Export Rollback Script. The rollback script downloads to your local machine.
To inspect a single record before exporting, click View Details to review the full record and copy individual rollback statements.
What to do next
Execute the rollback script
Choose an execution method based on the number of affected rows:
Small number of rows: Run the rollback statements directly in the SQL Console. See Manage a database on the SQLConsole tab.
Large number of rows: Submit a Normal Data Modify ticket and upload the rollback script as the SQL file. See Perform regular data change.
Automate with the API
Use the following API operations to manage data tracking programmatically: