- MySQL 5.1 Reference Manual :: 4 MySQL Programs :: 4.5 MySQL Client Programs :: 4.5.1 mysql — The MySQL Command-Line Tool :: 4.5.1.1 mysql Options
-
- MySQL 5.1 Reference Manual
- Preface, Notes, Licenses
- 1 General Information
- 2 Installing and Upgrading MySQL
- 3 Tutorial
- 4 MySQL Programs
- 5 MySQL Server Administration
- 6 Backup and Recovery
- 7 Optimization
- 8 Language Structure
- 9 Internationalization and Localization
- 10 Data Types
- 11 Functions and Operators
- 12 SQL Statement Syntax
- 13 Storage Engines
- 14 High Availability and Scalability
- 15 MySQL Enterprise Monitor
- 16 Replication
- 17 MySQL Cluster NDB 6.X/7.X
- 18 Partitioning
- 19 Stored Programs and Views
- 20 INFORMATION_SCHEMA Tables
- 21 Connectors and APIs
- 22 Extending MySQL
- A MySQL 5.1 Frequently Asked Questions
- B Errors, Error Codes, and Common Problems
- C MySQL Change History
- D Restrictions and Limits
- Index
- Standard Index
- C Function Index
- Command Index
- Function Index
- INFORMATION_SCHEMA Index
- Transaction Isolation Level Index
- JOIN Types Index
- Operator Index
- Option Index
- Privileges Index
- SQL Modes Index
- Status Variable Index
- Statement/Syntax Index
- System Variable Index
mysql supports the following options, which can be specified on the command line or in the
[mysql]
and[client]
option file groups. mysql also supports the options for processing option files described at Section 4.2.3.3.1, “Command-Line Options that Affect Option-File Handling”.Table 4.2.
mysql
OptionsFormat Config File Description Introduction Deprecated Removed --auto-rehash auto-rehash Enable automatic rehashing --batch batch Don't use history file --character-sets-dir=name character-sets-dir Set the default character set --column-names column-names Write column names in results --column-type-info column-type-info Display result set metadata 5.1.14 --comments comments Whether to retain or strip comments in statements sent to the server 5.1.23 --compress compress Compress all information sent between the client and the server --connect_timeout=value connect_timeout The number of seconds before connection timeout --database=dbname database The database to use --debug[=debug_options] debug Write a debugging log --debug-check debug-check Print debugging information when the program exits 5.1.21 --debug-info debug-info Print debugging information, memory and CPU statistics when the program exits --default-character-set=charset_name default-character-set Use charset_name as the default character set --delimiter=str delimiter Set the statement delimiter --execute=statement execute Execute the statement and quit --force force Continue even if an SQL error occurs --help Display help message and exit --host=host_name host Connect to the MySQL server on the given host --html html Produce HTML output --ignore-spaces ignore-spaces Ignore spaces after function names --line-numbers line-numbers Write line numbers for errors --local-infile[={0|1}] local-infile Enable or disable for LOCAL capability for LOAD DATA INFILE --max_allowed_packet=value max_allowed_packet The maximum packet length to send to or receive from the server --max_join_size=value max_join_size The automatic limit for rows in a join when using --safe-updates --named-commands named-commands Enable named mysql commands --net_buffer_length=value net_buffer_length The buffer size for TCP/IP and socket communication --no-auto-rehash Disable automatic rehashing --no-beep no-beep Do not beep when errors occur --no-named-commands no-named-commands Disable named mysql commands --no-pager no-pager Deprecated form of --skip-pager --no-tee no-tee Do not copy output to a file --one-database one-database Ignore statements except those for the default database named on the command line --pager[=command] pager Use the given command for paging query output --password[=password] password The password to use when connecting to the server --port=port_num port The TCP/IP port number to use for the connection --prompt=format_str prompt Set the prompt to the specified format --protocol=type protocol The connection protocol to use --quick quick Do not cache each query result --raw raw Write column values without escape conversion --reconnect reconnect If the connection to the server is lost, automatically try to reconnect --safe-updates safe-updates Allow only UPDATE and DELETE statements that specify key values --secure-auth secure-auth Do not send passwords to the server in old (pre-4.1.1) format --select_limit=value select_limit The automatic limit for SELECT statements when using --safe-updates --show-warnings show-warnings Show warnings after each statement if there are any --sigint-ignore sigint-ignore Ignore SIGINT signals (typically the result of typing Control-C) --silent silent Silent mode --skip-auto-rehash skip-auto-rehash Disable automatic rehashing --skip-column-names skip-column-names Do not write column names in results --skip-line-numbers skip-line-numbers Skip line numbers for errors --skip-named-commands skip-named-commands Disable named mysql commands --skip-pager skip-pager Disable paging --skip-reconnect skip-reconnect Disable reconnecting --socket=path socket For connections to localhost --ssl-ca=file_name ssl-ca The path to a file that contains a list of trusted SSL CAs --ssl-capath=directory_name ssl-capath The path to a directory that contains trusted SSL CA certificates in PEM format --ssl-cert=file_name ssl-cert The name of the SSL certificate file to use for establishing a secure connection --ssl-cipher=cipher_list ssl-cipher A list of allowable ciphers to use for SSL encryption --ssl-key=file_name ssl-key The name of the SSL key file to use for establishing a secure connection --ssl-verify-server-cert ssl-verify-server-cert The server's Common Name value in its certificate is verified against the host name used when connecting to the server --table table Display output in tabular format --tee=file_name tee Append a copy of output to the given file --unbuffered unbuffered Flush the buffer after each query --user=user_name user The MySQL user name to use when connecting to the server --verbose Verbose mode --version Display version information and exit --vertical vertical Print query output rows vertically (one line per column value) --wait wait If the connection cannot be established, wait and retry instead of aborting --xml xml Produce XML output -
--help
,-?
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-rehash
to disable rehashing. That causes mysql to start faster, but you must issue therehash
command 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.
-
--batch
,-B
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
--raw
option. -
The directory where character sets are installed. See Section 9.5, “Character Set Configuration”.
-
Write column names in results.
-
Display result set metadata. This option was added in MySQL 5.1.14. (Before that, use
--debug-info
.) The-m
short option was added in MySQL 5.1.21. -
--comments
,-c
Whether to preserve comments in statements sent to the server. The default is --skip-comments (discard comments), enable with --comments (preserve comments). This option was added in MySQL 5.1.23.
-
--compress
,-C
Compress all information sent between the client and the server if both support compression.
-
--database=
,db_name
-D
db_name
The database to use. This is useful primarily in an option file.
-
--debug[=
,debug_options
]-# [
debug_options
]Write a debugging log. A typical
debug_options
string is'd:t:o,
. The default isfile_name
''d:t:o,/tmp/mysql.trace'
. -
Print some debugging information when the program exits. This option was added in MySQL 5.1.21.
-
--debug-info
,-T
Before MySQL 5.1.14, this option prints debugging information and memory and CPU usage statistics when the program exits, and also causes display of result set metadata during execution. As of MySQL 5.1.14, use
--column-type-info
to display result set metadata. -
--default-character-set=
charset_name
Use
charset_name
as the default character set for the client and connection.A common issue that can occur when the operating system uses
utf8
or another multi-byte character set is that output from the mysql client is formatted incorrectly, due to the fact that the MySQL client uses thelatin1
character 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 9.5, “Character Set Configuration”, for more information.
-
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 4.5.1.2, “mysql Commands”. -
--execute=
,statement
-e
statement
Execute the statement and quit. The default output format is like that produced with
--batch
. See Section 4.2.3.1, “Using Options on the Command Line”, for some examples. -
--force
,-f
Continue even if an SQL error occurs.
-
--host=
,host_name
-h
host_name
Connect to the MySQL server on the given host.
-
--html
,-H
Produce HTML output.
-
--ignore-spaces
,-i
Ignore spaces after function names. The effect of this is described in the discussion for the
IGNORE_SPACE
SQL mode (see Section 5.1.7, “Server SQL Modes”). -
Write line numbers for errors. Disable this with
--skip-line-numbers
. -
Enable or disable
LOCAL
capability forLOAD DATA INFILE
. With no value, the option enablesLOCAL
. The option may be given as--local-infile=0
or--local-infile=1
to explicitly disable or enableLOCAL
. EnablingLOCAL
has no effect if the server does not also support it.MySQL Enterprise. For expert advice on the security implications of enabling
LOCAL
, subscribe to the MySQL Enterprise Monitor. For more information, see http://www.mysql.com/products/enterprise/advisors.html. -
--named-commands
,-G
Enable named mysql commands. Long-format commands are allowed, not just short-format commands. For example,
quit
and\q
both are recognized. Use--skip-named-commands
to disable named commands. See Section 4.5.1.2, “mysql Commands”. -
--no-auto-rehash
,-A
This has the same effect as
-skip-auto-rehash
. See the description for--auto-rehash
. -
--no-beep
,-b
Do not beep when errors occur.
-
Deprecated, use
--disable-named-commands
instead.--no-named-commands
is removed in MySQL 5.5. -
Deprecated form of
--skip-pager
. See the--pager
option.--no-pager
is removed in MySQL 5.5. -
Deprecated form of
--skip-tee
. See the--tee
option.--no-tee
is removed in MySQL 5.5. -
--one-database
,-o
Ignore statements except those for the default database named on the command line. This is useful for skipping updates to other databases in the binary log.
-
Use the given command for paging query output. If the command is omitted, the default pager is the value of your
PAGER
environment 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 4.5.1.2, “mysql Commands”, discusses output paging further. -
--password[=
,password
]-p[
password
]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 thepassword
value following the--password
or-p
option on the command line, mysql prompts for one.Specifying a password on the command line should be considered insecure. See Section 5.3.2.2, “End-User Guidelines for Password Security”. You can use an option file to avoid giving the password on the command line.
-
--pipe
,-W
On Windows, connect to the server via a named pipe. This option applies only if the server supports named-pipe connections.
-
--port=
,port_num
-P
port_num
The TCP/IP port number to use for the connection.
-
Set the prompt to the specified format. The default is
mysql>
. The special sequences that the prompt can contain are described in Section 4.5.1.2, “mysql Commands”. -
--protocol={TCP|SOCKET|PIPE|MEMORY}
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 allowable values, see Section 4.2.2, “Connecting to the MySQL Server”.
-
--quick
,-q
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.
-
--raw
,-r
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 output so they can be identified easily. Newline, tab,NUL
, and backslash are written as\n
,\t
,\0
, and\\
. The--raw
option disables this character escaping.The following example demonstrates tabular versus nontabular output and the use of raw mode to disable escaping:
%
mysql
mysql> SELECT CHAR(92); +----------+ | CHAR(92) | +----------+ | \ | +----------+ %mysql -s
mysql> SELECT CHAR(92); CHAR(92) \\ %mysql -s -r
mysql> 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
--skip-reconnect
. -
--safe-updates
,--i-am-a-dummy
,-U
Allow only those
UPDATE
andDELETE
statements 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-updates
on the command line. See Section 4.5.1.5, “mysql Tips”, for more information about this option. -
Do not send passwords to the server in old (pre-4.1.1) format. This prevents connections except for servers that use the newer password format.
MySQL Enterprise. For expert advice on database security, subscribe to the MySQL Enterprise Monitor. For more information, see http://www.mysql.com/products/enterprise/advisors.html.
-
Cause warnings to be shown after each statement if there are any. This option applies to interactive and batch mode.
-
Ignore
SIGINT
signals (typically the result of typing Control-C). -
--silent
,-s
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. -
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.
-
--socket=
,path
-S
path
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
--ssl
specify whether to connect to the server via SSL and indicate where to find SSL keys and certificates. See Section 5.5.6.3, “SSL Command Options”. -
--table
,-t
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 4.5.1.2, “mysql Commands”, discusses tee files further.
-
--unbuffered
,-n
Flush the buffer after each query.
-
--user=
,user_name
-u
user_name
The MySQL user name to use when connecting to the server.
-
--verbose
,-v
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 -v
produces table output format even in batch mode.) -
--version
,-V
Display version information and exit.
-
--vertical
,-E
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
\G
. -
--wait
,-w
If the connection cannot be established, wait and retry instead of aborting.
-
--xml
,-X
Produce XML output.
Note
Prior to MySQL 5.1.12, there was no differentiation in the output when using this option between columns containing the
NULL
value and columns containing the string literal'NULL'
; both were represented as<field name="
column_name
">NULL</field>Beginning with MySQL 5.1.12, the output when
--xml
is used with mysql matches that of mysqldump--xml
. See Section 4.5.4, “mysqldump — A Database Backup Program” for details.Beginning with MySQL 5.1.18, 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>(See Bug#25946.)
You can also set the following variables by using
--
. Thevar_name
=value
--set-variable
format is deprecated and is removed in MySQL 5.5.-
The number of seconds before connection timeout. (Default value is
0
.) -
The maximum packet length to send to or receive from the server. (Default value is 16MB.)
-
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.)
-
The automatic limit for
SELECT
statements when using--safe-updates
. (Default value is 1,000.)
On Unix, the mysql client writes a record of executed statements to a history file. By default, this file is named
.mysql_history
and is created in your home directory. To specify a different file, set the value of theMYSQL_HISTFILE
environment variable.The
.mysql_history
should be protected with a restrictive access mode because sensitive information might be written to it, such as the text of SQL statements that contain passwords. See Section 5.3.2.2, “End-User Guidelines for Password Security”.If you do not want to maintain a history file, first remove
.mysql_history
if it exists, and then use either of the following techniques:Set the
MYSQL_HISTFILE
variable to/dev/null
. To cause this setting to take effect each time you log in, put the setting in one of your shell's startup files.-
Create
.mysql_history
as a symbolic link to/dev/null
:shell>
ln -s /dev/null $HOME/.mysql_history
You need do this only once.