下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、linux下的db2命令.docdb2 数据库简介 1 启动数据库 db2start 2 停止数据库 db2stop 3 衔接数据库 db2 connect to o_yd user db2 using 4 读数据库管理程序配置 db2 get dbm cfg 5 写数据库管理程序配置 db2 up 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 u
2、pdate db cfg for o_yd using 参数名 参数值 8 关闭全部应用衔接 db2 force appliion 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
3、to .tape0 10 复原数据库 db2 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:plus.bnd 拷贝存储过程到服务器上的 c:sqllibfution 名目中 12 收拾表 db2 connect to o_yd user db2 using pwd db2 reorg table y db2 runs on table ydd with disibution and indes all
4、13 导出表数据 db2 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
5、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 i
6、nto 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 detail indexes all; from syscat.tables where tabschema= db2 an
7、d type= t db2 -tf temp.sql runstats.sql 17 自动生成建表(视图)语句 在服务器上: c:sqllibmisc 名目中 db2 connect to o_yd user db2 using pwd db2 -d o_yd -u db2 -e -p -c c:o_yd.txt 18 其他指令 grant dbadm on database to user bb 19select * from czyxx fetch first 1 rows only 20db2look -d ylbx -u db2admin -w -asd -a -e -o a.txt2
8、1. 显示当前用户全部表 list tables 22. 列出全部的系统表 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 r
9、estore db db2name - 还原数据库 4 、 db2 list application - 查看全部衔接(需要衔接到详细数据库才干查看) 5 、 db2start - 启动数据库 db2stop - 停止数据库 6 、 create database 数据库名 using code utf-8 territory cn - 创建数据库用法 utf-8 编码 7 、 db2 catalog 指令 db2 catalog tip node 接点名称 remote 远程数据库地址 server 端口号 - 把远程数据库映射到本地接点普通为 50000 db2 catalog db 远程
10、数据库名称 as 接点名称 at node pub11 - 远程数据库名称到本地接点 db2 connect to 接点名称 user 用户名 using 密码 - 衔接本地接点拜访远程数据库 8 、数据库导出 db2look -d 数据库名 -u 用户 -e -o 脚本名称 .sql - 导出数据库的表结构,其中用户空间普通为 db2admin/db2inst1 db2look -d 数据库名 -u 用户 -t 表 1 表 2 -e -o 脚本名称 .sql - 导出数据库中表 1 和表 2 的表结构 db2move 数据库名 export - 导出数据库数据 db2move 数据库名 ex
11、port -tn 表 1 , 表 2 - 导出数据库中表和表数据 9 、数据库导入 db2 -tvf 脚本名称 .sql - 把上述导出的表结构导入到数据库表结构 db2move 数据库名 load -lo replace - 把上述 db2move 数据库名 export 导出的数据导入到数据库中并把相同的数据替换掉 在实际用法过程中,假如用到 db2 自增主键,需要用法 by default , 而不是 always ,功能是一样的,但这样在数据移植时候会很方 便 ! 10 、 db2 connect 或 db2 teinate - 断开与数据库的衔接 11 、 db2set db2cod
12、epage=1208 - 修改页编码为 1208 12 、 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 only 16 、 coalesce( 字段名,转换后的值 ) - 对是 null 的字段举
13、行值转换 例如: select coalesce(,1) from 表名 - 对表中 id 假如为 null 转换成 1 17 、 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 范围之内
14、注重:参数中日期的格式是 yyyy-mm-dd 的形式,假如不是需要举行转换,否则函数不能用法 例如:日期是 20080116 必需要举行转换 dayofweek(concat(concat(concat(bstr(opendate,1,4), - ),concat(substr(opendate,5,2), - ),substr(opendate,7,2) as week) 这样格式正确的。 19 、 concatt( 参数 1 ,衔接值 ) - 把参数加上衔接值组成一个新值。 例如: concat( aa , b ) - 返回是 aab 衔接数据库: connect to 数据库名 use
15、r 操作用户名 using 密码 创建缓冲池 (8k) : create bufferpool ibmdefault8k 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 ; 创建表空间: crea
16、te tablespace exoatbs in database partition group ibmdefaultgroup 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 gr
17、oup ibmdefaultgroup pagesize 16k managed by system using ( /home/exoa2/exoacontainer16k ) extentsize 32 prefetchsize 16 bufferpool ibmdefault16k overhead 24.1 transferrate 0.90 dropped table recovery off; create tablespace exoatbs32k in database partition group ibmdefaultgroup pagesize 32k managed b
18、y system using ( /home/exoa2/exoacontainer32k ) extentsize 32 prefetchsize 16 bufferpool ibmdefault32k overhead 24.1 transferrate 0.90 dropped table recovery off; grant use of tablespace exoatbs to public; grant use of tablespace exoatbs16k to public; grant use of tablespace exoatbs32k to public; 创建
19、系统表空间: create temporary tablespace exoasystmp in database partition group ibmtempgroup pagesize 8k managed by system using ( /home/exoa2/exoasystmp ) extentsize 32 prefetchsize 16 bufferpool ibmdefault8k overhead 24.10 transferrate 0.90 dropped table recovery off; create temporary tablespace exoasys
20、tmp16k in database partition group ibmtempgroup pagesize 16k managed by system using ( /home/exoa2/exoasystmp16k ) extentsize 32 prefetchsize 16 bufferpool ibmdefault16k overhead 24.10 transferrate 0.90 dropped table recovery off; create temporary tablespace exoasystmp32k in database partition group
21、 ibmtempgroup pagesize 32k managed by system using ( /home/exoa2/exoasystmp32k ) extentsize 32 prefetchsize 16 bufferpool ibmdefault32k overhead 24.10 transferrate 0.90 dropped table recovery off; 1. 启动实例 (db2inst1): db2start 2. 停止实例 (db2inst1): db2stop 3. 列出全部实例 (db2inst1) db2ilist 5. 列出当前实例 : db2
22、get instance 4. 察看示例配置文件 : db2 get dbm cfg| 5. 更新数据库管理器参数信息 : db2 update dbm cfg using para_name para_value 6. 创建数据库 : db2 create db test 7. 察看数据库配置参数信息 db2 get db cfg for test|more 8. 更新数据库参数配置信息 db2 update db cfg for test using para_name para_value 10. 删除数据库 : db2 drop db test 11. 衔接数据库 db2 connec
23、t to test 12. 列出全部表空间的具体信息。 db2 list tablespaces show detail 13. 查询数据 : db2 select * from tb1 14. 删除数据 : db2 delete from tb1 where id=1 15. 创建索引 : db2 create index idx1 on tb1(id); 16. 创建视图 : db2 create view view1 as select id from tb1 17. 查询视图 : db2 select * from view1 18. 节点编目 db2 catalog tcp node
24、 node_name remote server_ip server server_port 19. 察看端口号 db2 get dbm cfg| svcename 20. 测试节点的附接 db2 attach to node_name 21. 察看本地节点 db2 list node direcotry 22. 节点反编目 db2 uncatalog node node_name 23. 数据库编目 db2 catalog db db_name as db_ at node node_name 24. 察看数据库的编目 db2 list db directory 25. 衔接数据库 db2
25、connect to db_alias user user_name using user_password 26. 数据库反编目 db2 uncatalog db db_alias 27. 导出数据 db2 export to my of ixf messages msg select * from tb1 28. 导入数据 db2 import from myfile of ixf messages msg replace into tb1 29. 导出数据库的全部表数据 db2move test export 30. 生成数据库的定义 db2look -d db_alias -a -e
26、-m -l -x -f -o db2look.sql 31. 创建数据库 db2 create db test1 32. 生成定义 db2 -tvf db2look.sql 33. 导入数据库全部的数据 db2move db_alias import 34. 重组检查 db2 reorgchk 35. 重组表 tb1 db2 reorg table tb1 36. 更新统计信息 db2 runstats on table tb1 37. 备份数据库 test db2 backup db test 38. 复原数据库 test db2 restore db test 399. 列出容器的信息 d
27、b2 list tablespace containers for tbs_id show detail 40. 创建表 : db2 ceate table tb1(id integer not null,name char(10) 41. 列出全部表 db2 list tables 42. 插入数据 : db2 insert into tb1 values(1, sam ); db2 insert into tb2 values(2, smitty ); . 建立数据库 db2_gcb create database db2_gcb on g: alias db2_gcb using cod
28、eset gbk territory cn collate using system dft_extent_sz 32 2. 衔接数据库 connect to sample1 user db2admin using 8301206 3. 建立别号 create alias db2admin.tables for sysstat.tables; create alias db2admin.views for syscat.views create alias db2admin.umns for syscat.columns; create alias guest.columns for sysc
29、at.columns; 4. 建立表 create table zjt_tables as (select * from tables) definition only; create table zjt_views as (select * from views) definition only; 5. 插入记录 insert into zjt_tables select * from tables; insert into zjt_views select * from views; 6. 建立视图 create view v_zjt_tables as select tabschema,
30、tabname from zjt_tables; 7. 建立触发器 create trigger zjt_tables_del after delete on zjt_tables referencing old as o for each row mode db2sql insert into zjt_tables1 values(substr(o.tabschema,1,8),substr(o.tabname,1,10) 8. 建立唯一性索引 create unique index i_ztables_tabname size=3on zjt_tables(tabname); 9. 查看表
31、 select tabname from tables where tabname= zjt_tables 10. 查看列 select substr(colname,1,20) as 列名 ,typename as 类型 ,length as 长度 from columns where tabname= zjt_tables 11. 查看表结构 db2 describe table user1.department db2 describe select * from user.tables 12. 查看表的索引 db2 describe indexes for table user1.de
32、partment 13. 查看视图 select viewname from views where viewname= v_zjt_tables 14. 查看索引 select indname from indexes where indname= i_ztables_tabname 15. 查看存贮过程 select substr(procschema,1,15),substr(procname,1,15) from syscat.procedures; 16. 类型转换 (cast) ip datatype:varchar select cast(ip as integer)+50 fr
33、om log_comm_failed 17. 重新衔接 connect reset 18. 中断数据库衔接 disconnect db2_gcb 19. view application list application; 20. application force application(0); db2 force applications all ( 强迫全部应用程序从数据库断开 ) 21. lock table lock table test in exclusive mode 22. 分享 lock table test in share mode 23. 显示当前用户全部表 list
34、 tables 24. 列出全部的系统表 list tables for system 25. 显示当前活动数据库 list active databases 26. 查看指令选项 list command options 27. 系统数据库名目 list database directory 28. 表空间 list tablespaces 29. 表空间容器 list tablespace containers for example: list tablespace containers for 1 30. 显示用户数据库的存取权限 get authorizations 31. 启动实例
35、 db2start 32. 停止实例 db2stop 33. 表或视图特权 grant select,delete,insert,update on tables to user grant all on tables to user with grant option 34. 程序包特权 grant execute on package package-name to public 35. 模式特权 grant createin on schema schema-name to user 36. 数据库特权 grant connect,createtab,dbadm on database
36、to user 37. 索引特权 grant control on index index-name to user 38. 信息协助 (? xxxnnnnn ) 例 :? sql30081 39. sql 协助 ( 解释 sql 语句的语法 ) help statement 例如, help select 40. sqlstate 协助 ( 解释 sql 的状态和类别代码 ) ? sqtate 或 ? class-code 41. 更改与 管理服务器 相关的口令 db2admin setid username password 42. 创建 sample 数据库 db2sampl db2sa
37、mpl f:( 指定安装盘 ) 43. 用法操作系统指令 ! dir 44. 转换数据类型 (cast) select empno, cast(resume as varchar(370) from emp_resume where resume_format = ascii 45. udf 要运行 db2 java 存储过程或 udf ,还需要更新服务器上的 db2 数据库管理程序配置,以包括在该机器上安装 jdk 的路径 db2 update dbm cfg using jdk11_path d:sqllibjavajdk terminate update dbm cfg using sp
38、m_name sample 46. 检查 db2 数据库管理程序配置 db2 get dbm cfg 47. 检索具有特权的全部授权名 select distinct grantee, granteetype, database from syscat.dbauth union select distinct grantee, granteetype, table from syscat.tabauth union select distinct grantee, granteetype, package from syscat.packageauth union select distinc
39、t grantee, granteetype, index from syscat.indexauth union select distinct grantee, granteetype, column from syscat.colauth union select distinct grantee, granteetype, schema from syscat.schemaauth union select distinct grantee, granteetype, server from syscat.passthruauth order by grantee, granteety
40、pe, 3 create table yhdab (id varchar(10), password varchar(10), ywlx varchar(10), kh varchar(10); create table ywlbb (ywlbbh varchar(8), yw varchar(60) 48. 修改表结构 alter table yhdab alter kh set data type varchar(13); alter table yhdab alter id set data type varchar(13); alter table lst_bsi alter bsi_
41、money set data type int; insert into yhdab values ( 20000300001 , 123456 , user01 , 20000300001 ), ( 20000300002 , 123456 , user02 , 20000300002 49. 业务类型解释 insert into ywlbb values ( user01 , 业务申请 ), ( user02 , 业务撤消 ), ( user03 , 费用查询 ), ( user04 , 费用自缴 ), ( user05 , 费用预存 ), ( user06 , 密码修改 ), ( use
42、r07 , 发票打印 ), ( gl01 , 改用户基本信息 ), ( gl02 , 更改支付信息 ), ( gl03 , 日统计功能 ), ( gl04 , 冲帐功能 ), ( gl05 , 对帐功能 ), ( gl06 , 计费功能 ), ( gl07 , 综合统计 ) 备份数据库: connect to exoa; quiesce database immediate force connections; connect reset; backup database exoa to /home/exoa2/db2bak/ with 2 buffers buffer 1024 parall
43、elism 1 without prompting; connect to exoa; unquiesce database; connect reset; 以下是小弟在用法 db2move 中的一些阅历,希翼对大家有所协助。 db2 connect to yourdb 衔接数据库 db2look -d yourdb -a -e -x -o creatab.sql 导出建库表的 sql db2move yourdb export 用 db2move 将数据备份出来 vi creatab.sql 如要导入的数据库名与原数据库不同,要修改 creatab.sql 中 connect 项 如相同则不用更改 db2move newdb load 将数据导入新库中 在导入中可能由于种种缘由发生中断,会使数据库暂挂 db2 list
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- (2026年)医院医疗安全工作总结
- GEO优化是什么 服务商类型:媒体信源型、新媒体信源型、技术型三类深度解析
- 2025年河南省焦作市中站区数学三下期末检测试题(含解析)
- 2025年河南省南阳市方城县部分校数学四下期中复习检测模拟试题含答案解析
- 肾衰竭的临床表现及护理
- 中国制造业AI场景应用全景指南(2026):167个案例洞察从传统ML到AI Agent的落地路径
- 肝性脑病昏迷护理查房
- 自我防护相关试题与答案解析
- 脱水缩合易错试题及详细纠正答案
- 2025-2026年江苏省苏教版小学一年级道德与法治第5课知识点巩固习题
- AI在输血安全管理中的智能应用与风控
- T∕CVIA 107-2023 交互平板触控系统技术规范
- 2026年保教结合幼儿园
- 中新嘉善现代产业园开发有限公司招聘笔试题库2026
- GA 1817.1-2026学校反恐怖防范要求第1部分:普通高等学校
- (2025秋新版)外研版八年级英语上册全册教案
- DZ/T 0125-1994煤田地质钻孔数据文件格式
- 光伏弱电安装合同范本
- 华为光芯片机考题库
- 《数字矿山课件》课件
- 《电机拖动学》课件
评论
0/150
提交评论