linux下的DB2命令

上传人:碎****木 文档编号:235773309 上传时间:2022-01-06 格式:DOCX 页数:21 大小:28.83KB
返回 下载 相关 举报
linux下的DB2命令_第1页
第1页 / 共21页
linux下的DB2命令_第2页
第2页 / 共21页
linux下的DB2命令_第3页
第3页 / 共21页
亲,该文档总共21页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

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

1、DB2 数据库命令简介1启动数据库db2start 2停止数据库db2stop 3连接数据库db2 connect to o_yd user db2 using pwd 4读数据库管理程序配置db2 get dbm cfg5. 写数据库管理程序配置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 pwddb2 update db cfg for o_y

2、d using 参数名 参数值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 .tape0 10恢复数据库db2 rest

3、ore 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:sqllibfunction 目录中12. 整理表db2 connect to o_yd user db2 using pwd db2 reorg table ydddb2 runstats on table ydd with distribution and indexes all 13导出表数据db2

4、export to c:dftz.txt of del select * from dftzdb2 export to c:dftz.ixf of ixf select * from dftz 14导入表数据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:

5、dftz.msg insert into dftz db2 import to c:dftz.ixf of ixf commitcount 5000 insert into dftzdb2 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 dftzdb2 import to c:dftz.ixf of ixf commitcount 5000 create into dftz (仅 I

6、XF)db2 import to c:dftz.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.s

7、qlrunstats.sql 17自动生成建表(视图)语句在服务器上:C:sqllibmisc 目录中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 bb19select * from czyxx fetch first 1 rows only20db2look -d ylbx -u db2admin -w -asd -a -e -o a.txt21. 显示当前用户所有表list tables22.列出所

8、有的系统表list tables for system 23.查看表结构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-启动数据库

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

10、/db2inst1db2look -d -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 conn

11、ect reset 或 db2 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(字段名,转换后的值)-

12、对是 null 的字段进行值转换例如: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(openDa te,5,2),-),substr(openDate,7,2) as week)这样格式正确的。19、concatt(参数 1,连接值)-把参数加上连接值组成一个新值。例如: concat(aa,b)-返回是 aab连接数据库:connect to 数据库名 user 操作用户名 using 密码创建缓冲池(8K):create bufferpool ibm

14、default8k IMMEDIATESIZE 5000 PAGESIZE 8 K ;创建缓冲池(16K)(OA_DIVERTASKRECORD):create bufferpool ibmdefault16k IMMEDIATESIZE 5000 PAGESIZE 16 K ;创建缓冲池(32K)(OA_TASK):create bufferpool ibmdefault32k IMMEDIATESIZE 5000 PAGESIZE 32 K ;创建表空间:CREATE TABLESPACE exoatbs IN DATABASE PARTITION GROUP IBMDEFAULTGROUP PAGESIZE 8K MANAGED BY SYSTEM USING(/home/exoa2/exoacontainer) EXTENTSIZE 32

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 教育/培训

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