Directory Compare FCRS-1.0 /llms.txt
← Back to Directory

MySQL CLI

$ mysql Official High Risk
Oracle · Database & Data · GPL-2.0 · macos / linux / windows

The classic mysql client executes SQL queries and .sql dumps against MySQL and MariaDB servers. Supports non-interactive -e execution, --batch (-B) tab-separated output, and --init-command session settings, though it lacks native JSON output.

FCRS-1.0 Score
77 /100
Good
High Confidence
Zero-Friction Install
brew install mysql-client
CLI vs MCP Decision CLI Preferred vs MCP

mysql --batch --raw -e "..." is fast and universally available on servers; wrap results with JSON_ARRAYAGG(JSON_OBJECT(...)) or pipe TSV through mlr.

Agent-Readiness Checklist

Local Probe Evidence
— JSON Output
— Field Filtering
✓ Non-Interactive
— Dry-Run
— Read-Only Mode
— NO_COLOR Clean
✓ Self-Describing
— Official SKILL.md
Version
mysql Ver 9.3.0 for macos15.2 on arm64 (Homebrew)
Startup
66 ms
Exit Codes (help / invalid)
0 / 2
NO_COLOR Clean / Non-TTY Safe
Yes / Safe
Captured --help excerpt
mysql  Ver 9.3.0 for macos15.2 on arm64 (Homebrew)
Copyright (c) 2000, 2025, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --auto-rehash       Enable automatic rehashing. One doesn't need to use
                      'rehash' to get table and field completion, but startup
                      and reconnecting may take a longer time. Disable with
                      --disable-auto-rehash.
                      (Defaults to on; use --skip-auto-rehash to disable.)
  -A, --no-auto-rehash 
                      No automatic rehashing. One has to use 'rehash' to get
                      table and field completion. This gives a quicker start of
                      mysql and disables rehashing on reconnect.
  --auto-vertical-output 
                      Automatically switch to vertical output mode if the
                      result is wider than the terminal width.
  -B, --batch         Don't use history file. Disable interactive behavior.
                      (Enables --silent.)
  --bind-address=name IP address to bind to.
  --binary-as-hex     Print binary data as hex. Enabled by default for
                      interactive terminals.
  --character-sets-dir=name 
                      Directory for character set files.
  --column-type-info  Display column type information.
  -c, --comments      Preserve comments. Send comments to the server. The
                      default is --comments (keep comments), disable with
                      --skip-comments.
                      (Defaults to on; use --skip-comments to disable.)
  -C, --compress      Use compression in server/client protocol.
  -#, --debug[=#]     This is a non-debug version. Catch this and exit.
  --debug-check       This is a non-debug version. Catch this and exit.
  -T, --debug-info    This is a non-debug version. Catch this and exit.
  -D, --database=name Database to use.
  --default-character-set=name 
                      Set the default character set.
  --delimiter=name    Delimiter to be used.
  --enable-cleartext-plugin 
                      Enable/disable the clear text authentication plugin.
  -e, --execute=name  Execute command and quit. (Disables --force and history
                      file.)
  -E, --vertical      Print the output

FCRS-1.0 6-Dimension Breakdown

Agent-Readiness 17 / 25

Supports -e, --batch, -N, and --xml, but lacks native --json output and has legacy credential-passing quirks.

  • Supports -e, --batch, -N; no native --json output
Trust & Safety 18 / 25

Supports --init-command="SET SESSION TRANSACTION READ ONLY;", though --safe-updates (-U) is off by default and -p flags leak secrets in ps.

  • Server-side read-only via --init-command; -p leaks passwords in argv
Setup & Portability 13 / 15

Widely packaged (mysql-client, mariadb-client) across Linux, macOS, and Windows.

  • Standard mysql-client package across OSes
Utility & Efficiency 13 / 15

Canonical fast C/C++ client for MySQL/MariaDB queries and SQL file imports.

  • Native wire-protocol performance for queries and batch scripts
Maintenance & Lineage 9 / 10

Official Oracle mysql/mysql-server client maintained continuously.

  • Official Oracle MySQL client
Docs & Verifiability 7 / 10

Detailed reference manual at dev.mysql.com, though MariaDB vs MySQL 8 flag differences exist.

  • Official MySQL Reference Manual

Security, Auth & Guardrails

Auth Modes
Config File Env API Key
Credential Storage

Connection profiles stored in ~/.my.cnf or --defaults-extra-file; password via MYSQL_PWD (discouraged) or login-path ~/.mylogin.cnf.

Side Effects
Read-Only Local Write Remote Write Destructive
Cost & Quotas

100% free and GPL-2.0 open-source.

Copyable Guardrail for CLAUDE.md / AGENTS.md
# MySQL CLI Agent Rules
- Always pass `-e "<sql>"` and `--batch` (`-B`); never start interactive `mysql` shell.
- Prefix read queries with `--init-command="SET SESSION TRANSACTION READ ONLY;"`.
- Use `--defaults-extra-file` or `~/.mylogin.cnf` instead of `-p<password>` on the command line.

Agent-Ready Command Recipes

Safe Read-Only Queries

Execute a read-only batch query in TSV
mysql --defaults-extra-file=.my.cnf --batch --init-command="SET SESSION TRANSACTION READ ONLY;" -e "SHOW TABLES;"

Forces a read-only session on the server and returns tab-delimited rows cleanly.

Return MySQL query rows as JSON via SQL
mysql --defaults-extra-file=.my.cnf --batch -N -e "SELECT JSON_OBJECT('id', id, 'name', name) FROM users LIMIT 10;"

Suppresses column headers (-N) and emits one JSON object per line (NDJSON).

Strengths for Agents

  • + --batch -N -e produces clean headerless TSV or NDJSON when paired with JSON_OBJECT().
  • + --init-command="SET SESSION TRANSACTION READ ONLY;" prevents accidental mutations.
  • + Available natively in almost every Linux/Docker environment.

Caveats & Pitfalls

  • ! No built-in --json output flag (only --xml and --html alongside TSV/table).
  • ! Passing -p<secret> in CLI arguments exposes credentials in process lists.

Tested Agent Hosts

Claude Code Codex CLI Gemini CLI