2.7. Client Commands and SQL Statements


When you issue an SQL statement while running mysql, the program sends the statement to the MySQL server to be executed. SELECT, INSERT, UPDATE, and DELETE are examples of this type of input. mysql also understands a number of its own commands that aren't SQL statements. The QUIT and SOURCE commands that have already been discussed are examples of mysql commands. Another example is STATUS, which displays information about the current connection to the server, as well as status information about the server itself. Here is what a status display might look like:

 mysql> STATUS; mysql  Ver 14.12 Distrib 5.0.10-beta, for pc-linux-gnu (i686) Connection id:          14498 Current database:       world Current user:           myname@localhost SSL:                    Not in use Current pager:          stdout Using outfile:          '' Using delimiter:        ; Server version:         5.0.10-beta-log Protocol version:       10 Connection:             Localhost via UNIX socket Server characterset:    latin1 Db     characterset:    latin1 Client characterset:    latin1 Conn.  characterset:    latin1 UNIX socket:            /tmp/mysql.sock Uptime:                 37 days 16 hours 50 min 3 sec Threads: 4  Questions: 2439360  Slow queries: 854  Opens: 2523 Flush tables: 3  Open tables: 64  Queries per second avg: 0.749 -------------- 

A full list of mysql commands can be obtained using the HELP command.

mysql commands have both a long form and a short form. The long form is a full word (such as SOURCE, STATUS, or HELP). The short form consists of a backslash followed by a single character (such as \., \s, or \h). The long forms may be given in any lettercase. The short forms are case sensitive.

Unlike SQL statements, mysql commands cannot be entered over multiple lines. For example, if you issue a SOURCE input_file command to execute statements stored in a file, input_file must be given on the same line as SOURCE. It cannot be entered on the next line.

By default, the short command forms are recognized on any input line, except within quoted strings. The long command forms aren't recognized except at the mysql> primary prompt. For example, CLEAR and \c both clear (cancel) the current command, which is useful if you change your mind about issuing the statement that you're currently entering. But CLEAR isn't recognized after the first line of a multiple-line statement, so you should use \c instead. To have mysql recognize the long command names on any input line, invoke it with the--named-commands option.



MySQL 5 Certification Study Guide
MySQL 5.0 Certification Study Guide
ISBN: 0672328127
EAN: 2147483647
Year: 2006
Pages: 312

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net