db2常用命令
命令大全
- 创建数据库(并设定编码):create database <数据库名> using codeset utf-8 territory CN
- 连接本地数据库:connect to <数据库名>
- 连接远端数据库:connect to <数据库名> user <用户名> using <密码>
DB2命令行处理器常用命令
1. 实例
|
CLP 命令 |
描述 |
|
db2start |
启动数据库管理器实例。 |
|
db2stop |
停止数据库管理器实例。 |
|
get dbm cfg |
返回数据库管理器配置设置。 |
|
get dbm cfg show detail |
显示数据库管理器参数的当前值和延迟值(从 V8 起)。 |
|
1update dbm cfg using <p> <v> |
将数据库管理器配置参数 <p> 更新为值 <v>。 |
|
get instance |
返回 DB2INSTANCE 环境变量的值。 |
|
list active databases |
列出活动的数据库和连接数。 |
|
list application [show detail] |
返回关于当前连接的应用程序的信息。 |
|
force application (h1 [,h2,..,hn]) |
根据句柄号与特定应用程序断开连接。 |
|
force application all |
断开所有应用程序与数据库的连接。 |
|
attach to <node> user <userid> using <pwd> |
以用户 <userid> 通过使用密码 <pwd> 与标识为 <node> 的远程实例连接。 |
数据库
|
create database <dbname> |
创建名为 <dbname> 的数据库。 |
|
activate database <dbname> |
显式地激活数据库。 |
|
deactivate database <dbname> |
显式地使数据库失效。 |
|
connect to <dbname> [ [user <userid>] using <pwd>] |
根据需要,显式地以用户 <userid> 和密码 <pwd> 与数据库 <dbname> 连接。 |
|
1update dbm cfg using <p> <v> |
将数据库管理器配置参数 <p> 更新为值 <v>。 |
|
connect reset |
断开与当前数据库的连接。 |
|
get db cfg show detail |
显示数据库配置参数的当前值和延迟值(仅适用于 V8)。 |
|
get db cfg for <dbname> |
返回数据库 <dbname> 的数据库配置设置。 |
|
update db cfg for <dbname> using <p> <v> |
将数据库 <dbname> 的数据库配置参数 <p> 更新为值 <v>。 |
|
list tables[for {user | all | system | schema <schemaname>}][show detail] |
列出数据库中的表。如果没有指定任何参数,则缺省情况是列出当前用户的表。 |
|
describe table <tablename> |
显示一个表或视图的列信息。 |
|
list tablespaces [show detail] |
显示表空间的标识、名称、类型、内容和状态。 |
|
list tablespace containers for <tablespace_id> [show detail] |
显示用 <tablespace_id> 指定的表空间的容器信息。 |
|
quiesce tablespaces for table <tablename> reset |
将表空间的状态复位成正常(normal)。 |
连接性
|
catalog [admin] <protocol> node … |
为协议 <protocol> 在节点目录中创建一项。 |
|
list [admin] node directory |
返回节点目录的内容。 |
|
catalog database <dbname>… |
为数据库 <dbname> 在数据库目录中创建一项。 |
|
list database directory [on <path>] |
返回数据库目录的内容。 |
性能
|
get monitor switches |
返回会话监控开关的状态。 |
|
update monitor switches using <monitor> <on|off> |
为 <monitor> 设置会话监控开关的状态。 |
|
reset monitor all |
复位性能监控程序值。 |
|
get snapshot for dbm |
返回实例级别的性能信息。 |
|
get snapshot for all on <dbname> |
为数据库 <dbname> 在数据库级别返回所有性能信息。 |
|
get snapshot for dynamic sql on <dbname> |
返回动态 SQL 高速缓存的内容。 |
|
runstats on table <tbschema>.<tbname> |
收集表 <tbname> 的统计信息。表名必须是用 <dbschema> 全限定的。 |
|
reorgchk on table all |
确定是否需要对表进行重组。这对于对所有表自动执行 runstats 很有用。 |
|
reorg table <tablename> |
通过重构行来消除“碎片”数据并压缩信息,对表进行重组。 |
管理
|
export |
将数据库数据抽取到一个平面文件中。 |
|
import |
通过使用 IMPORT 实用程序,将数据导入到数据库。 |
|
load query table <tbname> [to local-message-file][nosummary | summaryonly] [showdelta] |
返回 LOAD 实用程序的进度。 |
|
backup database <dbname> [to <path>] |
执行数据库备份。 |
|
restore database <dbname> [from <path>] |
执行数据库恢复。 |
|
get health snapshot for dbm |
返回实例的正常快照信息(仅适用于 V8)。 |
|
get health snapshot for all on <dbname> |
返回数据库 <dbname> 的所有正常快照(仅适用于 V8)。 |
管理服务器
|
get admin cfg |
返回管理服务器的配置设置。 |
|
update admin cfg using <p> <v> |
将管理服务器配置参数 <p> 更新为值 <v>。 |
应用程序开发
|
get routine into <filename> from [specific] procedure <routine-name>[hide body] |
将 SQL 过程抽取成二进制文件。 |
|
put routine from <filename> [owner <newowner>[use registers]] |
从二进制文件部署 SQL 过程。 |
浙公网安备 33010602011771号