Publish to MySQL
MySQL publishing writes TDengine TMQ subscription data to a single MySQL table for downstream applications to query. Verification must confirm that primary keys, timestamps, and business fields in the target match the source. Target connectivity, a successful preview, or healthy task status does not mean verification is complete.
Where to operate: taosExplorer → Data Out → MySQL. Prepare the source in the taosExplorer Data Browser or taos CLI, and prepare the target database and verify downstream in a MySQL client.
Data flows TDengine TMQ → taosX → MySQL. To ingest data from MySQL, follow MySQL.
1. Prepare the Environment
- Verify that
taosdandtaosAdapterare running and that taosX is installed with data publishing support. - Use MySQL 5.6, 5.7, or 8.0 and later. The target database must already exist. taosX does not create databases.
- Set
WAL_RETENTION_PERIODon the source database to a value greater than 0. The source user needs permission to create topics and subscribe. The target user needs permission to write to the table and, if automatic table creation is enabled, to create it. - Execution through taosX-Agent or
VIAis not supported.
2. Prepare Data
Run the following SQL in the taos CLI or taosExplorer to create an example supertable and insert a row. In the taos CLI, put each statement on a single line before running it. You do not need to create a topic manually.
CREATE DATABASE IF NOT EXISTS dataout_mysql_demo
VGROUPS 1
WAL_RETENTION_PERIOD 3600;
CREATE STABLE IF NOT EXISTS dataout_mysql_demo.meters (
ts TIMESTAMP,
current FLOAT,
voltage INT
) TAGS (
device VARCHAR(16)
);
INSERT INTO dataout_mysql_demo.meter01
USING dataout_mysql_demo.meters
TAGS ('meter01')
VALUES (NOW, 10.5, 220);
3. Create a MySQL Data Out Task
In taosExplorer, open Data Out, click Create New Task, enter a task name, and select MySQL as the data target type.
3.1 TDengine Subscription

- TDengine Endpoint: for example
tmq+ws://USER:PASSWORD@localhost:6041/dataout_mysql_demo. The database in the path is the default database of the subscription SQL. - Subscription SQL: a single
SELECTquery. It follows TDengine query topic rules: query one table, child table or supertable, and project columns, tags,tbnameand scalar functions with an optionalWHERE. Aggregates, windows, JOIN, subqueries,UNION,DISTINCT,GROUP BY,ORDER BY,LIMITand virtual tables are not supported. - Start Position:
earliestincludes historical data,latestsubscribes only new data. It takes effect only on the first consumption of the consumer group. - Consumer Group ID: defaults to the task topic name. Changing it uses a new consumer group and rereads the data.
- TSDB Data: when enabled, persisted TSDB data is subscribed as well, not only WAL data. Together with the start position it determines what is read on the first start.
| Start Position | TSDB Data | Data read on the first start |
|---|---|---|
| earliest | on | All persisted historical data from TSDB, then WAL for new data |
| earliest | off | Only from the earliest position still retained in WAL |
| latest | any | Only data written after the task starts |
For this example, use SELECT ts, device, current, voltage FROM dataout_mysql_demo.meters. For more about query topics and consumer positions, see Data Subscription.
3.2 Connection and Authentication
Under Connection, enter the host, port (default 3306), and the name of an existing database such as rdb_out. Under Authentication, enter the database user and password.
- SSL Mode: Choose
DISABLED,PREFERRED, orREQUIREDto match the MySQL server’s TLS configuration.
3.3 Target Table

