网上找的一些DB2资料,备忘
来源:互联网 发布:三打哈网络推广 编辑:程序博客网 时间:2024/04/28 20:51
1.安装DB2
DB2的安装可以算是再各个数据库里面最简单的了。除了sqlite。
下载安装包,解压
[root@Enterprisetmp]# tar xvf DB2_V82_PE_LNX_32_NLV.tar
解开以后的文件都被放置在当前目录下的pe文件夹中。
开始安装:
[root@Enterprisetmp]# cd pe
[root@Enterprisepe]# ls
db2 db2_deinstall db2_install db2setup doc
[root@Enterprisepe]# ./db2_install
Specifyone or more of the following keywords,
separatedby spaces, to install DB2 products.
选择自己要安装的产品,输入名字后回车。等待安装完成。
我们现在需要做的是,对数据库的初始化工作。包括安装授权文件和创建一个实例并运行它。
首先,我们安装授权文件。
不安装授权文件的话,则是评估版,九十天后就要过期。授权文件,在安装包已经有了。我们用下面的命令安装它:
[root@Enterprisepe]# /opt/IBM/db2/V8.2/adm/db2licm -a /tmp/pe/db2/lic
ense/db2pe.lic
如果没有db2pe.lic 文件。可以去网上找找。
我们需要创建一个用户。
[root@Enterprisepe]# useradd db2inst1
[root@Enterprisepe]# passwd db2inst1
开始创建实例:
[root@Enterprisepe]#/opt/IBM/db2/V8.2/instance/db2icrt -u db2inst1 db2inst1
这样,我们就创建了一个实例db2ins1。
[root@Enterprisepe]# su db2inst1
[db2inst1@Enterprisepe]$ db2start
07/26/200716:45:10 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
这样我们数据库就启动成功。
[db2inst1@Enterprisepe]$ db2
(c)Copyright IBM Corporation 1993,2002
CommandLine Processor for DB2 SDK 8.2.0
Youcan issue database manager commands and SQL statements from the command
prompt.For example:
db2 => connect to sample
db2 => bind sample.bnd
Forgeneral help, type: ?.
Forcommand help, type: ? command, where command can be
thefirst few keywords of a database manager command. For example:
?CATALOG DATABASE for help on the CATALOG DATABASE command
?CATALOG for help on allof the CATALOG commands.
Toexit db2 interactive mode, type QUIT at the command prompt. Outside
interactivemode, all commands must be prefixed with 'db2'.
Tolist the current command option settings, type LIST COMMAND OPTIONS.
Formore detailed help, refer to the Online Reference Manual.
db2=>
创建一个最简单的数据库
db2=> create database testdb
DB20000I The CREATE DATABASE command completed successfully.
查看本instance下有哪些database
db2=> list database directory
SystemDatabase Directory
Numberof entries in the directory = 2
Database1 entry:
Databasealias = TESTDB
Databasename = TESTDB
Localdatabasedirectory = /home/db2inst1
Databasereleaselevel = a.00
Comment =
Directoryentrytype = Indirect
Catalogdatabase partition number = 0
Alternateserverhostname =
Alternateserver port number =
Database2 entry:
Databasealias = OMNIDB
Databasename = OMNIDB
Localdatabasedirectory = /home/db2inst1/data
Databasereleaselevel = a.00
Directoryentrytype = Indirect
Catalogdatabase partition number = 0
Alternateserverhostname =
Alternateserver port number =
源文档 <http://crrok2002.blogbus.com/logs/7556671.html>
2. DB2的一些常用命令
一、基础篇
1、db2 connect to <数据库名> --连接到本地数据库名
db2 connect to<数据库名> user <用户名> using <密码> --连接到远端数据库
2、 db2force application all --强迫所有应用断开数据库连接
3、db2backup db db2name<数据库名称> --备份整个数据库数据
db2 restore db<db2name> --还原数据库
4、db2list application --查看所有连接(需要连接到具体数据库才能查看)
5、db2start --启动数据库
db2stop --停止数据库
6、createdatabase <数据库名> using codeset utf-8 territory CN --创建数据库使用utf-8编码
7、db2catalog 命令
db2catalog tcpip node <接点名称> remote <远程数据库地址> server<端口号> --把远程数据库映射到本地接点一般为50000
db2catalog db <远程数据库名称> as <接点名称> at nodePUB11 --远程数据库名称到本地接点
db2CONNECT 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<数据库名> export -tn<表1>,<表2> --导出数据库中表和表数据
9、数据库导入
db2-tvf <脚本名称>.sql --把上述导出的表结构导入到数据库表结构
db2move<数据库名> load -lo replace --把上述“db2move <数据库名>export “导出的数据导入到数据库中并把相同的数据替换掉
在实际使用过程中,如果用到db2自增主键,需要使用bydefault, 而不是always,功能是一样的,但这样在数据移植时候会很方
便!
10、db2connect reset 或 db2 terminate --断开与数据库的连接
11、db2setdb2codepage=1208 --修改页编码为1208
12、db2describe table <表名> --查看表结构
13、db2listtables --查看数据库中所有表结构
list tables forsystem --列出所有系统表
14、db2listtablespaces --列出表空间
二、高级篇
15、fetchfirst 10 rows only --列出表中前10条数据
例如:select* from <表名> fetch first 10 rows only
16、coalesce(字段名,转换后的值) --对是null的字段进行值转换
例如:select coalesce(id,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范围之内
注意:参数中日期的格式是YYYY-MM-DD的形式,如果不是需要进行转换,否则函数不能使用
例如:日期是20080116必须要进行转换
dayofweek(concat(concat(concat(substr(openDate,1,4),'-'),concat(substr(openDate,5,2),'-')),substr(openDate,7,2)))as week)
这样格式正确的。
19、concatt(参数1,连接值) --把参数1加上连接值组成一个新值。
例如: concat('aa','b') --返回是aab
原文地址 :http://www.blogjava.net/wuxj888java/archive/2008/01/16/175595.html
3. 安装文件时的产品简称的说明:
client
DB2 Client
consv
DB2 Connect™ Enterprise Edition
doce
DB2 Information Center
ese
DB2 Enterprise Server Edition
exp
DB2 Express Edition
gse
DB2 Spatial Extender
Comment =
lsdc
WebSphere® Federation Server Non-Relational Wrappers
nlpack
DB2 National Language Package
pe
DB2 Personal Edition
pe_connect
DB2 Connect Personal Edition
qp
DB2 Query Patroller
rcon
WebSphere Federation Server Relational Wrappers
rtcl
DB2 Runtime Client
wse
DB2 Workgroup Server Edition
universal
Universal fix pack image that allows to you install the fix pack for multiple products simultaneously.
源文档 <http://www-01.ibm.com/support/docview.wss?uid=swg21253570>
- 网上找的一些DB2资料,备忘
- 网上找的资料
- 网上搜集的有用资料备忘
- 网上找的.net的资料!!!
- 从网上找的DBMS_STATS.SET_DATABASE_PREFS资料
- JEECG树相关网上找的资料
- 收集一些网上的资料
- TR069网上的一些资料
- 从网上找了一些开源spider的相关资料,整理在下面
- 找来的一些资料
- 网络数据库网上找的一些题目
- 网上找的一些django教程
- 一些面试题(网上找的)
- 网上找的一些效果代码
- 一些网上搜集的Qtopia的资料
- 在网上找的javascript的内置对象的资料
- UITextfiel 网上找的比较全面的资料
- Curses Library 一些网上的资料
- 在Android中监视wifi状态
- C语言中随机数产生
- 什么是爱情?
- Talking about Android Process
- 激动啊,终于找到了免费下载文献的地方
- 网上找的一些DB2资料,备忘
- 调用 Reporting Service 时,怎么去掉滚动条。
- 浅析android下如何通过jni监控wifi网络连接、dhcpcd执行和power电源控制
- 拥有博客的第一天
- 获取子框架内容
- hibernate的查询缓存
- 分组
- 线性代数知识点框架
- Discuz!7.0升级Discuz!7.2教程