下面内容都是通过网上查找及实践后整理出来的 ,加入了部分个人理解,如果错误请谅解
--备份数据库结构
db2look -d hneduu -e -a -x -i db2admin -w db2admin -o D:\db2\2\db2look.sql
--备份表的结构
db2look -d hneduu -t "GOV_DTISSUE" -e -a -x -i db2admin -w db2admin -o D:\db2\2\db2look1.sql
db2look -d hneduu -t "EIP4_MAIL" -e -a -x -i db2admin -w db2admin -o D:\sql\eip4_mail.sql
--db2move备份整个数据库数据
db2move hneduu export -sn db2admin -tn * -u db2admin -p db2admin
--备份一个表数据
db2move hneduu export -sn db2admin -tn "select * from EIP4_INFO" -u db2admin -p db2admin
db2move hneduu export -sn db2fenc1 -tn "select * from EIP4_INFO" -u db2fenc1 -p db2jiajie@
db2move hneduu export -sn db2admin -tn "select info_id, user_id, user_name, info_title, info_color, info_bold, info_url, info_preimage, info_comment, column_id, column_name, site_id, info_share, site_domain, info_status, info_pubtime, info_ordertime, info_intro, info_auditerid, info_auditintro, info_titlecontent, info_titleimage, info_gainfile, info_keyword, info_perpage, info_hits, title_show, info_istop, site_idexp, info_address, info_permission, info_password,sitename,maincolumnid,govinfo_catalog_id,govinfo_catalog_name,govinfo_workflow_id,govinfo_workflow_name from DB2ADMIN.Eip4_Info where info_Status='0' and (substr(cast(column_id as varchar(20)),1,4) ='603' or substr(cast(maincolumnid as varchar(100)),1,4) = '603') and site_id=0 order by info_Istop desc , info_Ordertime desc" -u db2admin -p db2admin
--export备份单个数据库数据
db2 export to /usr/sql/del/mail.del of del select ID,NAME,QQ,TEL,EMAIL,PHONE,ADDRESS,ZIP,MAIL_DATA,MAIL_COMMENT,MAIL_TYPE,MAIL_STATUS REPLY_COMMENT from eip4_mail
db2 export to D:/sql/jb/hnedou/del/info20130916 of del select * from eip4_info
--导入csv
import from "d:\table.csv" OF DEL messages "d:\msg.out" INSERT INTO table
--导入del
db2 import from d:\datafile.txt of del insert into deltable
*注意在什么位置执行的db2move备份程序,备份文件的位置就在什么地方
如果D:\DB2\1> 备份文件位置 就在D:\DB2\1下
&新建一个.sql文件,将数据库创建语句写入其中如:
create db hneduu on /usr/src/mySrc using codeset gbk territory cn pagesize 32K catalog tablespace managed by database using (file '/usr/src/mySrc/syscat.c01' 40960) user tablespace managed by database using (file '/usr/src/mySrc/userspace1.c01' 32670) temporary tablespace managed by database using (file '/usr/src/mySrc/systempspace1.c01' 10240)
创建数据库的时候要注意表空间大小,特别是在数据库中有clob类型时
*********************************************
*数据库管理器中表的行长度不能超过: *
*在具有 4K 页大小的表空间中,是 4005 字节 *
*在具有 8K 页大小的表空间中,是 8101 字节。 *
*在具有 16K 页大小的表空间中,是 16293 字节.*
*在具有 32K 页大小的表空间中,是 32677 字节.*
*********************************************
创建文件夹 mkdir + 文件名称 (创建在当前位置)
创建文件 touch + 文件名称 (创建在当前位置)
将文件复制到liunx
进入liunx服务器 登陆db2admin用户 并且进入到文件存放的目录
[db2admin@localhost htdctr]$ db2 -tvf 手动创建的.sql文件
[db2admin@localhost htdctr]$ ls
db2look_htdc.sql
[db2admin@localhost htdctr]$ db2 -tvf db2look_htdctr.sql
[db2admin@localhost dbback]$ pwd
/home/db2admin/dbback/db2move/htdctr/
[db2admin@localhost htdctr]$ db2move htdctr load
迁移中错误及处理
------------------------------------------------------------------------------------------------------------------------------
* LOAD: table "DB2FENC1"."EIP4_TGXT_USER"
*** ERROR -3508. Check message file tab21.msg!
*** SQLCODE: -3508 - SQLSTATE:
*** SQL3508N Error in accessing a file or path of type "MSGFILE" during load or load query. Reason code: "1". Path: "tab21.msg".
原因:
文件解读权限不够
解决方法:
[root@localhost src]# chown -R db2fenc1:root /usr/src/mySrc
-------------------------------------------------------------------------------------------------------------------------------
* LOAD: table "DB2FENC1"."EIP4_INFO"
*** ERROR -3304. Check message file tab11.msg!
*** SQLCODE: -3304 - SQLSTATE:
*** SQL3304N The table does not exist.
原因:
数据库中表 eip4_info表 不存在
解决方式 通过db2look 方式重新导入导出
//db2move HNEDUU export -sn db2admin -tn "EIP4_GOVINFO_WORKFLOW" "EIP4_INFO" "EIP4_INFOBAK201111241300" "EIP4_INQUIRE_QUESTION" "GOV_DTISSUE" "TGXT_INFO" -u db2admin -p db2admin
db2look -d hneduu -t "EIP4_INFO" "EIP4_INQUIRE_QUESTION" "GOV_DTISSUE" -e -a -x -i db2admin -w db2admin -o D:\db2\2\db2look1.sql
------------------------------------------------------------------------------------------------------------------------------
* LOAD: table "DB2FENC1"."GOV_DTISSUELOG"
*** ERROR -289. Check message file tab26.msg!
*** SQLCODE: -289 - SQLSTATE: 57011
*** SQL0289N Unable to allocate new pages in table space "USERSPACE1". SQLSTATE=57011
原因:
数据库表空间不够
db2 "import from eip4_info.ixf of ixf lobs from /usr/src/mySrc/db2ixf modified by lobsinfile replace into db2fencl."
----------------------------------------------------------------------------------------------------------------------------------------
*** SQLCODE: -551 - SQLSTATE: 42501
*** SQL0551N "DB2ADMIN" 不具有对对象 "NULLID.DB2COMMO" 执行操作 "EXECUTE" 的必需权限或特权。 SQLSTATE=42501
----------------------------------------------------------------------------------------------------------------------------------------
附录:
查看表空间数据
db2 list tablespaces
查看单个表空间信息
db2pd -d hneduu -tablespaces 2[表空间编号] -storagepaths
修改表空间容器大小
增加
db2 "alter tablespace USERSPACE1 add(file '/usr/src/mySrc/USERSPACE1' 10240)"
扩展
db2 "alter tablespace userspace1 resize (file '/usr/src/mySrc/userspace1.c01' 3G)"
win
db2 "alter tablespace userspace1 resize (file 'D:\userspace1.c01' 3G)"
当表挂起,需要释放
db2 "load from /usr/src/mySrc/db2/null of del terminate into DB2FENC1.EIP4_LOG"
去除重复项
SELECT oldcolumn FROM DB2ADMIN."EIP4_INFO" group by oldcolumn;
查询oldcolumn包含10的所有数据
select * from eip4_info where locate('10',oldcolumn) >0;
删除oldcolumn包含10的所有数据
delete DB2ADMIN."EIP4_INFO" where locate('10',oldcolumn) >0;
------------------------------------------------------------------------------------------------------------------------------------
win7db2数据库还原方法
1、在命令行使用db2cmd
2、用cd命令进入建库的脚本位置
3、执行db2 -tvf 建库脚本名称.扩展名
4、完成后,用操作用户登录进入数据库
5、用cd命令进入建表的脚本位置
6、执行db2 -tvf 建表脚本名称.扩展名
7、db2 list tables 查看 所有表
----------------------------------------------------------------------------------------------------------------------------------
控制中心连接远程数据库
1、编目节点
catalog tcpip node
remote 192.168.100.1 server 50000;
2、编目数据库
catalog db at node sinodb;
/*
要注意本地不能存在于远程数据库同名的数据库
*/
3、进行连接
connect to user using
-----------------------------------------------------------------------------------------------------------------------------------
1、将数据库取消激活状态
Db2 deactivate db hneduu
2、将数据库处于激活状态
Db2 activate db hadrdb
3、查看数据库连接
Db2 list applications
4、清空连接
Db2 force application all