Вы находитесь на странице: 1из 7

24/09/2013

MySQL :: MySQL 5.0 Reference Manual :: 4.5.1.2 mysql Commands

MySQL 5.0 Reference Manual :: 4 MySQL Programs :: 4.5 MySQL Client Programs :: 4.5.1 mysql The MySQL Command-Line Tool :: 4.5.1.2 mysql Commands

4.5.1.2. mysql Commands


mysql sends each SQL statement that you issue to the server to be executed. There is also a set of commands that mysql itself interprets. For a list of these commands, type h e l por \ hat the m y s q l >prompt:

4.5.1.1 mysql Options 4.5.1.3 mysql Logging

Section Navigation

[Toggle]

4.5.1 mysql The MySQL Command-Line Tool 4.5.1.1 mysql Options 4.5.1.2 mysql Commands 4.5.1.3 mysql Logging m y s q l >h e l p 4.5.1.4 mysql Server-Side Help L i s to fa l lM y S Q Lc o m m a n d s : 4.5.1.5 Executing SQL N o t et h a ta l lt e x tc o m m a n d sm u s tb ef i r s to nl i n ea n de n dw i t h' ; ' from a Text File Statements ? ( \ ? )S y n o n y mf o r` h e l p ' . 4.5.1.6 mysql Tips
c l e a r c o n n e c t e d i t e g o e x i t g o h e l p n o p a g e r n o t e e p a g e r p r i n t p r o m p t q u i t r e h a s h s o u r c e s t a t u s s y s t e m t e e u s e c h a r s e t ( \ c )C l e a rc o m m a n d . ( \ r )R e c o n n e c tt ot h es e r v e r .O p t i o n a la r g u m e n t sa r ed ba n dh o s t . ( \ e )E d i tc o m m a n dw i t h$ E D I T O R . ( \ G )S e n dc o m m a n dt om y s q ls e r v e r ,d i s p l a yr e s u l tv e r t i c a l l y . ( \ q )E x i tm y s q l .S a m ea sq u i t . ( \ g )S e n dc o m m a n dt om y s q ls e r v e r . ( \ h )D i s p l a yt h i sh e l p . ( \ n )D i s a b l ep a g e r ,p r i n tt os t d o u t . ( \ t )D o n ' tw r i t ei n t oo u t f i l e . ( \ P )S e tP A G E R[ t o _ p a g e r ] .P r i n tt h eq u e r yr e s u l t sv i aP A G E R . ( \ p )P r i n tc u r r e n tc o m m a n d . ( \ R )C h a n g ey o u rm y s q lp r o m p t . ( \ q )Q u i tm y s q l . ( \ # )R e b u i l dc o m p l e t i o nh a s h . ( \ . )E x e c u t ea nS Q Ls c r i p tf i l e .T a k e saf i l en a m ea sa na r g u m e n t . ( \ s )G e ts t a t u si n f o r m a t i o nf r o mt h es e r v e r . ( \ ! )E x e c u t eas y s t e ms h e l lc o m m a n d . ( \ T )S e to u t f i l e[ t o _ o u t f i l e ] .A p p e n de v e r y t h i n gi n t og i v e n o u t f i l e . ( \ u )U s ea n o t h e rd a t a b a s e .T a k e sd a t a b a s en a m ea sa r g u m e n t . ( \ C )S w i t c ht oa n o t h e rc h a r s e t .M i g h tb en e e d e df o rp r o c e s s i n g b i n l o gw i t hm u l t i b y t ec h a r s e t s . w a r n i n g s ( \ W )S h o ww a r n i n g sa f t e re v e r ys t a t e m e n t . n o w a r n i n g( \ w )D o n ' ts h o ww a r n i n g sa f t e re v e r ys t a t e m e n t . F o rs e r v e rs i d eh e l p ,t y p e' h e l pc o n t e n t s '

d e l i m i t e r( \ d )S e ts t a t e m e n td e l i m i t e r .

Each command has both a long and short form. The long form is not case sensitive; the short form is. The long form can be followed by an optional semicolon terminator, but the short form should not.
dev.mysql.com/doc/refman/5.0/en/mysql-commands.html 1/7

24/09/2013

MySQL :: MySQL 5.0 Reference Manual :: 4.5.1.2 mysql Commands

The use of short-form commands within multi-line / *. . .* /comments is not supported.


h e l p[ a r g ] ,\ h[ a r g ] ,\ ?[ a r g ] , ?[ a r g ]

Display a help message listing the available mysql commands. If you provide an argument to the h e l pcommand, mysql uses it as a search string to access serverside help from the contents of the MySQL Reference Manual. For more information, see Section 4.5.1.4, mysql Server-Side Help.
c h a r s e tc h a r s e t _ n a m e ,\ Cc h a r s e t _ n a m e

Change the default character set and issue a S E TN A M E Sstatement. This enables the character set to remain synchronized on the client and server if mysql is run with auto-reconnect enabled (which is not recommended), because the specified character set is used for reconnects. This command was added in MySQL 5.0.19.
c l e a r ,\ c

Clear the current input. Use this if you change your mind about executing the statement that you are entering.
c o n n e c t[ d b _ n a m eh o s t _ n a m e ] ] ,\ r[ d b _ n a m eh o s t _ n a m e ] ]

Reconnect to the server. The optional database name and host name arguments may be given to specify the default database or the host where the server is running. If omitted, the current values are used.
d e l i m i t e rs t r ,\ ds t r

Change the string that mysql interprets as the separator between SQL statements. The default is the semicolon character (; ). The delimiter string can be specified as an unquoted or quoted argument on the d e l i m i t e r command line. Quoting can be done with either single quote (' ), double quote (" ), or backtick (` ) characters. To include a quote within a quoted string, either quote the string with a different quote character or escape the quote with a backslash (\ ) character. Backslash should be avoided outside of quoted strings because it is the escape character for MySQL. For an unquoted argument, the delimiter is read up to the first space or end of line. For a quoted argument, the delimiter is read up to the matching quote on the line. mysql interprets instances of the delimiter string as a statement delimiter anywhere it occurs, except within quoted strings. Be careful about defining a delimiter that might occur within other words. For example, if you define the delimiter as X , you will be unable to use the word I N D E Xin statements. mysql interprets this as I N D Efollowed by the delimiter X . When the delimiter recognized by mysql is set to something other than the default of ; , instances of that character are sent to the server without interpretation. However, the server itself still interprets ; as a statement delimiter and processes statements accordingly. This behavior on the server side comes into play for multiple-statement execution (see Section 20.6.16, C API Support for Multiple Statement Execution), and for parsing the body of stored procedures and functions and triggers (see Section 18.1, Defining Stored Programs).
e d i t ,\ e

