linux中如何使用db2命令

上传人:第*** 文档编号:32688113 上传时间:2018-02-12 格式:DOC 页数:21 大小:77KB
返回 下载 相关 举报
linux中如何使用db2命令_第1页
第1页 / 共21页
linux中如何使用db2命令_第2页
第2页 / 共21页
linux中如何使用db2命令_第3页
第3页 / 共21页
linux中如何使用db2命令_第4页
第4页 / 共21页
linux中如何使用db2命令_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《linux中如何使用db2命令》由会员分享,可在线阅读,更多相关《linux中如何使用db2命令(21页珍藏版)》请在金锄头文库上搜索。

1、DB2 数据库命令简介1启动数据库db2start2停止数据库db2stop3连接数据库db2 connect to o_yd user db2 using pwd4读数据库管理程序配置db2 get dbm cfg5写数据库管理程序配置db2 update dbm cfg using 参数名 参数值6读数据库的配置db2 connect to o_yd user db2 using pwddb2 get db cfg for o_yd7写数据库的配置db2 connect to o_yd user db2 using pwddb2 update db cfg for o_yd using 参

2、数名 参数值8关闭所有应用连接db2 force application alldb2 force application ID1,ID2,Idn MODE ASYNC(db2 list application for db o_yd show detail)9备份数据库db2 force application alldb2 backup db o_yd to d:(db2 initialize tape on .tape0)(db2 rewind tape on .tape0)db2 backup db o_yd to .tape010恢复数据库db2 restore db o_yd fr

3、om d: to d:db2 restore db o_yd from .tape0 to d:11绑定存储过程db2 connect to o_yd user db2 using pwddb2 bind c:dfplus.bnd拷贝存储过程到服务器上的 C:sqllibfunction 目录中12整理表db2 connect to o_yd user db2 using pwddb2 reorg table ydddb2 runstats on table ydd with distribution and indexes all13导出表数据db2 export to c:dftz.txt

4、 of del select * from dftzdb2 export to c:dftz.ixf of ixf select * from dftz14导入表数据import from c:123.txt of del insert into ylbx.czyxxdb2 import to c:dftz.txt of del commitcount 5000 messages c:dftz.msg insert into dftzdb2 import to c:dftz.ixf of ixf commitcount 5000 messages c:dftz.msg insert into

5、dftzdb2 import to c:dftz.ixf of ixf commitcount 5000 insert into dftzdb2 import to c:dftz.ixf of ixf commitcount 5000 insert_update into dftzdb2 import to c:dftz.ixf of ixf commitcount 5000 replace into dftzdb2 import to c:dftz.ixf of ixf commitcount 5000 create into dftz (仅 IXF)db2 import to c:dftz

6、.ixf of ixf commitcount 5000 replace_create into dftz (仅 IXF)15执行一个批处理文件db2 -tf 批处理文件名(文件中每一条命令用 ;结束)16自动生成批处理文件建文本文件:temp.sqlselect runstats on table DB2. | tabname | with distribution and detailed indexes all;from syscat.tables where tabschema=DB2 and type=T;db2 -tf temp.sqlrunstats.sql17自动生成建表(视图

7、)语句在服务器上:C:sqllibmisc 目录中db2 connect to o_yd user db2 using pwddb2look -d o_yd -u db2 -e -p -c c:o_yd.txt18其他命令grant dbadm on database to user bb19select * from czyxx fetch first 1 rows only20db2look -d ylbx -u db2admin -w -asd -a -e -o a.txt21. 显示当前用户所有表list tables22.列出所有的系统表list tables for system2

8、3.查看表结构db2 describe select * from user.tables一、基础篇1、db2 connect to -连接到 本地 数据库名db2 connect to user using -连接到 远端 数据库2、 db2 force application all -强迫所有应用断开数据库连接3、db2 backup db db2name -备份整个数据库数据db2 restore db -还原数据库4、db2 list application -查看所有连接(需要连接到具体数据库才能查看)5、db2start -启动数据库db2stop -停止数据库6、create

