MySQL CLI
$ mysql Official High RiskThe 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.
brew install mysql-client 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 EvidenceCaptured --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
Supports -e, --batch, -N, and --xml, but lacks native --json output and has legacy credential-passing quirks.
- Supports
-e,--batch,-N; no native--jsonoutput
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;-pleaks passwords in argv
Widely packaged (mysql-client, mariadb-client) across Linux, macOS, and Windows.
- Standard
mysql-clientpackage across OSes
Canonical fast C/C++ client for MySQL/MariaDB queries and SQL file imports.
- Native wire-protocol performance for queries and batch scripts
Official Oracle mysql/mysql-server client maintained continuously.
- Official Oracle MySQL client
Detailed reference manual at dev.mysql.com, though MariaDB vs MySQL 8 flag differences exist.
- Official MySQL Reference Manual
Security, Auth & Guardrails
Connection profiles stored in ~/.my.cnf or --defaults-extra-file; password via MYSQL_PWD (discouraged) or login-path ~/.mylogin.cnf.
100% free and GPL-2.0 open-source.
# 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
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.
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 -eproduces clean headerless TSV or NDJSON when paired withJSON_OBJECT(). - +
--init-command="SET SESSION TRANSACTION READ ONLY;"prevents accidental mutations. - + Available natively in almost every Linux/Docker environment.
Caveats & Pitfalls
- ! No built-in
--jsonoutput flag (only--xmland--htmlalongside TSV/table). - ! Passing
-p<secret>in CLI arguments exposes credentials in process lists.