CONTENT
  • CHANGES
Szukaj
counter

#top mysql


mysql - the MySQL command-line tool

Powiązane:
mysql, mysqladmin, mysqldump,

SYNOPSIS
mysql [options] db_name


DESCRIPTION



OPTIONS
--help, -?
Display a help message and exit.

--auto-rehash
Enable automatic rehashing. This option is on by default, which enables table and column name completion. Use --skip-auto-rehash to disable rehashing. That causes mysql to start faster, but you must issue the rehash command if you want to use table and column name completion.

--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.

--character-sets-dir=path
The directory where character sets are installed. See Section 8.1, "The Character Set Used for Data and Sorting".

--column-names
Write column names in results.

--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. The debug_options string often is 'd:t:o,file_name'. The default is 'd:t:o,/tmp/mysql.trace'.

--debug-info, -T
Print some debugging information when the program exits.

--default-character-set=charset_name
Use charset_name as the default character set. See Section 8.1, “The Character Set Used for Data and Sorting”.

--delimiter=str
Set the statement delimiter. The default is the semicolon character (';').

--execute=statement, -e statement
Execute the statement and quit. The default output format is like that produced with --batch. See Section 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 the section called "SQL MODES").

--line-numbers
Write line numbers for errors. Disable this with --skip-line-numbers.

--local-infile[={0|1}]
Enable or disable LOCAL capability for LOAD DATA INFILE. With no value, the option enables LOCAL. The option may be given as --local-infile=0 or --local-infile=1 to explicitly disable or enable LOCAL. Enabling LOCAL 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 Network Monitoring and Advisory Service. 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 the section called “MYSQL COMMANDS”.

--no-auto-rehash, -A
Deprecated form of -skip-auto-rehash. See the description for --auto-rehash.

--no-beep, -b
Do not beep when errors occur.

--no-named-commands, -g
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 the section called “MYSQL COMMANDS”.

--no-pager
Deprecated form of --skip-pager. See the --pager option.

--no-tee
Do not copy output to a file. the section called "MYSQL COMMANDS", discusses tee files further.

--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.

--pager[=command]
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. It does not work in batch mode. To disable paging, use --skip-pager. the section called "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 the password value following the --password or -p option on the command line, you are prompted for one.

Specifying a password on the command line should be considered insecure. See Section 6.6, "Keeping Your Password Secure".

--port=port_num, -P port_num
The TCP/IP port number to use for the connection.

--prompt=format_str
Set the prompt to the specified format. The default is mysql>. The special sequences that the prompt can contain are described in the section called "MYSQL COMMANDS".

--protocol={TCP|SOCKET|PIPE|MEMORY}
The connection protocol to use.

--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
Write column values without escape conversion. Often used with the --batch option.

--reconnect
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 and DELETE 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 the section called “MYSQL TIPS”, for more information about this option.

--secure-auth
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 Network Monitoring and Advisory Service. For more information see http://www.mysql.com/products/enterprise/advisors.html.

--show-warnings
Cause warnings to be shown after each statement if there are any. This option applies to interactive and batch mode. This option was added in MySQL 5.0.6.

--sigint-ignore
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.

--skip-column-names, -N
Do not write column names in results.

--skip-line-numbers, -L
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.

--ssl*
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 6.7.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.

--tee=file_name
Append a copy of output to the given file. This option does not work in batch mode. in the section called “MYSQL COMMANDS”, discusses tee files further.

--unbuffered, -n
Flush the buffer after each query.

--user=user_name, -u user_name
The MySQL username 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.0.26, 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.0.26, the output when --xml is used with mysql matches that of mysqldump --xml. See the section of the Manual which discusses the --xml option for mysqldump for details.

Beginning with MySQL 5.0.40, 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 [1]Bug#25946.)


You can also set the following variables by using --var_name=value syntax:
connect_timeout
The number of seconds before connection timeout. (Default value is 0.)

max_allowed_packet
The maximum packet length to send to or receive from the server. (Default value is 16MB.)

max_join_size
The automatic limit for rows in a join when using --safe-updates. (Default value is 1,000,000.)

net_buffer_length
The buffer size for TCP/IP and socket communication. (Default value is 16KB.)

select_limit
The automatic limit for SELECT statements when using --safe-updates. (Default value is 1,000.)

It is also possible to set variables by using --set-variable=var_name=value or -O var_name=value syntax. This syntax is deprecated.

On Unix, the mysql client writes a record of executed statements to a history file. By default, the history file is named .mysql_history and is created in your home directory. To specify a different file, set the value of the MYSQL_HISTFILE environment variable.

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.



EXAMPLES
echo "show tables" | mysql -u username --password=password database
echo "show tables" | mysql -h hostname -u username --password=password database
echo "show tables" | mysql -h hostname -P 3307 -u username --password=password database
echo "show tables" | mysql -h hostname --port=3307 -u username --password=password database
mysql -h hostname -u username --password=password database -e "show tables"

echo "select * from temp_table" | mysql -h hostname -P 3307 -u username --password=password database
idtemp  name    value
1       name1   value1
2       name2   WzUoVh
3       name3   value3
4       name4   value1
5       name5   BfLpOi
6       name6   JvOsHj

echo "select * from temp_table" | mysql -s -B -N -h hostname -P 3307 -u username --password=password database
1       name1   value1
2       name2   WzUoVh
3       name3   value3
4       name4   value1
5       name5   BfLpOi
6       name6   JvOsHj




Zmodyfikowany ostatnio: 2014/05/15 09:59:29 (9 lat temu), textsize: 14,8 kB, htmlsize: 17,4 kB

Zapraszam do komentowania, zgłaszania sugestii, propozycji, własnych przykładów, ...
Dodaj komentarzKomentarze użytkowników