Skip to content

Reads events from a MySQL database.

from_mysql [uri=string], [table=string], [sql=string], [show=string],
[live=bool], [tracking_column=string],
[host=string], [port=int], [user=string], [password=string],
[database=string], [tls=bool|record]

The from_mysql operator reads data from a MySQL database. You can query data using a table name, raw SQL, or retrieve database metadata.

The operator supports three query modes that are mutually exclusive:

  1. Table mode: Read all rows from a table using the table parameter
  2. SQL mode: Execute a custom SQL query using the sql parameter
  3. Show mode: List tables or columns using the show parameter

A MySQL connection URI in the format:

mysql://[user[:password]@]host[:port][/database]

When provided, the URI takes precedence over individual connection parameters. Credentials in the URI can be overridden by explicit user and password parameters.

The name of the table to read from. This is mutually exclusive with sql and show.

A raw SQL query to execute. This is mutually exclusive with table and show.

Use raw strings for complex queries:

from_mysql sql=r"SELECT id, name FROM users WHERE active = 1"

Retrieve database metadata. This is mutually exclusive with table and sql.

Supported values:

  • "tables": List all tables in the database
  • "columns": List all columns for the table specified in table

Enables continuous polling for new rows from a table. The operator tracks progress using a watermark on an integer column and polls every second for rows above the last-seen value. Mutually exclusive with sql and show. Requires table.

Defaults to false.

The integer column to use for watermark tracking in live mode. The operator queries for rows where this column exceeds the last-seen watermark.

When omitted, the tracking column is auto-detected from the table’s auto-increment primary key. Requires live=true.

The hostname or IP address of the MySQL server.

Defaults to "localhost".

The port number of the MySQL server.

Defaults to 3306.

The username for authentication. Supports the secret function for secure credential management.

Defaults to "root".

The password for authentication. Supports the secret function for secure credential management.

Defaults to "".

The database to connect to.

TLS configuration for the MySQL connection. Defaults to false (no TLS).

Use tls=true to enable TLS with default settings and certificate verification, or provide a record to customize specific options:

{
skip_peer_verification: bool, // skip certificate verification.
cacert: string, // CA bundle to verify peers.
certfile: string, // client certificate to present.
keyfile: string, // private key for the client certificate.
}

The operator maps MySQL types to Tenzir types as follows:

MySQL TypeTenzir TypeNotes
TINYINT(1)boolBoolean representation
TINYINT, SMALLINT, INTint64
BIGINTint64
BIGINT UNSIGNEDuint64
FLOAT, DOUBLEdouble
DECIMAL, NUMERICdoubleMay lose precision
DATE, DATETIMEtime
TIMESTAMPtime
TIMEduration
CHAR, VARCHAR, TEXTstring
BINARY, VARBINARY, BLOBblob
JSONstring
ENUMenumeration
from_mysql table="users", host="db.example.com", database="mydb"
from_mysql uri="mysql://admin:secret@db.example.com:3306/production", table="events"
from_mysql sql=r"SELECT id, name, created_at FROM users WHERE active = 1 LIMIT 100",
host="localhost", database="app"
from_mysql table="orders",
host="db.example.com",
user=secret("mysql-user"),
password=secret("mysql-password"),
database="shop"
from_mysql show="tables", host="localhost", database="mydb"
from_mysql show="columns", table="users", host="localhost", database="mydb"
from_mysql table="events",
host="db.example.com",
database="production",
tls=true

Connect with TLS but skip peer verification

Section titled “Connect with TLS but skip peer verification”
from_mysql table="events",
host="db.example.com",
database="production",
tls={skip_peer_verification: true}
from_mysql table="events",
host="db.example.com",
database="production",
tls={cacert: "/path/to/ca.pem"}
from_mysql table="events", live=true,
host="db.example.com", database="mydb"
from_mysql table="events", live=true, tracking_column="event_id",
host="db.example.com", database="mydb"

Last updated: