操作简介及常用命令

首先登陆我们的MySQL:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Sing-2:local Sing$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

可以看到第三行提示我们,命令的结尾为“;”或者“\g”,其次,倒数第二行提示我们可以通过“help”或者“\h”来获取帮助,通过“\c”来取消输入的命令,最后的“mysql>”为命令提示符,我们可以退出mysql来修改他:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Sing-2:local Sing$ mysql -uroot -p --prompt=sing
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

sing

通过 prompt=sing 可以看到我们已经修改为sing,我们也可以在登录之后通过 prompt 命令来修改

1
2
3
mysql> prompt sing>
PROMPT set to 'sing>'
sing>

常用命令

  • SELECT VERSION();   显示当前版本
  • SELECT NOW();     显示当前日期时间
  • SELECT USER();    显示当前用户
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
sing> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 5.7.19 |
+-----------+
1 row in set (0.00 sec)

sing> SELECT NOW();
+---------------------+
| NOW() |
+---------------------+
| 2017-08-15 22:05:46 |
+---------------------+
1 row in set (0.00 sec)

sing> SELECT USER();
+----------------+
| USER() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

sing>

MySQL语句的规范

  • 关键字与函数名称全部大写
  • 数据库名称、表名称、字段名称等全部小写
  • SQL语句必须以分隔符结尾
  • SQL语句支持折行操作,只有不把单词、标记或引号字符串分割
  • 数据库名称、表名称、字段名称不要使用MqSQL保留字,如果需要,必须用反引号(‘’)括起来。