Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1601925
  • 博文数量: 184
  • 博客积分: 3044
  • 博客等级: 中校
  • 技术积分: 2467
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-25 15:04
文章分类

全部博文(184)

文章存档

2022年(4)

2021年(3)

2020年(1)

2019年(5)

2018年(13)

2017年(6)

2016年(10)

2015年(11)

2014年(11)

2013年(13)

2012年(23)

2011年(25)

2010年(2)

2008年(1)

2007年(5)

2006年(51)

分类:

2006-11-17 00:33:28

DB2 命令行处理器(CLP)中的常用命令
 
 
作者: applezhang1314  发布日期: 2006-11-08    查看数: 34   出自:
 
 

以下是最常用的 DB2 CLP 命令的快速参考方括号中的参数是可选参数,尖括号中的内容表示变量。例如,CONNECT 的语法是:

connect to
[ [user ] using ]这意味着,通过 CONNECT 命令以 user1 身份使用密码 mypass 与数据库 sample 连接可以有下列形式:

Connect to sample
Connect to sample user user1
Connect to sample user user1 using mypass
根据命令的作用域来组织所有命令。对于任何 CLP 命令,您都可以输入加上前缀问号(“?”)的关键字,以查看其完整的语法。实例

CLP 命令描述
db2start 启动数据库管理器实例。
db2stop 停止数据库管理器实例。
get dbm cfg 返回数据库管理器配置设置。
get dbm cfg show detail 显示数据库管理器参数的当前值和延迟值(从 V8 起)。
update dbm cfg using

将数据库管理器配置参数

更新为值 。
get instance 返回 DB2INSTANCE 环境变量的值。
list active databases 列出活动的数据库和连接数。
list application [show detail] 返回关于当前连接的应用程序的信息。
force application (h1 [,h2,..,hn]) 根据句柄号与特定应用程序断开连接。
force application all 断开所有应用程序与数据库的连接。
attach to user using 以用户 通过使用密码 与标识为 的远程实例连接。数据库

create database 创建名为 的数据库。
activate database 显式地激活数据库。
deactivate database 显式地使数据库失效。
connect to
[ [user ] using ] 根据需要,显式地以用户 和密码 与数据库 连接。
update dbm cfg using

将数据库管理器配置参数

更新为值 。
connect reset 断开与当前数据库的连接。
get db cfg show detail 显示数据库配置参数的当前值和延迟值(仅适用于 V8)。
get db cfg for 返回数据库 的数据库配置设置。
update db cfg for using

将数据库 的数据库配置参数

更新为值 。
list tables[for {user | all | system | schema }][show detail] 列出数据库中的表。如果没有指定任何参数,则缺省情况是列出当前用户的表。
describe table 显示一个表或视图的列信息。
list tablespaces [show detail] 显示表空间的标识、名称、类型、内容和状态。
list tablespace containers for [show detail] 显示用 指定的表空间的容器信息。
quiesce tablespaces for table reset 将表空间的状态复位成正常(normal)。连接性

catalog [admin] node … 为协议 在节点目录中创建一项。
list [admin] node directory 返回节点目录的内容。
catalog database … 为数据库 在数据库目录中创建一项。
list database directory [on ] 返回数据库目录的内容。性能

get monitor switches 返回会话监控开关的状态。
update monitor switches using 为 设置会话监控开关的状态。
reset monitor all 复位性能监控程序值。
get snapshot for dbm 返回实例级别的性能信息。
get snapshot for all on 为数据库 在数据库级别返回所有性能信息。
get snapshot for dynamic sql on 返回动态 SQL 高速缓存的内容。
runstats on table . 收集表 的统计信息。表名必须是用 全限定的。
reorgchk on table all 确定是否需要对表进行重组。这对于对所有表自动执行 runstats 很有用。
reorg table 通过重构行来消除“碎片”数据并压缩信息,对表进行重组。管理

