mysql supports the following options, which
can be specified on the command line or in the
groups of an option file. For information about option files
used by MySQL programs, see Section 5.2.6, “Using Option Files”.
|--auto-rehash||Enable automatic rehashing|
|--auto-vertical-output||Enable automatic vertical result set display|
|--batch||Do not use history file|
|--binary-mode||Disable \r\n - to - \n translation and treatment of \0 as end-of-query|
|--bind-address||Use specified network interface to connect to MySQL Server|
|--character-sets-dir||Directory where character sets are installed|
|--column-names||Write column names in results|
|--column-type-info||Display result set metadata|
|--comments||Whether to retain or strip comments in statements sent to the server|
|--compress||Compress all information sent between client and server|
|--connect-expired-password||Indicate to server that client can handle expired-password sandbox mode.||5.7.2|
|--connect_timeout||Number of seconds before connection timeout|
|--database||The database to use|
|--debug||Write debugging log; supported only if MySQL was built with debugging support|
|--debug-check||Print debugging information when program exits|
|--debug-info||Print debugging information, memory, and CPU statistics when program exits|
|--default-auth||Authentication plugin to use|
|--default-character-set||Specify default character set|
|--defaults-extra-file||Read named option file in addition to usual option files|
|--defaults-file||Read only named option file|
|--defaults-group-suffix||Option group suffix value|
|--delimiter||Set the statement delimiter|
|--enable-cleartext-plugin||Enable cleartext authentication plugin|
|--execute||Execute the statement and quit|
|--force||Continue even if an SQL error occurs|
|--help||Display help message and exit|
|--histignore||Patterns specifying which statements to ignore for logging|
|--host||Connect to MySQL server on given host|
|--html||Produce HTML output|
|--ignore-spaces||Ignore spaces after function names|
|--init-command||SQL statement to execute after connecting|
|--line-numbers||Write line numbers for errors|
|--local-infile||Enable or disable for LOCAL capability for LOAD DATA INFILE|
|--login-path||Read login path options from .mylogin.cnf|
|--max_allowed_packet||Maximum packet length to send to or receive from server|
|--max_join_size||The automatic limit for rows in a join when using --safe-updates|
|--named-commands||Enable named mysql commands|
|--net_buffer_length||Buffer size for TCP/IP and socket communication|
|--no-auto-rehash||Disable automatic rehashing|
|--no-beep||Do not beep when errors occur|
|--no-defaults||Read no option files|
|--one-database||Ignore statements except those for the default database named on the command line|
|--pager||Use the given command for paging query output|
|--password||Password to use when connecting to server|
|--pipe||On Windows, connect to server using named pipe|
|--plugin-dir||Directory where plugins are installed|
|--port||TCP/IP port number to use for connection|
|--print-defaults||Print default options|
|--prompt||Set the prompt to the specified format|
|--protocol||Connection protocol to use|
|--quick||Do not cache each query result|
|--raw||Write column values without escape conversion|
|--reconnect||If the connection to the server is lost, automatically try to reconnect|
|--i-am-a-dummy, --safe-updates||Allow only UPDATE and DELETE statements that specify key values|
|--secure-auth||Do not send passwords to server in old (pre-4.1) format||5.7.5|
|--select_limit||The automatic limit for SELECT statements when using --safe-updates|
|--server-public-key-path||Path name to file containing RSA public key|
|--shared-memory-base-name||The name of shared memory to use for shared-memory connections|
|--show-warnings||Show warnings after each statement if there are any|
|--sigint-ignore||Ignore SIGINT signals (typically the result of typing Control+C)|
|--skip-auto-rehash||Disable automatic rehashing|
|--skip-column-names||Do not write column names in results|
|--skip-line-numbers||Skip line numbers for errors|
|--skip-named-commands||Disable named mysql commands|
|--socket||For connections to localhost, the Unix socket file to use|
|--ssl||Enable secure connection|
|--ssl-ca||Path of file that contains list of trusted SSL CAs|
|--ssl-capath||Path of directory that contains trusted SSL CA certificates in PEM format|
|--ssl-cert||Path of file that contains X509 certificate in PEM format|
|--ssl-cipher||List of permitted ciphers to use for connection encryption|
|--ssl-crl||Path of file that contains certificate revocation lists|
|--ssl-crlpath||Path of directory that contains certificate revocation list files|
|--ssl-key||Path of file that contains X509 key in PEM format|
|--ssl-mode||Security state of connection to server||5.7.11|
|--ssl-verify-server-cert||Verify server certificate Common Name value against host name used when connecting to server|
|--syslog||Log interactive statements to syslog||5.7.1|
|--table||Display output in tabular format|
|--tee||Append a copy of output to named file|
|--tls-version||Protocols permitted for secure connections||5.7.10|
|--unbuffered||Flush the buffer after each query|
|--user||MySQL user name to use when connecting to server|
|--version||Display version information and exit|
|--vertical||Print query output rows vertically (one line per column value)|
|--wait||If the connection cannot be established, wait and retry instead of aborting|
|--xml||Produce XML output|
Display a help message and exit.
Enable automatic rehashing. This option is on by default, which enables database, table, and column name completion. Use
--disable-auto-rehashto disable rehashing. That causes mysql to start faster, but you must issue the
rehashcommand or its
\#shortcut if you want to use name completion.
To complete a name, enter the first part and press Tab. If the name is unambiguous, mysql completes it. Otherwise, you can press Tab again to see the possible names that begin with what you have typed so far. Completion does not occur if there is no default database.Note
This feature requires a MySQL client that is compiled with the readline library. Typically, the readline library is not available on Windows.
Cause result sets to be displayed vertically if they are too wide for the current window, and using normal tabular format otherwise. (This applies to statements terminated by
Print results using tab as the column separator, with each row on a new line. With this option, mysql does not use the history file.
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
This option helps when processing mysqlbinlog output that may contain
BLOBvalues. By default, mysql translates
\r\nin statement strings to
\0as the statement terminator.
--binary-modedisables both features. It also disables all mysql commands except
delimiterin non-interactive mode (for input piped to mysql or loaded using the
On a computer having multiple network interfaces, use this option to select which interface to use for connecting to the MySQL server.
The directory where character sets are installed. See Section 11.5, “Character Set Configuration”.
Write column names in results.
Display result set metadata.
Whether to preserve comments in statements sent to the server. The default is --skip-comments (discard comments), enable with --comments (preserve comments).
Compress all information sent between the client and the server if both support compression.
Indicate to the server that the client can handle sandbox mode if the account used to connect has an expired password. This can be useful for noninteractive invocations of mysql because normally the server disconnects noninteractive clients that attempt to connect using an account with an expired password. (See Section 7.3.7, “Password Expiration and Sandbox Mode”.) This option was added in MySQL 5.7.2.
The database to use. This is useful primarily in an option file.
Write a debugging log. A typical
d:t:o,. The default is
This option is available only if MySQL was built using
WITH_DEBUG. MySQL release binaries provided by Oracle are not built using this option.
Print some debugging information when the program exits.
Print debugging information and memory and CPU usage statistics when the program exits.
A hint about the client-side authentication plugin to use. See Section 7.3.8, “Pluggable Authentication”.
charset_nameas the default character set for the client and connection.
A common issue that can occur when the operating system uses
utf8or another multibyte character set is that output from the mysql client is formatted incorrectly, due to the fact that the MySQL client uses the
latin1character set by default. You can usually fix such issues by using this option to force the client to use the system character set instead.
See Section 11.5, “Character Set Configuration”, for more information.
Read this option file after the global option file but (on Unix) before the user option file. If the file does not exist or is otherwise inaccessible, an error occurs.
file_nameis interpreted relative to the current directory if given as a relative path name rather than a full path name.
Use only the given option file. If the file does not exist or is otherwise inaccessible, an error occurs.
file_nameis interpreted relative to the current directory if given as a relative path name rather than a full path name.
Read not only the usual option groups, but also groups with the usual names and a suffix of
str. For example, mysql normally reads the
[mysql]groups. If the
--defaults-group-suffix=_otheroption is given, mysql also reads the
Set the statement delimiter. The default is the semicolon character (“
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 first line. See Section 126.96.36.199, “mysql Commands”.
mysql_clear_passwordcleartext authentication plugin. (See Section 188.8.131.52, “The Cleartext Client-Side Authentication Plugin”.)
Execute the statement and quit. The default output format is like that produced with
--batch. See Section 5.2.4, “Using Options on the Command Line”, for some examples. With this option, mysql does not use the history file.
Continue even if an SQL error occurs.
A colon-separated list of one or more patterns specifying statements to ignore for logging purposes. These patterns are added to the default pattern list (
"*IDENTIFIED*:*PASSWORD*"). The value specified for this option affects logging of statements written to the history file, and to
--syslogoption is given. For more information, see Section 184.108.40.206, “mysql Logging”.
Connect to the MySQL server on the given host.
Produce HTML output.
SQL statement to execute after connecting to the server. If auto-reconnect is enabled, the statement is executed again after reconnection occurs.
Write line numbers for errors. Disable this with
Enable or disable
LOAD DATA INFILE. With no value, the option enables
LOCAL. The option may be given as
--local-infile=1to explicitly disable or enable
LOCALhas no effect if the server does not also support it.
Read options from the named login path in the
.mylogin.cnflogin path file. A “login path” is an option group containing options that specify which MySQL server to connect to and which account to authenticate as. To create or modify a login path file, use the mysql_config_editor utility. See Section 5.6.6, “mysql_config_editor — MySQL Configuration Utility”.
Enable named mysql commands. Long-format commands are permitted, not just short-format commands. For example,
\qboth are recognized. Use
--skip-named-commandsto disable named commands. See Section 220.127.116.11, “mysql Commands”.
This has the same effect as
--skip-auto-rehash. See the description for
Do not beep when errors occur.
Do not read any option files. If program startup fails due to reading unknown options from an option file,
--no-defaultscan be used to prevent them from being read.
The exception is that the
.mylogin.cnffile, if it exists, is read in all cases. This permits passwords to be specified in a safer way than on the command line even when
--no-defaultsis used. (
.mylogin.cnfis created by the mysql_config_editor utility. See Section 5.6.6, “mysql_config_editor — MySQL Configuration Utility”.)
Ignore statements except those that occur while the default database is the one named on the command line. This option is rudimentary and should be used with care. Statement filtering is based only on
Initially, mysql executes statements in the input because specifying a database
db_nameon the command line is equivalent to inserting
USEat the beginning of the input. Then, for each
USEstatement encountered, mysql accepts or rejects following statements 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);
DELETEstatement is executed because the default database is
db1, even though the statement names a table in a different database.
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 in interactive mode. To disable paging, use
--skip-pager. Section 18.104.22.168, “mysql Commands”, discusses output paging further.
The password to use when connecting to the server. If you use the short option form (
-p), you cannot have a space between the option and the password. If you omit the
passwordvalue following the
-poption on the command line, mysql prompts for one.
Specifying a password on the command line should be considered insecure. See Section 22.214.171.124, “End-User Guidelines for Password Security”. You can use an option file to avoid giving the password on the command line.
On Windows, connect to the server using a named pipe. This option applies only if the server supports named-pipe connections.
The directory in which to look for plugins. Specify this option if the
--default-authoption is used to specify an authentication plugin but mysql does not find it. See Section 7.3.8, “Pluggable Authentication”.
The TCP/IP port number to use for the connection.
Print the program name and all options that it gets from option files.
Set the prompt to the specified format. The default is
mysql>. The special sequences that the prompt can contain are described in Section 126.96.36.199, “mysql Commands”.
The connection protocol to use for connecting to the server. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want. For details on the permissible values, see Section 5.2.2, “Connecting to the MySQL Server”.
Do not cache each query result, print each row as it is received. This may slow down the server if the output is suspended. With this option, mysql does not use the history file.
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
--silentoption is given), special characters are escaped in the output so they can be identified easily. Newline, tab,
NUL, and backslash are written as
--rawoption disables this character escaping.
The following example demonstrates tabular versus nontabular output and the use of raw mode to disable escaping:
mysqlmysql> SELECT CHAR(92); +----------+ | CHAR(92) | +----------+ | \ | +----------+ %
mysql -smysql> SELECT CHAR(92); CHAR(92) \\ %
mysql -s -rmysql> SELECT CHAR(92); CHAR(92) \
If the connection to the server is lost, automatically try to reconnect. A single reconnect attempt is made each time the connection is lost. To suppress reconnection behavior, use
Permit only those
DELETEstatements that specify which rows to modify by using key values. If you have set this option in an option file, you can override it by using
--safe-updateson the command line. See Section 188.8.131.52, “mysql Tips”, for more information about this option.
Do not send passwords to the server in old (pre-4.1) format. This prevents connections except for servers that use the newer password format.
As of MySQL 5.7.5, this option is deprecated and will be removed in a future MySQL release. It is always enabled and attempting to disable it (
--secure-auth=0) produces an error. Before MySQL 5.7.5, this option is enabled by default but can be disabled.Note
Passwords that use the pre-4.1 hashing method are less secure than passwords that use the native password hashing method and should be avoided. Pre-4.1 passwords are deprecated and support for them is removed in MySQL 5.7.5. For account upgrade instructions, see Section 184.108.40.206, “Migrating Away from Pre-4.1 Password Hashing and the mysql_old_password Plugin”.
The path name to a file containing the server RSA public key. The file must be in PEM format. The public key is used for RSA encryption of the client password for connections to the server made using accounts that authenticate with the
sha256_passwordplugin. This option is ignored for client accounts that do not authenticate with that plugin. It is also ignored if password encryption is not needed, as is the case when the client connects to the server using an SSL connection.
The server sends the public key to the client as needed, so it is not necessary to use this option for RSA password encryption to occur. It is more efficient to do so because then the server need not send the key.
For additional discussion regarding use of the
sha256_passwordplugin, including how to get the RSA public key, see Section 220.127.116.11, “The SHA-256 Authentication Plugin”.
This option is available only if MySQL was built using OpenSSL.
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.
The server must be started with the
--shared-memoryoption to enable shared-memory connections.
Cause warnings to be shown after each statement if there are any. This option applies to interactive and batch mode.
SIGINTsignals (typically the result of typing Control+C).
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
Do not write column names in results.
Do not write line numbers for errors. Useful when you want to compare result files that include error messages.
For connections to
localhost, the Unix socket file to use, or, on Windows, the name of the named pipe to use.
Options that begin with
--sslspecify whether to connect to the server using SSL and indicate where to find SSL keys and certificates. See Section 18.104.22.168, “Command Options for Secure Connections”.
This option causes mysql to send interactive statements to the system logging facility. On Unix, this is
syslog; on Windows, it is the Windows Event Log. The destination where logged messages appear is system dependent. On Linux, the destination is often the
Here is a sample of output generated on Linux by using
--syslog. This output is formatted for readability; each logged message actually takes a single line.
Mar 7 12:39:25 myhost MysqlClient: 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: 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 Section 22.214.171.124, “mysql Logging”.
--syslogoption was added in MySQL 5.7.1.
Display output in table format. This is the default for interactive use, but can be used to produce table output in batch mode.
Append a copy of output to the given file. This option works only in interactive mode. Section 126.96.36.199, “mysql Commands”, discusses tee files further.
The protocols permitted by the client for encrypted connections. The value is a comma-separated list containing one or more protocol names. The protocols that can be named for this option depend on the SSL library used to compile MySQL. For details, see Section 188.8.131.52, “Secure Connection Protocols and Ciphers”.
This option was added in MySQL 5.7.10.
Flush the buffer after each query.
The MySQL user name to use when connecting to the server.
Verbose mode. Produce more output about what the program does. This option can be given multiple times to produce more and more output. (For example,
-v -v -vproduces table output format even in batch mode.)
Display version information and exit.
Print query output rows vertically (one line per column value). Without this option, you can specify vertical output for individual statements by terminating them with
If the connection cannot be established, wait and retry instead of aborting.
Produce XML output.
The output when
--xmlis used with mysql matches that of mysqldump
--xml. See Section 5.5.4, “mysqldump — A Database Backup Program” for details.
The XML output also uses an XML namespace, as shown here:
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>
(See Bug #25946.)
You can also set the following variables by using
The number of seconds before connection timeout. (Default value is
The maximum size of the buffer for client/server communication. The default is 16MB, the maximum is 1GB.
The automatic limit for rows in a join when using
--safe-updates. (Default value is 1,000,000.)
The buffer size for TCP/IP and socket communication. (Default value is 16KB.)