Skip to main content

MySQL

Connects to a MySQL or MariaDB database via the standard database/sql MySQL driver. An agent can run read-only SELECT queries, execute write/DDL statements, describe a table's columns, and list tables in the database.

Add to an agent node's tools array with _node_type: "tool-mysql". See Connector Reference — How connectors are used.

Authentication

FieldRequiredDescription
dsnYes*Full MySQL DSN, e.g. user:pass@tcp(host:3306)/db?parseTime=true. If set, all other fields below are ignored.
hostYes*Database host. Defaults to localhost if user and database are set but host is empty.
portNoDatabase port. Defaults to 3306.
userYes*Database user.
passwordNoDatabase password.
databaseYes*Database name.

* Either dsn must be set, or user and database (with optional host, port, password) must all be set to build a DSN of the form user:password@tcp(host:port)/database?parseTime=true&multiStatements=true. If neither is satisfiable, the connector returns an error.

{
"name": "mysql",
"_node_type": "tool-mysql",
"host": "db.internal",
"port": "3306",
"user": "agent",
"password": "{{ secret.MYSQL_PASSWORD }}",
"database": "app_production"
}

Tools

mysql_query

Run a SELECT query against MySQL/MariaDB and return results.

Parameters

ParameterTypeRequiredDescription
querystringYesSELECT query to execute
max_rowsnumberNoMaximum rows to return (default 100, hard cap 500)

Returns: A |-separated table: a header row of column names, a separator line, then up to max_rows data rows (NULL for null values, otherwise %v-formatted), followed by a final (N rows) count line.

mysql_execute

Execute an INSERT, UPDATE, DELETE, or DDL statement against MySQL/MariaDB.

Parameters

ParameterTypeRequiredDescription
statementstringYesINSERT UPDATE DELETE or DDL statement

Returns: OK: N rows affected, last_insert_id=<id>.

mysql_describe_table

Describe the columns of a MySQL table.

Parameters

ParameterTypeRequiredDescription
tablestringYesTable name to describe

Returns: A |-separated table — a header row from DESCRIBE `<table>` (typically Field | Type | Null | Key | Default | Extra) followed by one row per column.

mysql_list_tables

List all tables in the MySQL database.

Parameters

ParameterTypeRequiredDescription
databasestringNoDatabase to list tables for (default: current)

Returns: A newline-separated list of table names, from SHOW TABLES (or SHOW TABLES FROM `<database>` if database is set).

Next