MySQL table function

BETA

The Tinybird mysql() table function is currently in private beta. If you're interested in early access, reach out to support.

The Tinybird mysql() table function allows you to read data from your existing MySQL database into Tinybird, then schedule a regular copy pipe to orchestrate synchronization. You can load full tables, and every run performs a full replace on the data source.

To use it, define a node using standard SQL and the mysql function keyword, then publish the node as a copy pipe that does a sync on every run. See Table functions for general information and tips.

Setting secrets

Table functions require authentication credentials (such as AWS keys) that must be stored securely. Tinybird provides different methods for managing secrets depending on the version you're using.

Using the Variables API (Classic)

In Tinybird Classic, you must set your credentials using the Environment Variables API:

curl -X POST -H "Authorization: Bearer $TOKEN" \
  --data-urlencode "name=my_username" \
  --data-urlencode "value=mysql_user" \
  https://<TB_HOST_URL>/v0/variables/

For more details, see the Environment Variables API documentation.

Using the CLI (Forward)

In Tinybird Forward, you manage secrets using the tb secret command:

tb secret set my_username mysql_user
tb secret set my_password your_password

For more details, see the tb secret command documentation.

Once you've set up your secrets, you can reference them in your SQL with the tb_secret function as shown in the Syntax section below.

Syntax

Create a new pipe node. Call the mysql table function and pass the hostname and port, database, table, user, and password:

Example query logic
SELECT *
FROM mysql(
  'aws-0-eu-central-1.TODO.com:3866',
  'mysql',
  'orders',
  {{tb_secret('my_username')}},
  {{tb_secret('my_password')}}
)

Publish this node as a copy pipe. You can choose to append only new data or replace all data.

Type support and inference

Here's a detailed conversion table:

MySQL data typeTinybird data type
UNSIGNED TINYINTUInt8
TINYINTInt8
UNSIGNED SMALLINTUInt16
SMALLINTInt16
UNSIGNED INT, UNSIGNED MEDIUMINTUInt32
INT, MEDIUMINTInt32
UNSIGNED BIGINTUInt64
BIGINTInt64
FLOATFloat32
DOUBLEFloat64
DATEDate
DATETIME, TIMESTAMPDateTime
BINARYFixedString

Considerations

The following considerations apply to the mysql() table function:

  • Tinybird doesn't support all MySQL types directly, so some types are mapped to String, which is the most flexible type for arbitrary data.
  • Time zone support in Tinybird's DateTime can be managed via additional functions or by ensuring consistent storage and retrieval time zones.

See also

Updated