** 转到db2官方网站: **
以下是最常用的 DB2 CLP 命令的快速参考。虽然不是一份完整的参考,但这篇文档对于任何刚接触 DB2 的用户来说,可以证明是案边有价值的参考材料。反馈意见可以发送至 [email protected] 。
方括号中的参数是可选参数,尖括号中的内容表示变量。例如,CONNECT 的语法是:
connect to
1<dbname>
2 [ [user <userid>] using <pwd>]
3
4这意味着,通过 CONNECT 命令以 user1 身份使用密码 mypass 与数据库 sample 连接可以有下列形式:
5
6
7 Connect to sample
8 Connect to sample user user1
9 Connect to sample user user1 using mypass
10
11
12根据命令的作用域来组织所有命令。对于任何 CLP 命令,您都可以输入加上前缀问号(“?”)的关键字,以查看其完整的语法。
13
14祝愉快!
15
16**实例**
17
18
19> **CLP 命令** | **描述**
20> ---|---
21> db2start | 启动数据库管理器实例。
22> db2stop | 停止数据库管理器实例。
23> get dbm cfg | 返回数据库管理器配置设置。
24> get dbm cfg show detail | 显示数据库管理器参数的当前值和延迟值(从 V8 起)。
25> 1update dbm cfg using <p> <v> | 将数据库管理器配置参数 <p> 更新为值 <v>。
26> get instance | 返回 DB2INSTANCE 环境变量的值。
27> list active databases | 列出活动的数据库和连接数。
28> list application [show detail] | 返回关于当前连接的应用程序的信息。
29> force application (h1 [,h2,..,hn]) | 根据句柄号与特定应用程序断开连接。
30> force application all | 断开所有应用程序与数据库的连接。
31> attach to <node> user <userid> using <pwd> | 以用户 <userid> 通过使用密码 <pwd> 与标识为 <node> 的远程实例连接。
32
33**数据库**
34
35
36> create database <dbname> | 创建名为 <dbname> 的数据库。
37> ---|---
38> activate database <dbname> | 显式地激活数据库。
39> deactivate database <dbname> | 显式地使数据库失效。
40> connect to <dbname>
41> [ [user <userid>] using <pwd>] | 根据需要,显式地以用户 <userid> 和密码 <pwd> 与数据库 <dbname> 连接。
42> 1update dbm cfg using <p> <v> | 将数据库管理器配置参数 <p> 更新为值 <v>。
43> connect reset | 断开与当前数据库的连接。
44> get db cfg show detail | 显示数据库配置参数的当前值和延迟值(仅适用于 V8)。
45> get db cfg for <dbname> | 返回数据库 <dbname> 的数据库配置设置。
46> update db cfg for <dbname> using <p> <v> | 将数据库 <dbname> 的数据库配置参数 <p> 更新为值 <v>。
47> list tables[for {user | all | system | schema <schemaname>}][show detail] | 列出数据库中的表。如果没有指定任何参数,则缺省情况是列出当前用户的表。
48> describe table <tablename> | 显示一个表或视图的列信息。
49> list tablespaces [show detail] | 显示表空间的标识、名称、类型、内容和状态。
50> list tablespace containers for <tablespace_id> [show detail] | 显示用 <tablespace_id> 指定的表空间的容器信息。
51> quiesce tablespaces for table <tablename> reset | 将表空间的状态复位成正常(normal)。
52
53**连接性**
54
55
56> catalog [admin] <protocol> node … | 为协议 <protocol> 在节点目录中创建一项。
57> ---|---
58> list [admin] node directory | 返回节点目录的内容。
59> catalog database <dbname>… | 为数据库 <dbname> 在数据库目录中创建一项。
60> list database directory [on <path>] | 返回数据库目录的内容。
61
62**性能**
63
64
65> get monitor switches | 返回会话监控开关的状态。
66> ---|---
67> update monitor switches using <monitor> <on|off> | 为 <monitor> 设置会话监控开关的状态。
68> reset monitor all | 复位性能监控程序值。
69> get snapshot for dbm | 返回实例级别的性能信息。
70> get snapshot for all on <dbname> | 为数据库 <dbname> 在数据库级别返回所有性能信息。
71> get snapshot for dynamic sql on <dbname> | 返回动态 SQL 高速缓存的内容。
72> runstats on table <tbschema>.<tbname> | 收集表 <tbname> 的统计信息。表名必须是用 <dbschema> 全限定的。
73> reorgchk on table all | 确定是否需要对表进行重组。这对于对所有表自动执行 runstats 很有用。
74> reorg table <tablename> | 通过重构行来消除“碎片”数据并压缩信息,对表进行重组。
75
76**管理**
77
78
79> export | 将数据库数据抽取到一个平面文件中。
80> ---|---
81> import | 通过使用 IMPORT 实用程序,将数据导入到数据库。
82> load query table <tbname>
83> [to local-message-file][nosummary | summaryonly] [showdelta] | 返回 LOAD 实用程序的进度。
84> backup database <dbname> [to <path>] | 执行数据库备份。
85> restore database <dbname> [from <path>] | 执行数据库恢复。
86> get health snapshot for dbm | 返回实例的正常快照信息(仅适用于 V8)。
87> get health snapshot for all on <dbname> | 返回数据库 <dbname> 的所有正常快照(仅适用于 V8)。
88
89**管理服务器**
90
91
92> get admin cfg | 返回管理服务器的配置设置。
93> ---|---
94> update admin cfg using <p> <v> | 将管理服务器配置参数 <p> 更新为值 <v>。
95
96**应用程序开发**
97
98
99> get routine into <filename> from [specific] procedure <routine-name>[hide body] | 将 SQL 过程抽取成二进制文件。
100> ---|---
101> put routine from <filename> [owner <newowner>[use registers]] | 从二进制文件部署 SQL 过程。</newowner></filename></routine-name></filename></v></p></v></p></dbname></dbname></path></dbname></path></dbname></tbname></tablename></dbschema></tbname></tbname></tbschema></dbname></dbname></dbname></monitor></on|off></monitor></path></dbname></dbname></protocol></protocol></tablename></tablespace_id></tablespace_id></tablename></schemaname></v></p></dbname></v></p></dbname></dbname></dbname></v></p></v></p></dbname></pwd></userid></pwd></userid></dbname></dbname></dbname></dbname></dbname></node></pwd></userid></pwd></userid></node></v></p></v></p></pwd></userid></dbname>