Skip to main content

MySQL

The mysql collector will validate and add information about a MySQL server to a support bundle. The collector uses the network of the process running the support bundle CLI.

  • Inside a pod: requests use cluster networking, and in-cluster DNS (e.g. *.svc.cluster.local) resolves.
  • Outside the cluster (CI runners, local machines): requests use the host network, and in-cluster DNS names will not resolve.

To check connectivity to an in-cluster service, run the check from inside the cluster. See Run this check inside the cluster below.

Parameters

The mysql collector has the following parameters:

The name of the collector. This is recommended to set to a string identifying the MySQL instance, and can be used to refer to this collector in analyzers and preflight checks. If unset, this will be set to the string "mysql".

uri (Required)

The connection URI to use when connecting to the MySQL server.

parameters (Optional)

A list of variables to return as a result of the SHOW VARIABLES query.

Example Collector Definition

apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
metadata:
name: sample
spec:
collectors:
- mysql:
collectorName: mysql
uri: 'testuser:password@tcp(mysql:3306)/dbname?tls=false'
parameters:
- character_set_server
- collation_server
- init_connect
- innodb_file_format
- innodb_large_prefix
- innodb_strict_mode
- log_bin_trust_function_creators

Run this check inside the cluster

By default the mysql collector uses the network of the process running the CLI (see above). To run the connection check from inside the cluster, run it as a Pod using the runPod collector with the Troubleshoot image (proxy.replicated.com/library/troubleshoot, v0.131.0 or later) and the collect mysql subcommand. The Pod runs the collector from within the cluster and prints the same result JSON to its logs, which you evaluate with textAnalyze:

collectors:
- runPod:
name: mysql-check
namespace: default
podSpec:
restartPolicy: Never
containers:
- name: check
image: proxy.replicated.com/library/troubleshoot:v0.131.0
command: ["collect", "mysql", "--uri", "user:pass@tcp(my-db.default.svc.cluster.local:3306)/app"]
analyzers:
- textAnalyze:
checkName: MySQL reachable
collectorName: mysql-check
fileName: "*.log"
regex: '"isConnected": *true'
outcomes:
- pass:
when: "true"
message: "Connected to MySQL from inside the cluster."
- fail:
when: "false"
message: "Could not connect to MySQL from inside the cluster."

Note that --uri is a Go MySQL driver DSN (user:pass@tcp(host:3306)/db), not a URL. In addition to --uri (required) and the TLS flags (--tls-cacert, --tls-client-cert, --tls-client-key, --tls-skip-verify, --tls-secret-name, --tls-secret-namespace), collect mysql accepts --parameters to collect server variables via SHOW VARIABLES (returned under variables in the result).

Included resources

A single JSON file will be added to the support bundle, in the path /mysql/[collector-name].json:

{
"isConnected": false,
"error": "invalid password",
"version": "5.6.49",
"variables": {
"character_set_server": "utf8mb4",
"collation_server": "utf8mb4_0900_ai_ci",
"init_connect": "",
"innodb_strict_mode": "ON",
"log_bin_trust_function_creators": "OFF"
}
}

Fields

isConnected

a boolean indicating if the collector was able to connect and authenticate using the connection string provided.

error

a string that indicates the connection error, if there was one

version

when connected, a string indicating the version of MySQL that's running

variables

A filtered list of variables returned from the SHOW VARIABLES query.