MySQL CLI and mysqldump reference

Complete reference for MySQL client flags, mysqldump options, and common SQL administration commands.

Complete reference for MySQL command-line client connection flags, mysqldump backup options, and essential SQL administration commands.

MySQL Client Connection Flags

FlagMySQL client behaviorDefaultExample
-u {user}MySQL connects as the specified usernameCurrent OS usermysql -u root
-pMySQL prompts for the password interactivelyNo passwordmysql -u root -p
-h {host}MySQL connects to the specified hostname or IP addresslocalhostmysql -h 203.0.113.50
-P {port}MySQL connects to the specified TCP port3306mysql -P 3307
--socket {path}MySQL connects through the specified Unix socket file/var/run/mysqld/mysqld.sockmysql --socket=/tmp/mysql.sock
-e "{query}"MySQL executes the specified SQL query and exits without entering interactive modeInteractive modemysql -u root -p -e "SHOW DATABASES;"
--skip-column-namesMySQL omits column headers from query output, useful for scriptingHeaders shownmysql -u root -p -e "SELECT user FROM mysql.user;" --skip-column-names

mysqldump Backup Flags

Flagmysqldump behaviorDefaultExample
--all-databasesmysqldump exports every database on the serverSingle databasemysqldump --all-databases > all.sql
--single-transactionmysqldump uses a consistent snapshot for InnoDB tables without lockingTable locksmysqldump --single-transaction myapp > backup.sql
--routinesmysqldump includes stored procedures and functions in the exportExcludedmysqldump --routines myapp > backup.sql
--triggersmysqldump includes triggers in the exportIncludedmysqldump --triggers myapp > backup.sql
--no-datamysqldump exports only the schema (CREATE TABLE) without row dataData includedmysqldump --no-data myapp > schema.sql
--add-drop-tablemysqldump adds DROP TABLE statements before each CREATE TABLEIncludedmysqldump --add-drop-table myapp > backup.sql
--compressmysqldump compresses data during transfer between client and server (not the output file)Uncompressedmysqldump --compress myapp > backup.sql