mysql Command Reference: Flags, Usage & CI Examples
mysql runs SQL against a MySQL or MariaDB server from the shell.
mysql connects to a MySQL/MariaDB server and runs SQL interactively, from -e, or from a piped file. In CI it seeds databases and runs migrations against a service container.
Common flags and usage
- -h <host>: server host (use 127.0.0.1 to force TCP)
- -P <port>: server port (uppercase; default 3306)
- -u <user>: connect as this user
- -p[password]: password attached with no space (or set MYSQL_PWD)
- -e "SQL": run one statement and exit
- -N -B: header-free, tab-separated output for capture
Example
shell
MYSQL_PWD=${MYSQL_PWD} mysql -h 127.0.0.1 -P 3306 -u root app < schema.sql
MYSQL_PWD=${MYSQL_PWD} mysql -h 127.0.0.1 -u root -N -B -e 'SELECT 1' appIn CI
Use -h 127.0.0.1 (not localhost) to force TCP to the service container instead of a missing Unix socket. Supply the password via MYSQL_PWD or attached to -p with no space; a space after -p is a common "Access denied" cause.
Key takeaways
- mysql runs SQL interactively, via -e, or from a piped file.
- Force TCP with -h 127.0.0.1 to reach a CI service container.
- Pass the password via MYSQL_PWD or attached to -p, never spaced.
Related guides
mysqldump Command Reference: Flags, Usage & CI ExamplesReference for mysqldump: --single-transaction, --databases, --no-data, --routines, and a CI example that expo…
mysqladmin Command Reference: Commands, Usage & CI ExamplesReference for mysqladmin: ping, status, create, --wait, --silent, and a CI wait loop that blocks until a MySQ…
psql Command Reference: Flags, Usage & CI ExamplesReference for the psql PostgreSQL client: connection flags, -c and -f, PGPASSWORD, ON_ERROR_STOP, and a CI ex…