mysql笔记(Entering Queries)

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.

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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值