9、database using codeset utf-8 territory CN -创建数据库使用utf-8 编码7、db2 catalog 命令db2 catalog tcpip node remote server -把远程数据库映射到本地接点一般为 50000db2 catalog db as at node PUB11 -远程数据库名称到本地接点db2 CONNECT TO user using -连接本地接点访问远程数据库8、数据库导出db2look -d -u -e -o .sql -导出数据库的表结构,其中用户空间一般为 db2admin/db2inst1db2look -d

10、-u -t -e -o .sql -导出数据库中表 1 和表 2 的表结构db2move export -导出数据库数据db2move export -tn , -导出数据库中表和表数据9、数据库导入db2 -tvf .sql -把上述导出的表结构导入到数据库表结构db2move load -lo replace -把上述“db2move export “导出的数据导入到数据库中并把相同的数据替换掉 在实际使用过程中,如果用到 db2 自增主键,需要使用 by default, 而不是 always,功能是一样的,但这样在数据移植时候会很方便!10、db2 connect reset 或 db

11、2 terminate -断开与数据库的连接11、db2set db2codepage=1208 -修改页编码为 120812、db2 describe table -查看表结构13、db2 list tables -查看数据库中所有表结构list tables for system -列出所有系统表14、db2 list tablespaces -列出表空间二、高级篇15、fetch first 10 rows only -列出表中前 10 条数据例如:select * from fetch first 10 rows only16、coalesce(字段名,转换后的值) -对是 null

12、的字段进行值转换例如:select coalesce(id,1) from -对表中 id 如果为 null 转换成 117、dayofweek(日期) -计算出日期中是周几(1 是周日, 2 是周一.7 是周六)dayofweek_iso -计算出日期中是周几(1 是周一.7 是周日)例如:dayofweek(date(2008-01-16) -它会返回是 4,代表星期三dayofweek_iso(date(2008-01-16) -它会返回是 3,代表星期三18、dayofyear(日期) -一年中的第几天,范围在 1-366 范围之内注意:参数中日期的格式是 YYYY-MM-DD 的形式

13、,如果不是需要进行转换,否则函数不能使用例如:日期是 20080116 必须要进行转换dayofweek(concat(concat(concat(substr(openDate,1,4),-),concat(substr(openDate,5,2),-),substr(openDate,7,2) as week)这样格式正确的。19、concatt(参数 1,连接值) -把参数加上连接值组成一个新值。例如:concat(aa,b) -返回是 aab连接数据库:connect to 数据库名 user 操作用户名 using 密码 创建缓冲池(8K) :create bufferpool ib

14、mdefault8k IMMEDIATE SIZE 5000 PAGESIZE 8 K ;创建缓冲池(16K)(OA_DIVERTASKRECORD):create bufferpool ibmdefault16k IMMEDIATE SIZE 5000 PAGESIZE 16 K ;创建缓冲池(32K)(OA_TASK) :create bufferpool ibmdefault32k IMMEDIATE SIZE 5000 PAGESIZE 32 K ;创建表空间:CREATE TABLESPACE exoatbs IN DATABASE PARTITION GROUP IBMDEFAUL

15、TGROUP PAGESIZE 8K MANAGED BY SYSTEM USING (/home/exoa2/exoacontainer) EXTENTSIZE 32 PREFETCHSIZE 16 BUFFERPOOL IBMDEFAULT8K OVERHEAD 24.10 TRANSFERRATE 0.90 DROPPED TABLE RECOVERY OFF;CREATE TABLESPACE exoatbs16k IN DATABASE PARTITION GROUP IBMDEFAULTGROUP PAGESIZE 16K MANAGED BY SYSTEM USING (/home/exoa2/exoacontainer16k ) EXTENTSIZE 32

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 中学教育 > 职业教育

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号