Skip to main content

MySQL

MySQL is supported as a production database in the Commercial edition.

Supported versions

MySQL 8.0 and later.

Configuration

db:
dsn: "mysql://talos:secret@tcp(db:3306)/talos?tls=true&parseTime=true"

Or via environment variable:

export TALOS_DB_DSN="mysql://talos:secret@tcp(db:3306)/talos?tls=true&parseTime=true"

DSN format

mysql://user:password@tcp(host:port)/dbname?param=value&param=value

The mysql:// scheme prefix is required in the configuration. Talos strips it internally before passing the DSN to the Go MySQL driver.

caution

Required parameter: always include parseTime=true in the DSN. Without it, datetime columns are returned as byte arrays instead of time.Time, causing runtime errors.

DSN parameters

Connection pool parameters

Pool parameters are parsed from the DSN query string and removed before the DSN is passed to the database driver.

ParameterTypeDefaultDescription
max_connsinteger25Maximum number of open connections in the pool
max_idle_connsinteger5Maximum number of idle connections (must be ≤ max_conns)
max_conn_lifetimeduration30mMaximum age of a connection before it is closed and replaced
max_conn_idle_timeduration10mMaximum time a connection can sit idle before it is closed

Duration values use Go duration syntax: 5m (5 minutes), 1h (1 hour), 30s (30 seconds).

Talos sets non-zero defaults for max_conn_lifetime and max_conn_idle_time so connections are recycled through load balancers and DNS rotation. Setting either to 0 disables the recycle and is not recommended outside development.

MySQL uses standard database/sql pooling only. There is no advanced pool mode.

MySQL driver parameters

These parameters are passed through to the underlying Go MySQL driver.

ParameterDescriptionRequired
parseTimeParse DATETIME columns to time.TimeYes — always set to true
tlsTLS mode (true, skip-verify, custom)Recommended for production
charsetCharacter setDefaults to utf8mb4
collationCollationDefaults to utf8mb4_general_ci
locTimezone for time.Time valuesDefaults to UTC
timeoutConnection timeout (e.g., 10s)
readTimeoutRead timeout (e.g., 30s)
writeTimeoutWrite timeout (e.g., 30s)
multiStatementsAllow multiple statements per queryDo not enable

Connection pooling

MySQL uses Go's database/sql connection pool with the go-sql-driver/mysql driver.

db:
dsn: "mysql://talos:secret@tcp(db:3306)/talos?parseTime=true&max_conns=25&max_idle_conns=5&max_conn_lifetime=5m&max_conn_idle_time=1m"

Pool behavior:

  • Connections are created on demand up to max_conns
  • Idle connections are kept up to max_idle_conns
  • Connections older than max_conn_lifetime are closed and replaced
  • Connections idle longer than max_conn_idle_time are closed

Pool sizing

Start with 25 connections per instance. The total pool across all instances should stay below MySQL's max_connections (default: 151).

Deploymentmax_connsNotes
Single instance25Good starting point
3 instances25 each75 total — within default max_connections
5+ instances1520 eachUse ProxySQL or MySQL Router to multiplex

For large deployments, place ProxySQL or MySQL Router between Talos and MySQL for connection multiplexing.

Database preparation

CREATE DATABASE talos CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'talos'@'%' IDENTIFIED BY 'secret';
GRANT ALL PRIVILEGES ON talos.* TO 'talos'@'%';

Migrations

talos-commercial migrate up --database "mysql://talos:secret@tcp(db:3306)/talos?parseTime=true"

TLS / SSL

Use TLS parameters in the DSN for encrypted database connections:

db:
dsn: "mysql://talos:secret@tcp(db:3306)/talos?parseTime=true&tls=true"
ParameterDescription
tls=trueEnable TLS with default settings
tls=skip-verifyTLS without certificate verification
tls=customUse custom TLS configuration registered with mysql.RegisterTLSConfig

Example DSNs

Development:

mysql://talos:secret@tcp(localhost:3306)/talos?parseTime=true

Production with pooling:

mysql://talos:secret@tcp(db:3306)/talos?parseTime=true&tls=true&max_conns=25&max_idle_conns=5&max_conn_lifetime=5m&max_conn_idle_time=1m

With timeouts:

mysql://talos:secret@tcp(db:3306)/talos?parseTime=true&tls=true&timeout=10s&readTimeout=30s&writeTimeout=30s&max_conns=25