MySQL Chinese reference manual

Source: Internet
Author: User

Make sure you are connected to the server, as discussed in the previous section. Doing so itself will not select any database to work on, but that's fine. From this point of view, knowing a little bit about how to ask is more important than jumping to creating tables, loading data to them, and retrieving data from them. This section describes the basic principles of entering commands, using several queries, and you can try to get yourself to how MySQL works.

This is a simple command that asks the server to tell you its version number and current date. At mysql> prompt, enter the following command and press ENTER:

mysql> SELECT VERSION(), CURRENT_DATE;
+--------------+--------------+
| version()  | CURRENT_DATE |
+--------------+--------------+
| 3.22.20a-log | 1999-03-19  |
+--------------+--------------+
1 row in set (0.01 sec)
mysql>

This query explains several things about MySQL:

A command usually consists of an SQL statement followed by a semicolon. (Some exceptions do not require a semicolon.) The quit mentioned earlier were one of them. We'll see the rest later. )

When you send a command, MySQL sends it to the server and displays the result, then the other mysql> shows that it is ready to accept another command.

MySQL displays query output in a table (rows and columns). The first row contains the label for the column, followed by the query result. Usually, the column label is the name of the column you have taken from the database table. If you are retrieving an expression other than the value of a table column (as in the example just now), MySQL marks the column with the expression itself.

MySQL shows how many rows are returned, and how long the query takes to execute, which gives you a general idea of server performance. Because they represent clock time (not CPU or machine time), and because they are affected by such things as server load and network latency, these values are imprecise. (For brevity, the "Rows in the collection" are not shown in the remainder of this chapter.) )

Keywords can be entered in any uppercase and lowercase characters. The following queries are equivalent:

mysql> SELECT VERSION(), CURRENT_DATE;
mysql> select version(), current_date;
mysql> SeLeCt vErSiOn(), current_DATE;

Here's another query that says you can use MySQL as a simple calculator:

mysql> SELECT SIN(PI()/4), (4+1)*5;
+-------------+---------+
| SIN(PI()/4) | (4+1)*5 |
+-------------+---------+
|  0.707107 |   25 |
+-------------+---------+

The commands shown so far are fairly short, single-line statements. You can even enter multiple statements on a single line, ending each one with a semicolon:

mysql> SELECT VERSION(); SELECT NOW();
+--------------+
| version()  |
+--------------+
| 3.22.20a-log |
+--------------+

+---------------------+
| NOW()        |
+---------------------+
| 1999-03-19 00:15:33 |
+---------------------+

A command does not have to be all on a single line, so longer commands that require more than one line are not a problem. MySQL determines where your statement ends by looking for a terminating semicolon instead of finding the end of the input line. (in other words, MySQL accepts free form input: it collects input rows but executes them until it sees a semicolon.) )

Here is an example of a simple multiline statement:

mysql> SELECT
-> USER()
-> ,
-> CURRENT_DATE;
+--------------------+--------------+
| USER()       | CURRENT_DATE |
+--------------------+--------------+
| joesmith@localhost | 1999-03-18  |
+--------------------+--------------+

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.