Edit the current input statement. mysql checks the values of the E D I T O Rand V I S U A Lenvironment variables to determine which editor to use. The default editor is vi if neither variable is set.
dev.mysql.com/doc/refman/5.0/en/mysql-commands.html 2/7

24/09/2013

MySQL :: MySQL 5.0 Reference Manual :: 4.5.1.2 mysql Commands

The e d i tcommand works only in Unix.


e g o ,\ G

Send the current statement to the server to be executed and display the result using vertical format. Be careful about defining a delimiter that might occur within other words. For example, if you define the delimiter as X , you will be unable to use the word I N D E Xin statements.
e x i t ,\ q

Exit mysql.
g o ,\ g

Send the current statement to the server to be executed.


n o p a g e r ,\ n

Disable output paging. See the description for p a g e r . The n o p a g e rcommand works only in Unix.
n o t e e ,\ t

Disable output copying to the tee file. See the description for t e e .
n o w a r n i n g ,\ w

Enable display of warnings after each statement. This command was added in MySQL 5.0.6.
p a g e r[ c o m m a n d ] ,\ P[ c o m m a n d ]

Enable output paging. By using the p a g e roption when you invoke mysql, it is possible to browse or search query results in interactive mode with Unix programs such as less, more , or any other similar program. If you specify no value for the option, mysql checks the value of the P A G E R environment variable and sets the pager to that. Pager functionality works only in interactive mode. Output paging can be enabled interactively with the p a g e rcommand and disabled with n o p a g e r . The command takes an optional argument; if given, the paging program is set to that. With no argument, the pager is set to the pager that was set on the command line, or s t d o u tif no pager was specified. Output paging works only in Unix because it uses the p o p e n ( )function, which does not exist on Windows. For Windows, the t e eoption can be used instead to save query output, although it is not as convenient as p a g e rfor browsing output in some situations.
p r i n t ,\ p

