Linux "mysql" Command Line Options and Examples
the MySQL command-line client

mysql is a simple SQL shell with input line editing capabilities. It supports interactive and noninteractive use. When used interactively, query results are presented in an ASCII-table format.


Usage:

mysql [options] db_name




Command Line Options:

--help
Display a help message and exit.
mysql --help ...
--auto-rehash
Enable automatic rehashing. This option is on by default, which enables database, table, and column name completion. Use
mysql --auto-rehash ...
--auto-vertical-output
Cause result sets to be displayed vertically if they are too wide for the current window, and using normal tabular formatotherwise. (This applies to statements terminated by ; or \G.)
mysql --auto-vertical-output ...
--batch
Print results using tab as the column separator, with each row on a new line. With this option, mysql does not use the historyfile.Batch mode results in nontabular output format and escaping of special characters. Escaping may be disabled by using raw mode;see the description for the --raw option.
mysql --batch ...
--binary-as-hex
When this option is given, mysql displays binary data using hexadecimal notation (0xvalue). This occurs whether the overalloutput dislay format is tabular, vertical, HTML, or XML.
mysql --binary-as-hex ...
--binary-mode
This option helps when processing mysqlbinlog output that may contain BLOB values. By default, mysql translates \r\n in statementstrings to \n and interprets \0 as the statement terminator. --binary-mode disables both features. It also disables all mysqlcommands except charset and delimiter in noninteractive mode (for input piped to mysql or loaded using the source command).
mysql --binary-mode ...
--bind-address
On a computer having multiple network interfaces, use this option to select which interface to use for connecting to the MySQLserver.
mysql --bind-address ...
--character-sets-dir
The directory where character sets are installed. See Section 10.15, “Character Set Configuration”.
mysql --character-sets-dir ...
--column-names
Write column names in results.
mysql --column-names ...
--column-type-info
Display result set metadata.
mysql --column-type-info ...
--comments
Whether to strip or preserve comments in statements sent to the server. The default is --skip-comments (strip comments), enablewith --comments (preserve comments).NoteThe mysql client always passes optimizer hints to the server, regardless of whether this option is given.Comment stripping is deprecated. This feature and the options to control it will be removed in a future MySQL release.
mysql --comments ...
--compress
Compress all information sent between the client and the server if possible. See Section 4.2.6, “Connection Compression Control”.As of MySQL 8.0.18, this option is deprecated. It will be removed in a future MySQL version. See the section called “LegacyConnection Compression Configuration”.
mysql --compress ...
--connect-expired-password
Indicate to the server that the client can handle sandbox mode if the account used to connect has an expired password. This canbe useful for noninteractive invocations of mysql because normally the server disconnects noninteractive clients that attempt toconnect using an account with an expired password. (See Section 6.2.16, “Server Handling of Expired Passwords”.)
mysql --connect-expired-password ...
--connect-timeout
The number of seconds before connection timeout. (Default value is 0.)
mysql --connect-timeout ...
--database
The database to use. This is useful primarily in an option file.
mysql --database ...
--debug[
Write a debugging log. A typical debug_options string is d:t:o,file_name. The default is d:t:o,/tmp/mysql.trace.This option is available only if MySQL was built using WITH_DEBUG. MySQL release binaries provided by Oracle are not built usingthis option.
mysql --debug[ ...
--debug-check
Print some debugging information when the program exits.
mysql --debug-check ...
--debug-info
Print debugging information and memory and CPU usage statistics when the program exits.
mysql --debug-info ...
--default-auth
A hint about which client-side authentication plugin to use. See Section 6.2.17, “Pluggable Authentication”.
mysql --default-auth ...
--default-character-set
Use charset_name as the default character set for the client and connection.This option can be useful if the operating system uses one character set and the mysql client by default uses another. In thiscase, output may be formatted incorrectly. You can usually fix such issues by using this option to force the client to use thesystem character set instead.For more information, see Section 10.4, “Connection Character Sets and Collations”, and Section 10.15, “Character SetConfiguration”.
mysql --default-character-set ...
--defaults-extra-file
Read this option file after the global option file but (on Unix) before the user option file. If the file does not exist or isotherwise inaccessible, an error occurs. file_name is interpreted relative to the current directory if given as a relative pathname rather than a full path name.For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that AffectOption-File Handling”.
mysql --defaults-extra-file ...
--defaults-file
Use only the given option file. If the file does not exist or is otherwise inaccessible, an error occurs. file_name isinterpreted relative to the current directory if given as a relative path name rather than a full path name.Exception: Even with --defaults-file, client programs read .mylogin.cnf.For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that AffectOption-File Handling”.
mysql --defaults-file ...
--defaults-group-suffix
Read not only the usual option groups, but also groups with the usual names and a suffix of str. For example, mysql normallyreads the [client] and [mysql] groups. If the --defaults-group-suffix=_other option is given, mysql also reads the [client_other]and [mysql_other] groups.For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that AffectOption-File Handling”.
mysql --defaults-group-suffix ...
--delimiter
Set the statement delimiter. The default is the semicolon character (;).
mysql --delimiter ...
--disable-named-commands
Disable named commands. Use the \* form only, or use named commands only at the beginning of a line ending with a semicolon (;).mysql starts with this option enabled by default. However, even with this option, long-format commands still work from the firstline. See the section called “MYSQL CLIENT COMMANDS”.
mysql --disable-named-commands ...
--enable-cleartext-plugin
Enable the mysql_clear_password cleartext authentication plugin. (See Section 6.4.1.4, “Client-Side Cleartext PluggableAuthentication”.)
mysql --enable-cleartext-plugin ...
--execute
Execute the statement and quit. The default output format is like that produced with --batch. See Section 4.2.2.1, “Using Optionson the Command Line”, for some examples. With this option, mysql does not use the history file.
mysql --execute ...
--force
Continue even if an SQL error occurs.
mysql --force ...
--get-server-public-key
Request from the server the public key required for RSA key pair-based password exchange. This option applies to clients thatauthenticate with the caching_sha2_password authentication plugin. For that plugin, the server does not send the public keyunless requested. This option is ignored for accounts that do not authenticate with that plugin. It is also ignored if RSA-basedpassword exchange is not used, as is the case when the client connects to the server using a secure connection.If --server-public-key-path=file_name is given and specifies a valid public key file, it takes precedence over
mysql --get-server-public-key ...
--get-server-public-key.
For information about the caching_sha2_password plugin, see Section 6.4.1.3, “Caching SHA-2 Pluggable Authentication”.
mysql --get-server-public-key. ...
--histignore
A list of one or more colon-separated patterns specifying statements to ignore for logging purposes. These patterns are added tothe default pattern list ("*IDENTIFIED*:*PASSWORD*"). The value specified for this option affects logging of statements writtento the history file, and to syslog if the --syslog option is given. For more information, see the section called “MYSQL CLIENTLOGGING”.
mysql --histignore ...
--host
Connect to the MySQL server on the given host.
mysql --host ...
--html
Produce HTML output.
mysql --html ...
--ignore-spaces
Ignore spaces after function names. The effect of this is described in the discussion for the IGNORE_SPACE SQL mode (seeSection 5.1.11, “Server SQL Modes”).
mysql --ignore-spaces ...
--init-command
SQL statement to execute after connecting to the server. If auto-reconnect is enabled, the statement is executed again afterreconnection occurs.
mysql --init-command ...
--line-numbers
Write line numbers for errors. Disable this with --skip-line-numbers.
mysql --line-numbers ...
--local-infile[
Enable or disable LOCAL capability for LOAD DATA. For mysql, this capability is disabled by default. With no value, the optionenables LOCAL. The option may be given as --local-infile=0 or --local-infile=1 to explicitly disable or enable LOCAL. Enablinglocal data loading also requires that the server permits it; see Section 6.1.6, “Security Issues with LOAD DATA LOCAL”
mysql --local-infile[ ...
--login-path
Read options from the named login path in the .mylogin.cnf login path file. A “login path” is an option group containing optionsthat specify which MySQL server to connect to and which account to authenticate as. To create or modify a login path file, usethe mysql_config_editor utility. See mysql_config_editor(1).For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that AffectOption-File Handling”.
mysql --login-path ...
--max-join-size
The automatic limit for rows in a join when using --safe-updates. (Default value is 1,000,000.)
mysql --max-join-size ...
--named-commands
Enable named mysql commands. Long-format commands are permitted, not just short-format commands. For example, quit and \q bothare recognized. Use --skip-named-commands to disable named commands. See the section called “MYSQL CLIENT COMMANDS”.
mysql --named-commands ...
--net-buffer-length
The buffer size for TCP/IP and socket communication. (Default value is 16KB.)
mysql --net-buffer-length ...
--no-auto-rehash
This has the same effect as --skip-auto-rehash. See the description for --auto-rehash.
mysql --no-auto-rehash ...
--no-beep
Do not beep when errors occur.
mysql --no-beep ...
--no-defaults
Do not read any option files. If program startup fails due to reading unknown options from an option file, --no-defaults can beused to prevent them from being read.The exception is that the .mylogin.cnf file, if it exists, is read in all cases. This permits passwords to be specified in asafer way than on the command line even when --no-defaults is used. (.mylogin.cnf is created by the mysql_config_editor utility.See mysql_config_editor(1).)For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that AffectOption-File Handling”.
mysql --no-defaults ...
--one-database
Ignore statements except those that occur while the default database is the one named on the command line. This option isrudimentary and should be used with care. Statement filtering is based only on USE statements.Initially, mysql executes statements in the input because specifying a database db_name on the command line is equivalent toinserting USE db_name at the beginning of the input. Then, for each USE statement encountered, mysql accepts or rejects followingstatements depending on whether the database named is the one on the command line. The content of the statements is immaterial.Suppose that mysql is invoked to process this set of statements:DELETE FROM db2.t2;USE db2;DROP TABLE db1.t1;CREATE TABLE db1.t1 (i INT);USE db1;INSERT INTO t1 (i) VALUES(1);CREATE TABLE db2.t1 (j INT);If the command line is mysql --force --one-database db1, mysql handles the input as follows:· The DELETE statement is executed because the default database is db1, even though the statement names a table in a differentdatabase.· The DROP TABLE and CREATE TABLE statements are not executed because the default database is not db1, even though thestatements name a table in db1.· The INSERT and CREATE TABLE statements are executed because the default database is db1, even though the CREATE TABLEstatement names a table in a different database.
mysql --one-database ...
--pager[
Use the given command for paging query output. If the command is omitted, the default pager is the value of your PAGERenvironment variable. Valid pagers are less, more, cat [> filename], and so forth. This option works only on Unix and only ininteractive mode. To disable paging, use --skip-pager. the section called “MYSQL CLIENT COMMANDS”, discusses output pagingfurther.
mysql --pager[ ...
--password[
The password of the MySQL account used for connecting to the server. The password value is optional. If not given, mysql promptsfor one. If given, there must be no space between --password= or -p and the password following it. If no password option isspecified, the default is to send no password.Specifying a password on the command line should be considered insecure. To avoid giving the password on the command line, use anoption file. See Section 6.1.2.1, “End-User Guidelines for Password Security”.To explicitly specify that there is no password and that mysql should not prompt for one, use the --skip-password option.
mysql --password[ ...
--pipe
On Windows, connect to the server using a named pipe. This option applies only if the server was started with the named_pipesystem variable enabled to support named-pipe connections. In addition, the user making the connection must be a member of theWindows group specified by the named_pipe_full_access_group system variable.
mysql --pipe ...
--plugin-dir
The directory in which to look for plugins. Specify this option if the --default-auth option is used to specify an authenticationplugin but mysql does not find it. See Section 6.2.17, “Pluggable Authentication”.
mysql --plugin-dir ...
--port
For TCP/IP connections, the port number to use.
mysql --port ...
--print-defaults
Print the program name and all options that it gets from option files.For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that AffectOption-File Handling”.
mysql --print-defaults ...
--prompt
Set the prompt to the specified format. The default is mysql>. The special sequences that the prompt can contain are described inthe section called “MYSQL CLIENT COMMANDS”.
mysql --prompt ...
--protocol
The connection protocol to use for connecting to the server. It is useful when the other connection parameters normally result inuse of a protocol other than the one you want. For details on the permissible values, see Section 4.2.4, “Connecting to the MySQLServer Using Command Options”.
mysql --protocol ...
--quick
Do not cache each query result, print each row as it is received. This may slow down the server if the output is suspended. Withthis option, mysql does not use the history file.
mysql --quick ...
--raw
For tabular output, the “boxing” around columns enables one column value to be distinguished from another. For nontabular output(such as is produced in batch mode or when the --batch or --silent option is given), special characters are escaped in the outputso they can be identified easily. Newline, tab, NUL, and backslash are written as \n, \t, \0, and \\. The --raw option disablesthis character escaping.The following example demonstrates tabular versus nontabular output and the use of raw mode to disable escaping:% mysqlmysql> SELECT CHAR(92);
mysql --raw ...
--reconnect
If the connection to the server is lost, automatically try to reconnect. A single reconnect attempt is made each time theconnection is lost. To suppress reconnection behavior, use --skip-reconnect.
mysql --reconnect ...
--safe-updates
If this option is enabled, UPDATE and DELETE statements that do not use a key in the WHERE clause or a LIMIT clause produce anerror. In addition, restrictions are placed on SELECT statements that produce (or are estimated to produce) very large resultsets. If you have set this option in an option file, you can use --skip-safe-updates on the command line to override it. For moreinformation about this option, see Using Safe-Updates Mode (--safe-updates).
mysql --safe-updates ...
--secure-auth
This option was removed in MySQL 8.0.3.
mysql --secure-auth ...
--select-limit
The automatic limit for SELECT statements when using --safe-updates. (Default value is 1,000.)
mysql --select-limit ...
--server-public-key-path
The path name to a file containing a client-side copy of the public key required by the server for RSA key pair-based passwordexchange. The file must be in PEM format. This option applies to clients that authenticate with the sha256_password orcaching_sha2_password authentication plugin. This option is ignored for accounts that do not authenticate with one of thoseplugins. It is also ignored if RSA-based password exchange is not used, as is the case when the client connects to the serverusing a secure connection.If --server-public-key-path=file_name is given and specifies a valid public key file, it takes precedence over
mysql --server-public-key-path ...
--shared-memory-base-name
On Windows, the shared-memory name to use for connections made using shared memory to a local server. The default value is MYSQL.The shared-memory name is case-sensitive.This option applies only if the server was started with the shared_memory system variable enabled to support shared-memoryconnections.
mysql --shared-memory-base-name ...
--show-warnings
Cause warnings to be shown after each statement if there are any. This option applies to interactive and batch mode.
mysql --show-warnings ...
--sigint-ignore
Ignore SIGINT signals (typically the result of typing Control+C).
mysql --sigint-ignore ...
--silent
Silent mode. Produce less output. This option can be given multiple times to produce less and less output.This option results in nontabular output format and escaping of special characters. Escaping may be disabled by using raw mode;see the description for the --raw option.
mysql --silent ...
--skip-column-names
Do not write column names in results.
mysql --skip-column-names ...
--skip-line-numbers
Do not write line numbers for errors. Useful when you want to compare result files that include error messages.
mysql --skip-line-numbers ...
--socket
For connections to localhost, the Unix socket file to use, or, on Windows, the name of the named pipe to use.On Windows, this option applies only if the server was started with the named_pipe system variable enabled to support named-pipeconnections. In addition, the user making the connection must be a member of the Windows group specified by thenamed_pipe_full_access_group system variable.
mysql --socket ...
--ssl*
Options that begin with --ssl specify whether to connect to the server using SSL and indicate where to find SSL keys andcertificates. See the section called “Command Options for Encrypted Connections”.
mysql --ssl* ...
--syslog
This option causes mysql to send interactive statements to the system logging facility. On Unix, this is syslog; on Windows, itis the Windows Event Log. The destination where logged messages appear is system dependent. On Linux, the destination is oftenthe /var/log/messages file.Here is a sample of output generated on Linux by using --syslog. This output is formatted for readability; each logged messageactually takes a single line.Mar 7 12:39:25 myhost MysqlClient[20824]:SYSTEM_USER:'oscar', MYSQL_USER:'my_oscar', CONNECTION_ID:23,DB_SERVER:'127.0.0.1', DB:'--', QUERY:'USE test;'Mar 7 12:39:28 myhost MysqlClient[20824]:SYSTEM_USER:'oscar', MYSQL_USER:'my_oscar', CONNECTION_ID:23,DB_SERVER:'127.0.0.1', DB:'test', QUERY:'SHOW TABLES;'For more information, see the section called “MYSQL CLIENT LOGGING”.
mysql --syslog ...
--table
Display output in table format. This is the default for interactive use, but can be used to produce table output in batch mode.
mysql --table ...
--tee
Append a copy of output to the given file. This option works only in interactive mode. the section called “MYSQL CLIENTCOMMANDS”, discusses tee files further.
mysql --tee ...
--tls-ciphersuites
The permissible ciphersuites for encrypted connections that use TLSv1.3. The value is a list of one or more colon-separatedciphersuite names. The ciphersuites that can be named for this option depend on the SSL library used to compile MySQL. Fordetails, see Section 6.3.2, “Encrypted Connection TLS Protocols and Ciphers”.This option was added in MySQL 8.0.16.
mysql --tls-ciphersuites ...
--tls-version
The permissible TLS protocols for encrypted connections. The value is a list of one or more comma-separated protocol names. Theprotocols that can be named for this option depend on the SSL library used to compile MySQL. For details, see Section 6.3.2,“Encrypted Connection TLS Protocols and Ciphers”.
mysql --tls-version ...
--unbuffered
Flush the buffer after each query.
mysql --unbuffered ...
--user
The user name of the MySQL account to use for connecting to the server.
mysql --user ...
--verbose
Verbose mode. Produce more output about what the program does. This option can be given multiple times to produce more and moreoutput. (For example, -v -v -v produces table output format even in batch mode.)
mysql --verbose ...
--version
Display version information and exit.
mysql --version ...
--vertical
Print query output rows vertically (one line per column value). Without this option, you can specify vertical output forindividual statements by terminating them with \G.
mysql --vertical ...
--wait
If the connection cannot be established, wait and retry instead of aborting.
mysql --wait ...
--xml
Produce XML output.<field name="column_name">NULL</field>The output when --xml is used with mysql matches that of mysqldump --xml. See mysqldump(1), for details.The XML output also uses an XML namespace, as shown here:shell> mysql --xml -uroot -e "SHOW VARIABLES LIKE 'version%'"<?xml version="1.0"?><resultset statement="SHOW VARIABLES LIKE 'version%'" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><row><field name="Variable_name">version</field><field name="Value">5.0.40-debug</field></row><row><field name="Variable_name">version_comment</field><field name="Value">Source distribution</field></row><row><field name="Variable_name">version_compile_machine</field><field name="Value">i686</field></row><row><field name="Variable_name">version_compile_os</field><field name="Value">suse-linux-gnu</field></row></resultset>
mysql --xml ...