DB2数据库运维常用命令集锦

php中文网
发布: 2016-06-07 17:19:22
原创
1059人浏览过

在执行如下命令时,需要首先在客户端运行中输入db2cmd进行初始化或者su到db2的实例下操作。

在执行如下命令时,需要首先在客户端运行中输入db2cmd进行初始化或者su到db2的实例下操作。

一、常识性命令

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、db2stop --停止数据库  db2start    --启动数据库

6、create database using codeset utf-8 territory CN    --创建数据库使用utf-8编码

7、db2 catalog 命令

db2 catalog tcpip node remote server   --把远程数据库映射到本地接点一般为50000

db2 catalog db as   at node PUB11                       --远程数据库名称到本地接点

db2 CONNECT TO user using                                --连接本地接点访问远程数据库

8、数据库导出

db2look -d -u -e -o .sql        --导出数据库的表结构,其中用户空间一般为

db2admin/db2inst2

db2look -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 connect reset 或 db2 terminate    --断开与数据库的连接

11、db2set db2codepage=1208        --修改页编码为1208

12、db2 describe table        --查看表结构

13、db2 list tables                            --查看数据库中所有表结构

     db2 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的字段进行值转换

例如:select coalesce(id,1)  from     --对表中id如果为null转换成1

集简云
集简云

软件集成平台,快速建立企业自动化与智能化

集简云 22
查看详情 集简云

二、导入数据:

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 "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        断开数据库连接

    db2 force applications all    断开所有数据库连接

九、备份数据库

1、 db2 backup db btpdbs

2、 db2move btpdbs export

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

linux

相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号