2010的新年祝福:常用的一些DB2命令

使用DB2也有一段时间了,特总结了一些常用的命令,需要的XDJM们拿去吧,另祝大家新年快乐,虎虎生威,2010再创辉煌!

 

DB2监控命令

  查看锁表:
1、打开监视器
db2 update monitor switches using lock on
2、查看锁:
db2 get snapshot for locks on pcirs
3、查看应用程序:
db2 list applications
4、结束应用程序:
db2  "force  application (20,233) "

db2  "force  application (783)"  

5.查看表在何处建立
select tabname,tbspace from syscat.tables where tabschema='DB2INST3' and tabname='M_CCS_RPT_CUST_INFO';

 

连接:

1.启动数据库
     db2start
2.停止数据库
     db2stop
3.连接数据库
     db2 connect to 数据库名 user 用户名 using 密码,例如:db2 connect to ccportal user db2inst3 using 123
     如果已经在控制台输入了db2,则只需要输入connect to 数据库名 user 用户名 using 密码
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.导出表数据
windows环境:
   db2 export to c:/sss.txt of del select * from sss
   db2 export to c:/sss.ixf of ixf select * from sss
UNIX下:加入/grzxdb/temp/为目录
db2 export to /grzxdb/temp/m_ccs_rpt_loan_info.ixf of ixf select * from m_ccs_rpt_loan_info_7
db2 export to /grzxdb/temp/m_ccs_rpt_cust_info.ixf of ixf select * from m_ccs_rpt_cust_info_7
db2 export to /home/db2inst3/m_ccs_rpt_loan_info.ixf of ixf select * from m_ccs_rpt_loan_info

14.导入表数据
 db2 import from  /grzxdb/temp/m_ccs_rpt_loan_info.ixf of ixf commitcount 5000 insert into m_ccs_rpt_loan_info

 --假如已经把*.ixf文件上传到了同级目录,则直接输入以下语句即可
 db2 import from S_CHECK_CONFIG.ixf of ixf insert into s_check_config
 --如果你知道*.ixf文件的位置,则可使用以下语句
 db2 import from /home/db2inst3/pcirs/S_CHECK_CONFIG.ixf of ixf insert into s_check_config
15.执行一个批处理文件
       db2 –tf 批处理文件名
      (文件中每一条命令用 ;结束)
16.自动生成批处理文件
         建文本文件:temp.sql
        select 'runstats on table DB2.' || tabname || ' with distribution and  detailed indexes all&#59;' from syscat.tables where tabschema='DB2' and type='T'&#59;
        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
24. 删除日志
    运行:db2 get db cfg for testdb查看当前活动日志,假如为2323.LOG
    然后清除日志:db2 prune logfile testdb to 2323.LOG
    2323.LOG为当前活动日志
25.显示表空间详细信息

26.查看所有系统表
 db2 list tables for system
27.查看所有用户建立的表
   db2 list tables for user
28.#创建一个与数据库中某个表(t2)结构相同的新表(t1)
  db2 create table t1 like t2
  db2 list tablespaces show detail
29.查看表详细信息
  Linux或Unix下如何查看DB2所占用的端口号
#假设你已经用db2start启动了数据库管理器,并且通讯方式配置为TCP/IP。

#首先切换到db2inst1用户 su - db2inst1

#查找TCP/IP Service name :db2 get dbm cfg | grep -i service

#在/etc/services文件中找对应的端口号 grep db2c_db2inst1 /etc/services

#这是你将会看到这么一行从上一句的输出 db2c_db2inst1   50000/tcp

#其中50000就是db2数据库所占用的端口号

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值