export 将数据库数据抽取到一个平面文件中。
import 通过使用 IMPORT 实用程序,将数据导入到数据库。
load query table
[to local-message-file][nosummary | summaryonly] [showdelta] 返回 LOAD 实用程序的进度。
backup database [to ] 执行数据库备份。
restore database [from ] 执行数据库恢复。
get health snapshot for dbm 返回实例的正常快照信息(仅适用于 V8)。
get health snapshot for all on 返回数据库 的所有正常快照(仅适用于 V8)。管理服务器

get admin cfg 返回管理服务器的配置设置。
update admin cfg using

将管理服务器配置参数

更新为值 。应用程序开发

get routine into from [specific] procedure [hide body] 将 SQL 过程抽取成二进制文件。
put routine from [owner [use registers]] 从二进制文件部署 SQL 过程。
 
 
1.启动数据库
     db2start
2.停止数据库
     db2stop
3.连接数据库
     db2 connect to o_yd user db2 using pwd
4.读数据库管理程序配置
     db2 get dbm cfg
5.写数据库管理程序配置
     db2 update dbm cfg using 参数名 参数值
6.读数据库的配置
     db2 connect to o_yd user db2 using pwd
     db2 get db cfg for o_yd
7.写数据库的配置
     db2 connect to o_yd user db2 using pwd
     db2 update db cfg for o_yd using 参数名 参数值
8.关闭所有应用连接
     db2 force application all
     db2 force application ID1,ID2,,,Idn MODE ASYNC
     (db2 list application for db o_yd show detail)
9.备份数据库
     db2 force application all
     db2 backup db o_yd to d:
     (db2 initialize tape on \\.\tape0)
     (db2 rewind tape on \\.\tape0)
     db2 backup db o_yd to \\.\tape0
10.恢复数据库
        db2 restore db o_yd from d: to d:
        db2 restore db o_yd from \\.\tape0 to d:
11.绑定存储过程
        db2 connect to o_yd user db2 using pwd
        db2 bind c:\dfplus.bnd
  拷贝存储过程到服务器上的C:\sqllib\function目录中
12.整理表
        db2 connect to o_yd user db2 using pwd
        db2 reorg table ydd
        db2 runstats on table ydd with distribution and indexes all
13.导出表数据
         db2 export to c:\dftz.txt of del select * from dftz
        db2 export to c:\dftz.ixf of ixf select * from dftz
14.导入表数据
        import from c:\123.txt of del  insert into ylbx.czyxx
        db2 import to c:\dftz.txt of del commitcount 5000 messages  c:\dftz.msg insert into dftz
        db2 import to c:\dftz.ixf of ixf commitcount 5000 messages c:\dftz.msg insert into dftz
        db2 import to c:\dftz.ixf of ixf commitcount 5000 insert into dftz
        db2 import to c:\dftz.ixf of ixf commitcount 5000 insert_update into dftz
        db2 import to c:\dftz.ixf of ixf commitcount 5000 replace into dftz
        db2 import to c:\dftz.ixf of ixf commitcount 5000 create into dftz   (仅IXF)
        db2 import to c:\dftz.ixf of ixf commitcount 5000 replace_create into dftz  (仅IXF)
15.执行一个批处理文件
       db2 –tf 批处理文件名
      (文件中每一条命令用 ;结束)
16.自动生成批处理文件
         建文本文件:temp.sql
        select 'runstats on table DB2.' || tabname || ' with distribution and  detailed indexes all;' from syscat.tables where tabschema='DB2' and type='T';
        db2 –tf temp.sql>;runstats.sql
17.自动生成建表(视图)语句
        在服务器上:C:\sqllib\misc目录中
        db2 connect to o_yd user db2 using pwd
        db2look –d o_yd –u db2 –e –p –c c:\o_yd.txt
18.其他命令
        grant dbadm on database to user bb
19.select * from czyxx fetch first 1 rows only
20.db2look –d ylbx –u db2admin –w –asd –a –e –o a.txt21. 显示当前用户所有表
  list tables
22.列出所有的系统表
  list tables for system
23.查看表结构
  db2 describe select * from user.tables
阅读(1503) | 评论(0) | 转发(0) |
0

上一篇:db2备份

下一篇:Unix常用监控和管理命令

给主人留下些什么吧!~~