Print the current input statement without executing it.


p r o m p t[ s t r ] ,\ R[ s t r ]

Reconfigure the mysql prompt to the given string. The special character sequences that can be used in the prompt are described later in this section. If you specify the p r o m p tcommand with no argument, mysql resets the prompt to the default of m y s q l > .
dev.mysql.com/doc/refman/5.0/en/mysql-commands.html 3/7

24/09/2013

MySQL :: MySQL 5.0 Reference Manual :: 4.5.1.2 mysql Commands

q u i t ,\ q

Exit mysql.
r e h a s h ,\ #

Rebuild the completion hash that enables database, table, and column name completion while you are entering statements. (See the description for the a u t o r e h a s hoption.)
s o u r c ef i l e _ n a m e ,\ .f i l e _ n a m e

Read the named file and executes the statements contained therein. On Windows, you can specify path name separators as /or \ \ .
s t a t u s ,\ s

Provide status information about the connection and the server you are using. If you are running in s a f e u p d a t e smode, s t a t u salso prints the values for the mysql variables that affect your queries.
s y s t e mc o m m a n d ,\ !c o m m a n d

Execute the given command using your default command interpreter. The s y s t e mcommand works only in Unix.
t e e[ f i l e _ n a m e ] ,\ T[ f i l e _ n a m e ]

By using the t e eoption when you invoke mysql, you can log statements and their output. All the data displayed on the screen is appended into a given file. This can be very useful for debugging purposes also. mysql flushes results to the file after each statement, just before it prints its next prompt. Tee functionality works only in interactive mode. You can enable this feature interactively with the t e ecommand. Without a parameter, the previous file is used. The t e efile can be disabled with the n o t e ecommand. Executing t e eagain re-enables logging.
u s ed b _ n a m e ,\ ud b _ n a m e

Use d b _ n a m eas the default database.


w a r n i n g s ,\ W

Enable display of warnings after each statement (if there are any). This command was added in MySQL 5.0.6. Here are a few tips about the p a g e rcommand: You can use it to write to a file and the results go only to the file:
m y s q l >p a g e rc a t>/ t m p / l o g . t x t

You can also pass any options for the program that you want to use as your pager:
m y s q l >p a g e rl e s sniS

In the preceding example, note the Soption. You may find it very useful for browsing wide query
dev.mysql.com/doc/refman/5.0/en/mysql-commands.html 4/7

24/09/2013

MySQL :: MySQL 5.0 Reference Manual :: 4.5.1.2 mysql Commands

results. Sometimes a very wide result set is difficult to read on the screen. The Soption to less can make the result set much more readable because you can scroll it horizontally using the left-arrow and right-arrow keys. You can also use Sinteractively within less to switch the horizontal-browse mode on and off. For more information, read the less manual page:
s h e l l >m a nl e s s

The Fand Xoptions may be used with less to cause it to exit if output fits on one screen, which is convenient when no scrolling is necessary:
m y s q l >p a g e rl e s sniSFX

You can specify very complex pager commands for handling query output:
m y s q l >p a g e rc a t|t e e/ d r 1 / t m p / r e s . t x t\
|t e e/ d r 2 / t m p / r e s 2 . t x t|l e s sniS

In this example, the command would send query results to two files in two different directories on two different file systems mounted on / d r 1and / d r 2 , yet still display the results onscreen using less. You can also combine the t e eand p a g e rfunctions. Have a t e efile enabled and p a g e rset to less, and you are able to browse the results using the less program and still have everything appended into a file the same time. The difference between the Unix t e eused with the p a g e rcommand and the mysql built-in t e ecommand is that the built-in t e eworks even if you do not have the Unix tee available. The built-in t e e also logs everything that is printed on the screen, whereas the Unix tee used with p a g e rdoes not log quite that much. Additionally, t e efile logging can be turned on and off interactively from within mysql. This is useful when you want to log some queries to a file, but not others. The p r o m p tcommand reconfigures the default m y s q l >prompt. The string for defining the prompt can contain the following special sequences. Option
\ c \ D \ d \ h \ l \ m \ n \ O \ o \ P \ p \ R \ r \ S \ s \ t \ U
dev.mysql.com/doc/refman/5.0/en/mysql-commands.html

