1.Here is a simple query that asks the server to tell you its version number and the current date
mysql> SELECT VERSION(), CURRENT_DATE;
+-----------+--------------+
| VERSION() | CURRENT_DATE |
+-----------+--------------+
| 5.8.0-m17 | 2015-12-21 |
+-----------+--------------+
1 row in set (0.02 sec)
mysql>
2.Keywords may be entered in any lettercase. The following queries are equivalent
mysql> SELECT VERSION(), CURRENT_DATE;
mysql> select version(), current_date;
mysql> SeLeCt vErSiOn(), current_DATE;
3.Here is another query. It demonstrates that you can use mysql as a simple calculator
mysql> SELECT SIN(PI()/4), (4+1)*5;
+------------------+---------+
| SIN(PI()/4) | (4+1)*5 |
+------------------+---------+
| 0.70710678118655 | 25 |
+------------------+---------+
4.The queries shown thus far have been relatively short, single-line statements. You can even enter multiple statements on a single line. Just end each one with a semicolon:
mysql> SELECT VERSION(); SELECT NOW();
+-----------+
| VERSION() |
+-----------+
| 5.8.0-m17 |
+-----------+
+---------------------+
| NOW() |
+---------------------+
| 2015-12-21 14:06:10 |
+---------------------+
5.mysql accepts free-format input: it collects input lines but does not execute them until it sees the semicolon
mysql> SELECT
-> USER()
-> ,
-> CURRENT_DATE;
+---------------+--------------+
| USER() | CURRENT_DATE |
+---------------+--------------+
| jon@localhost | 2015-12-21 |
+---------------+--------------+
6.If you decide you do not want to execute a query that you are in the process of entering, cancel it by typing \c:
mysql> SELECT
-> USER()
-> \c
mysql>
7.The following table shows each of the prompts you may see and summarizes what they mean about the state that mysql is in.
Prompt | Mearning |
---|---|
-> | Ready for new query |
‘> | Waiting for next line, waiting for completion of a string that began with a single quote (‘) |
“> | Waiting for next line, waiting for completion of a string that began with a double quote (“) |
`> | Waiting for next line, waiting for completion of an identifier that began with a backtick (`) |
/*> |
8.Multiple-line statements commonly occur by accident when you intend to issue a query on a single line, but forget the terminating semicolon. In this case, mysql waits for more input:
mysql> SELECT USER()
->
Enter a semicolon to complete the statement, and mysql executes it
mysql> SELECT USER()
-> ;
+---------------+
| USER() |
+---------------+
| jon@localhost |
+---------------+
9.The ‘> and “> prompts occur during string collection (another way of saying that MySQL is waiting for completion of a string).
mysql> SELECT * FROM my_table WHERE name = 'Smith AND age < 30;
'>
At this point, what do you do?
mysql> SELECT * FROM my_table WHERE name = 'Smith AND age < 30;
'> '\c
mysql>
参考于官方文档:3.2 Entering Queries