- Table: Enter the target table name, such as
meters_out. - Create Table: If enabled, taosX creates the table when it does not exist. For an existing table, taosX checks compatibility without changing the table definition.
- Storage engine: Existing target tables must use a transactional engine such as InnoDB. taosX rejects nontransactional tables such as MyISAM.
- Primary Key: Fetch the result columns and select up to 16 columns. The form initially selects the first eligible column. In this example, select
tsanddeviceas the composite key and use a differentdevicevalue for each child table. If you select onlyts, rows from different child tables at the same timestamp can overwrite one another. Using the shortdevicetag instead oftbnamekeeps the key within the 767-byte limit that taosX applies to MySQL 5.6. - Timestamp Storage: With Auto, millisecond and microsecond timestamps use a date-time type and nanosecond timestamps use
BIGINT. WithBIGINT, all timestamps are stored as raw integers. - Timestamp columns in existing tables: In automatic mode, use
DATETIMEfor millisecond or microsecond timestamps.TIMESTAMPis not supported because MySQL would convert the written values using the session time zone. - Time Zone: Time zone for converting timestamps to date-time values. Leave this empty to use the taosX host’s local time zone.
3.4 Advanced
- Batch Size: maximum rows written per batch, default 1000.
- Batch Timeout (ms): maximum wait before a batch is written, default 1000.
- Write Timeout and Max Retry Time: configurable through DSN parameters, default to 60 and 180 seconds.
3.5 Connectivity Check and Preview
- Click Check Connection to check that the query returns a compatible result schema and that the target is reachable. This check does not create a topic. For query-topic restrictions, use the full preview or start the task.
- Set Row Count and Wait Time (s) and click Preview Data. The preview returns when it reaches either limit. Review the sample rows, the table creation statement (if a table needs to be created), and the write statement template. Preview does not write to the target database or alter the task’s consumer position.
- Click Submit, find the original task in the Data Out task list, and confirm its actual running status. Start the original task if it is stopped; do not create a duplicate. Then verify the target table as described in section 4.
4. Verify the Target Table
Confirm the target database and table in a MySQL client. Then run the following in the source cluster's taosExplorer Data Browser or taos CLI:
INSERT INTO dataout_mysql_demo.meter01 VALUES (NOW, 11.5, 221);
SELECT ts, device, current, voltage FROM dataout_mysql_demo.meters ORDER BY ts DESC LIMIT 5;
Record the actual ts and device of the new row, then query the target table in a MySQL client:
SELECT ts, device, `current`, voltage
FROM rdb_out.meters_out
ORDER BY ts DESC LIMIT 5;
Find the row by its recorded primary key. Confirm current=11.5 and voltage=221, and compare timestamps according to the storage mode, precision, and time zone. Write another row at a new timestamp to confirm continuous delivery. Do not rely only on total row counts or task counters.
Connectivity checks and previews do not replace verification of actual writes. Preview does not write to the target database or alter the task's consumer position. Submit and start the task, then query the target table to confirm the result.
5. DSN Example
The following source and target DSN fragments belong in a task definition; they are not standalone SQL statements. For complete task syntax, see SQL Management.
FROM 'tmq+ws://USER:PASSWORD@localhost:6041/dataout_mysql_demo?query=SELECT%20ts,%20device,%20current,%20voltage%20FROM%20dataout_mysql_demo.meters&auto.offset.reset=earliest'
TO 'mysql://USER:PASSWORD@localhost:3306/rdb_out?table=meters_out&primary_key=ts,device'
Data publishing parameters for the target DSN:
| Parameter | Description | Default |
|---|---|---|
table | Target table name, required | — |
primary_key | Primary key columns separated by commas, required | — |
create_table | Whether to create the table when it does not exist | true |
timestamp_type | auto or bigint | auto |
time_zone | local, an IANA name or an offset such as +08:00 | local |
batch_size | Maximum rows per batch | 1000 |
batch_timeout | Maximum wait before a batch is written, e.g. 1000, 500ms, 2s | 1s |
write_timeout | Timeout of one batch write | 60s |
max_retry_time | Total retry time for a recoverable error, at most 240 seconds | 180s |
6. Type Mapping
When taosX creates the table, it maps result columns as follows:
| TDengine type | MySQL type |
|---|---|
TIMESTAMP (ms, us) | DATETIME(3) / DATETIME(6) |
TIMESTAMP (ns) | BIGINT |
BOOL | TINYINT(1) |
TINYINT | TINYINT |
SMALLINT / INT / BIGINT | same name |
TINYINT UNSIGNED | TINYINT UNSIGNED |
SMALLINT UNSIGNED | SMALLINT UNSIGNED |
INT UNSIGNED | INT UNSIGNED |
BIGINT UNSIGNED | BIGINT UNSIGNED |
FLOAT / DOUBLE | FLOAT / DOUBLE |
VARCHAR / NCHAR | VARCHAR(n) or TEXT |
VARBINARY / GEOMETRY | VARBINARY(n) or BLOB |
BLOB | LONGBLOB |
JSON (tags only) | JSON |
DECIMAL / DECIMAL64 | not supported |
7. Write Semantics
taosX creates a TMQ query topic from the subscription SQL, writes batches to the target table by primary key, and commits the consumer position only after each write succeeds.
- Idempotent writes: rows are written with an UPSERT on the primary key, updating existing rows and inserting new ones. Task restarts, network interruptions and repeated delivery never create duplicate rows or stop the task with a primary key conflict.
- All columns are written: every result column of a row is written, including columns whose value is
NULL. When a column isNULLin TDengine, the target column is written asNULLtoo. - Repeated keys within one batch: only the last value is kept.
- Deletes are not propagated: data deleted in TDengine is kept in the target table.
- Tag values: tag values are read as they are in TDengine at consumption time.
8. Troubleshooting
| Symptom | Next check |
|---|---|
| Target connection fails | Check the network, port, target database existence, authentication, permissions, and TLS settings from the taosX host. |
| Preview succeeds but no new rows reach the target | Confirm the original task is running and the source has new data. Then check subscription SQL, consumer progress, and task activity. Preview itself does not write to the target. |
| Rows from different child tables overwrite one another | Check that the composite key includes device from this example and that the target constraint matches the configuration. |
| Timestamps do not match the source | Check source precision, timestamp_type, time_zone, and the target column type. Compare against the same time reference. |
| Data gaps appear after downtime | Check the source WAL retention range and warnings in task activity. Use section 10 to determine what can still be resynchronized. |
For other task, write, or runtime issues, see Troubleshoot by Symptom.
9. Stop and Resume
Stop and start the original task in the Data Out task list, keeping its subscription SQL, target table, and consumer group ID. After resuming, use section 4 to check primary keys, timestamps, and business values around the interruption. Also check task activity and write errors.
Changing the consumer group ID uses a new consumer group. Do not change it merely to resume a task. If historical data needs resynchronization, first check the retained source range as described in section 10, then decide whether to use a new group. Restarting cannot recover source data that has been deleted or expired.
10. Limitations
- One subscription SQL and one target table per task. Changing the SQL, the table, the primary key, the timestamp storage or the time zone requires a new task.
- A target table can be written by only one task and should have no other writers.
- A MySQL target table must not have unique indexes other than the primary key.
- The target table must have a primary key or unique constraint on exactly the configured primary key.
- DECIMAL output is not supported. Convert it in the subscription SQL, for example with
CAST(col AS VARCHAR(64)), which keeps the exact decimal text. - MySQL cannot store
NaNor±Inf; such values are written asNULLand counted in the metrics. - Data subject to a task stop or backlog longer than the WAL retention period of the source is skipped. taosX reports a warning in the task activity when it detects this; change the consumer group ID and restart with
earliestand TSDB Data enabled to resynchronize historical data still retained at the source. This cannot recover data deleted or expired at the source. - Topic columns are fixed at creation, so columns added to the source table later are not synchronized.
11. Performance and Observability
Task metrics include messages read, rows written, batches written, retries, write errors, elapsed time of the last write, values written as NULL because of NaN/Inf, WAL data gaps, and the consumer progress per vgroup.
Write throughput mainly depends on the target database and the row width, and can be improved by tuning the batch size and batch timeout.