Description
A counter that increments for each statement you issue The full current date The default database The server host The current delimiter (new in 5.0.25) Minutes of the current time A newline character The current month in three-letter format (Jan, Feb, ) The current month in numeric format am/pm The current TCP/IP port or socket file The current time, in 24-hour military time (023) The current time, standard 12-hour time (112) Semicolon Seconds of the current time A tab character

Your full u s e r _ n a m e @ h o s t _ n a m eaccount name

5/7

24/09/2013

MySQL :: MySQL 5.0 Reference Manual :: 4.5.1.2 mysql Commands

Your full u s e r _ n a m e @ h o s t _ n a m eaccount name


\ u \ v \ w \ Y \ y \ _ \ \ ' \ " \ \ \ x Your user name The server version The current day of the week in three-letter format (Mon, Tue, ) The current year, four digits The current year, two digits A space A space (a space follows the backslash) Single quote Double quote A literal \ backslash character x , for any x not listed above

You can set the prompt in several ways: Use an environment variable. You can set the M Y S Q L _ P S 1environment variable to a prompt string. For example:
s h e l l >e x p o r tM Y S Q L _ P S 1 = " ( \ u @ \ h )[ \ d ] >"

Use a command-line option. You can set the p r o m p toption on the command line to mysql. For example:
s h e l l >m y s q lp r o m p t = " ( \ u @ \ h )[ \ d ] >" ( u s e r @ h o s t )[ d a t a b a s e ] >

Use an option file. You can set the p r o m p toption in the [ m y s q l ]group of any MySQL option file, such as / e t c / m y . c n for the . m y . c n ffile in your home directory. For example:
[ m y s q l ] p r o m p t = ( \ \ u @ \ \ h )[ \ \ d ] > \ \ _

In this example, note that the backslashes are doubled. If you set the prompt using the p r o m p t option in an option file, it is advisable to double the backslashes when using the special prompt options. There is some overlap in the set of permissible prompt options and the set of special escape sequences that are recognized in option files. (The rules for escape sequences in option files are listed in Section 4.2.3.3, Using Option Files.) The overlap may cause you problems if you use single backslashes. For example, \ sis interpreted as a space rather than as the current seconds value. The following example shows how to define a prompt within an option file to include the current time in H H : M M : S S >format:
[ m y s q l ] p r o m p t = " \ \ r : \ \ m : \ \ s >"

Set the prompt interactively. You can change your prompt interactively by using the p r o m p t(or \ R ) command. For example:
m y s q l >p r o m p t( \ u @ \ h )[ \ d ] > \ _
dev.mysql.com/doc/refman/5.0/en/mysql-commands.html 6/7

24/09/2013

MySQL :: MySQL 5.0 Reference Manual :: 4.5.1.2 mysql Commands

P R O M P Ts e tt o' ( \ u @ \ h )[ \ d ] > \ _ ' ( u s e r @ h o s t )[ d a t a b a s e ] > ( u s e r @ h o s t )[ d a t a b a s e ] >p r o m p t R e t u r n i n gt od e f a u l tP R O M P To fm y s q l > m y s q l >


Copyright 1997, 2013, Oracle and/or its affiliates. All rights reserved. Legal Notices

Previous / Next / Up / Table of Contents

User Comments
Posted by Rami Jamleh on April 5 2011 5:56pm [Delete] [Edit]

this is a very useful prompt prompt="\R:\m:\\s[\d](\l)> " \R time 24 hours or use \\r instead for 12 hours you can concatenate \\r with \P for am/pm \m minutes \\s seconds \d current database \l current delimiter if your interested add \U not \u@\h for user and host it's you who choose.
Posted by Keith Shum on January 8 2012 5:51am [Delete] [Edit]

'prompt=\u@\h>\_' does not equal to 'prompt=\U>\_' Since 'The server host' does not equal to 'host_name'... be careful! =) Add your own comment. Top / Previous / Next / Up / Table of Contents 2013, Oracle Corporation and/or its affiliates

dev.mysql.com/doc/refman/5.0/en/mysql-commands.html

7/7

Вам также может понравиться