DB2常用命令

2021-08-29 21:22:24 字數 3938 閱讀 1621

啟動db2服務:db2start

關閉db2服務: db2stop

一、載入資料:

1、 以預設分隔符載入,預設為「,」號

db2 "import from btpoper.txt of del insert into btpoper"

2、 以指定分隔符「|」載入

db2 "import from btpoper.txt of del modified by coldel| insert into btpoper"

二、解除安裝資料:

1、 解除安裝乙個表中全部資料

db2 "export to btpoper.txt of del select * from btpoper"

db2 "export to btpoper.txt of del modified by coldel| select * from btpoper"

2、 帶條件解除安裝乙個表中資料

db2 "export to btpoper.txt of del select * from btpoper where brhid='907020000'"

db2 "export to cmmcode.txt of del select * from cmmcode where codtp='01'"

db2 "export to cmmcode.txt of del modified by coldel| select * from cmmcode where codtp='01'"

三、查詢資料結構及資料:

db2 "select * from btpoper"

db2 "select * from btpoper where brhid='907020000' and oprid='0001'"

db2 "select oprid,oprnm,brhid,passwd from btpoper"

db2 describe table 表名

四、刪除表中資料:

db2 "delete from btpoper"

db2 "delete from btpoper where brhid='907020000' or brhid='907010000'"

五、修改表中資料:

db2 "update svmmst set prtlines=0 where brhid='907010000' and jobtp='02'"

db2 "update svmmst set prtlines=0 where jobtp='02' or jobtp='03'"

六、聯接資料庫

db2 connect to btpdbs

七、清除資料庫聯接

db2 connect reset 斷開資料庫連線

db2 terminate 斷開資料庫連線

八、備份資料庫

1、 db2 backup db btpdbs

2、 db2move btpdbs export

db2look -d btpdbs -e -x [-a] -o crttbl.sql

九、恢復資料庫

1、 db2 restore db btpdbs without rolling forward

2、 db2 -tvf crtdb.sql

crtdb.sql檔案內容:create db btpdbs on /db2catalog

db2 -stvf crttbl.sql

db2move btpdbs import

十、db2幫助命令:

db2 ?

db2 ? restroe

db2 ? sqlcode (例:db2 ? sql0803) 注:code必須為4位數,不夠4位,前面補0

十一、bind命令:將應用程式與資料庫作一**,每次恢復資料庫後,建議都要做一次bind

(1) db2 bind br8200.bnd

(2) /btp/bin/bndall /btp/bnd

/btp/bin/bndall /btp/tran/bnd

十二、檢視資料庫引數:

db2 get dbm cfg

db2 get db cfg for btpdbs

十三、修改資料庫引數:

db2 update db cfg for btpdbs using logbufsz 20

db2 update db cfg for btpdbs using logfilsiz 5120

改完後,應執行以下命令使其生效:

db2 stop

db2 start

補充:db2 set schema btp 修改當前模式為"btp"

db2 list tablespaces show detail 檢視當前資料庫表空間分配狀況

db2 list tablespace containers for 2 show detail 檢視tablespace id=2使用容器所在目錄

db2 list db directory 列出所有資料庫

db2 list active databases 列出所有活動的資料庫

db2 list tables for all 列出當前資料庫下所有的表

db2 list tables for schema btp 列出當前資料庫中schema為btp的表

db2 list tablespaces show detail 顯示資料庫空間使用情況

db2 list packages for all

db2 "import from tab76.ixf of ixf commitcount 5000 insert into achact"

db2 "create table achact_t like achact"

db2 "rename table achact_t to achact"

db2 "insert into achact_t select * from achact where txndt>=(select lstpgdt from

acmact where actno=achact.actno)"

db2 get snapshot for dynaimic sql on jining

刪除乙個例項:

# cd /usr/lpp/db2_07_01/instance

# ./db2idrop instname

列出所有db2例項:

# cd /usr/lpp/db2_07_01/bin

# ./db2ilist

為資料庫建立編目

$ db2 catalog db btpdbs on /db2catalog

取消已編目的資料庫btpdbs

$ db2 uncatalog db btpdbs

檢視版本

# db2level

顯示當前資料庫管理例項

$ db2 get instance

設定例項系統啟動時是否自動啟動。

$ db2iauto -on 自動啟動

$ db2iauto -off 不自動啟動

資料庫優化命令:

reorg、runstats

當資料庫經過一段時間使用,資料空間會變得越來越龐大。一些delete掉

的資料仍存放在資料庫中,占用資料空間,影響系統效能。因此需要定期

執行reorg、runstats命令,清除已delete的資料,優化資料結構。

db2 reorg table 表名

db2 runstats on table 表名 with distribution and indexes all

因為要優化的表比較多,所以在/btp/bin目錄下提供了乙個sh程式runsall,

可在當天業務結束後,執行runsall,對資料庫進行優化

db2在命令列中登入遠端伺服器

connect to pas user pas using 1234

其中to後面的pas是資料庫,user 後面的pas 是使用者,using 後面的是密碼

DB2常用命令

常用操作 db2 list db directory db2 connect to user using db2ilist 顯示當前例項名 db2 list tables 顯示當前例項下的所有表 db2 list tablespaces 顯示表空間 db2pd db tablespaces 檢視表空...

DB2常用命令

1 db2 list node directory 2 db2 list node directory show detail 3 db2 catalog tcpip node wsii remote 9.181.139.155 server 50000 4 db2 catalog database...

DB2常用命令

例項 clp 命令描述 db2start 啟動資料庫管理器例項。db2stop 停止資料庫管理器例項。get dbm cfg 返回資料庫管理器配置設定。get dbm cfg show detail 顯示資料庫管理器引數的當前值和延遲值 從 v8 起 1update dbm cfg using 將資...