1.1 下载安装软件
DB2v10.5.0.4_linuxx64_expc.tar
1.2 解压安装软件
[root@localhost opt]# tar zxvf DB2v10.5.0.4_linuxx64_expc.tar.gz |
[root@localhost opt]# cd expc/ [root@localhost expc]# ll total 52 drwxr-xr-x. 6 bin bin 4096 Aug 14 2014 db2 -r-xr-xr-x. 1 bin bin 5349 Aug 14 2014 db2ckupgrade -r-xr-xr-x. 1 bin bin 5302 Aug 14 2014 db2_deinstall -r-xr-xr-x. 1 bin bin 5172 Aug 14 2014 db2_install -r-xr-xr-x. 1 bin bin 5136 Aug 14 2014 db2ls -r-xr-xr-x. 1 bin bin 5154 Aug 14 2014 db2prereqcheck -r-xr-xr-x. 1 bin bin 5154 Aug 14 2014 db2setup |
1.3 执行安装脚本
[root@localhost expc]# ./db2setup |
Requirement not matched for DB2 database "Server" . Version: "10.5.0.4".
Summary of prerequisites that are not met on the current system:
DBT3514W The db2prereqcheck utility failed to find the following 32-bit library file: "/lib/libpam.so*".
DBT3514W The db2prereqcheck utility failed to find the following 32-bit library file: "libstdc++.so.6".
DBI1190I db2setup is preparing the DB2 Setup wizard which will guide you through the program setup process. Please wait. |
1.4 选择Install a Product,点击Install New
1.5 接受许可协议
1.6 选择Typical
1.7 选择Install DB2 Express
1.8 选择安装目录
1.9 创建dasusr1用户,密码zhangjun
1.10 创建DB2实例
1.11 验证安装信息
Product to install: DB2 Express-C Installation type: Typical
Previously Installed Components:
Selected Components: Base client support Java support SQL procedures Base server support DB2 data source support DB2 LDAP support DB2 Instance Setup wizard Integrated Flash Copy Support Communication support - TCP/IP DB2 Update Service Sample database source First Steps
Languages: English All Products
Target directory: /opt/ibm/db2/V10.5
Space required: 935 MB
New instances: Instance name: db2inst1 Start instance on reboot: Yes TCP/IP configuration: Service name: db2c_db2inst1 Port number: 50000 Instance user information: User name: db2inst1 Group name: db2iadm1 Home directory: /home/db2inst1 Fenced user information: User name: db2fenc1 Group name: db2fadm1 Home directory: /home/db2fenc1
DB2 Administration server: Instance user information: User name: dasusr1 Group name: dasadm1 Home directory: /home/dasusr1 SMTP server: localhost.localdomain
Contact specification: New contacts: Name: db2inst1 Instance: db2inst1 E-mail address: db2inst1@localhost.localdomain E-mail address is for a pager: No
Response file name: /root/db2expc.rsp |
1.12 点击Finsh开始安装
1.13 安装完成
Post-install steps |
Required steps:
In order to start using DB2 you need to logon using a valid user ID such as the DB2 instance owner's ID "db2inst1".
You can connect to the DB2 instance "db2inst1" using the port number "50000". Record it for future reference.
Optional steps:
To validate your installation files, instance, and database functionality, run the Validation Tool, /opt/ibm/db2/V10.5/bin/db2val. For more information, see "db2val" in the DB2 Information Center.
Open First Steps by running "db2fs" using a valid user ID such as the DB2 instance owner's ID. You will need to have DISPLAY set and a supported web browser in the path of this user ID.
You should ensure that you have the correct license entitlements for DB2 products and features installed on this machine. Each DB2 product or feature comes with a license certificate file (also referred to as a license key) that is distributed on an Activation CD, which also includes instructions for applying the license file. If you purchased a base DB2 product, as well as, separately priced features, you might need to install more than one license certificate. The Activation CD for your product or feature can be downloaded from Passport Advantage if it is not part of the physical media pack you received from IBM. For more information about licensing, search the Information Center (http://publib.boulder.ibm.com/infocenter/db2luw/v10r5/index.jsp) using terms such as "license compliance", "licensing" or "db2licm".
To use your DB2 database product, you must have a valid license. For information about obtaining and applying DB2 license files, see http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.qb.server.doc/doc/c0061199.html.
Refer to "What's New" http://publib.boulder.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.wn.doc/doc/c0052035.html in the DB2 Information Center to learn about the new functions for DB2 10.5.
Verify that you have access to the DB2 Information Center based on the choices you made during this installation. If you performed a typical or a compact installation, verify that you can access the IBM Web site using the internet. If you performed a custom installation, verify that you can access the DB2 Information Center location specified during the installation.
Review the response file created at /root/db2expc.rsp. Additional information about response file installation is available in the DB2 documentation under "Installing DB2 using a response file". |
Log file |
Checking license agreement acceptance :.......Success Installing DB2 file sets :.......Success Executing control tasks :.......Success Updating global registry :.......Success Starting DB2 Fault Monitor :.......Success Updating the db2ls and db2greg link :.......Success Registering DB2 licenses :.......Success Setting default global profile registry variables :.......Success Creating the DB2 Administration Server :.......Success Initializing instance list :.......Success Configuring DB2 instances :.......Success Registering DB2 Update Service :.......Success Configuring the DB2 Administration Server :.......Success Updating global profile registry :.......Success Configuring health alert notifications :.......Success
============================================================
DB2 Setup log file started at: Sat Apr 04 06:44:42 AM 2015 PDT ============================================================
Operating system information: Linux 2.6.32-431.el6.x86_64.#1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64
Product to install: DB2 Express-C Installation type: Typical
Previously Installed Components:
Selected Components: Base client support Java support SQL procedures Base server support DB2 data source support DB2 LDAP support DB2 Instance Setup wizard Integrated Flash Copy Support Communication support - TCP/IP DB2 Update Service Sample database source First Steps
Languages: English All Products
Target directory: /opt/ibm/db2/V10.5
Space required: 935 MB
New instances: Instance name: db2inst1 Start instance on reboot: Yes TCP/IP configuration: Service name: db2c_db2inst1 Port number: 50000 Instance user information: User name: db2inst1 Group name: db2iadm1 Home directory: /home/db2inst1 Fenced user information: User name: db2fenc1 Group name: db2fadm1 Home directory: /home/db2fenc1
DB2 Administration server: Instance user information: User name: dasusr1 Group name: dasadm1 Home directory: /home/dasusr1 SMTP server: localhost.localdomain
Contact specification: New contacts: Name: db2inst1 Instance: db2inst1 E-mail address: db2inst1@localhost.localdomain E-mail address is for a pager: No
Response file name: /root/db2expc.rsp
Checking license agreement acceptance :.......Success Installing: BASE_CLIENT_R
Installing: DB2_PRODUCT_MESSAGES_EN
Installing: BASE_CLIENT
Installing: JAVA_RUNTIME_SUPPORT
Installing: DB2_JAVA_HELP_EN
Installing: BASE_DB2_ENGINE_R
Installing: GSK
Installing: JAVA_SUPPORT
Installing: SQL_PROCEDURES
Installing: ICU_SUP
Installing: JAVA_COMMON_FILES
Installing: BASE_DB2_ENGINE
Installing: DB2_DATA_SOURCE_SUPPORT
Installing: LDAP_EXPLOITATION
Installing: INSTANCE_SETUP_SUPPORT
Installing: ACS
Installing: COMMUNICATION_SUPPORT_TCPIP
Installing: DB2_UPDATE_SERVICE
Installing: EDB
Installing: DB2_SAMPLE_DATABASE
Installing: CLPPLUS
Installing: FIRST_STEPS
Installing: EXPC_PRODUCT_SIGNATURE
Installing DB2 file sets :.......Success Executing control tasks :.......Success Updating global registry :.......Success Starting DB2 Fault Monitor :.......Success Updating the db2ls and db2greg link :.......Success Registering DB2 licenses :.......Success The value "DB2_COMPATIBILITY_VECTOR=MYS" was set in the Profile Registry.
Setting default global profile registry variables :.......Success Creating the DB2 Administration Server :.......Success Initializing instance list :.......Success The instance "db2inst1" has been created successfully.
The value "SVCENAME=db2c_db2inst1" was set in the DBM CFG file for the "db2inst1" instance.
The value "DB2AUTOSTART=YES" was set in the Profile Registry for the "db2inst1" instance.
Configuring DB2 instances :.......Success Registering DB2 Update Service :.......Success Configuring the DB2 Administration Server :.......Success Updating global profile registry :.......Success The contact "db2inst1" was successfully added.
Configuring health alert notifications :.......Success |
1.14 操作数据库
1.14.1 创建表空间
CREATE 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 GROUP 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 BY 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; |
1.14.2 创建系统表空间
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 exoasystmp16k 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 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.14.3 创建数据库
create database <数据库名> using codeset utf-8 territory CN --创建数据库使用utf-8编码 |
db2 create db <数据库名> |
db2 create db test |
1.14.4 创建表
create table zjt_tables as (select * from tables) definition only; |
create table zjt_views as (select * from views) definition only; |
create table yhdab (id varchar(10), password varchar(10), ywlx varchar(10), kh varchar(10)); |
create table ywlbb (ywlbbh varchar(8), ywmc varchar(60)) |
1.14.5 启动数据库
db2start --启动数据库 |
1.14.6 停止数据库
db2stop --停止数据库 |
1.14.7 连接数据库
db2 connect to <数据库名> --连接到本地数据库名 |
db2 CONNECT TO <接点名称> user <用户名> using <密码> --连接本地接点访问远程数据库 |
db2 connect to <数据库名> user <用户名> using <密码> --连接到远端数据库 |
db2 connect to o_yd user db2 using pwd |
db2 force application all --强迫所有应用断开数据库连接 |
1.14.8 读数据库管理程序配置
db2 get dbm cfg
1.14.9 写数据库管理程序配置
db2 update dbm cfg using 参数名 参数值
1.14.10读数据库的配置
db2 connect to o_yd user db2 using pwd
db2 get db cfg for o_yd
1.14.11写数据库的配置
db2 connect to o_yd user db2 using pwd
db2 update db cfg for o_yd using 参数名 参数值
1.14.12关闭所有应用连接
db2 connect reset 或 db2 terminate --断开与数据库的连接 |
db2 force application all |
db2 force application ID1,ID2,,,Idn MODE ASYNC |
(db2 list application for db o_yd show detail) |
1.14.13备份数据库
db2 backup db db2name<数据库名称> --备份整个数据库数据 |
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 to \\.\tape0 |
1.14.14恢复数据库
db2 restore db <db2name> --还原数据库 |
db2 restore db o_yd from d: to d: |
db2 restore db o_yd from \\.\tape0 to d: |
1.14.15绑定存储过程
db2 connect to o_yd user db2 using pwd
db2 bind c:\dfplus.bnd
拷贝存储过程到服务器上的C:\sqllib\function目录中
1.14.16整理表
db2 connect to o_yd user db2 using pwd
db2 reorg table ydd
db2 runstats on table ydd with distribution and indexes all
1.14.17导出表数据
db2 export to c:\dftz.txt of del select * from dftz
db2 export to c:\dftz.ixf of ixf select * from dftz
1.14.18导入表数据
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 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 into dftz (仅IXF)
db2 import to c:\dftz.ixf of ixf commitcount 5000 replace_create into dftz (仅IXF)
1.14.19执行一个批处理文件
db2 -tf 批处理文件名
(文件中每一条命令用 ;结束)
1.14.20自动生成批处理文件
建文本文件:temp.sql
select 'runstats on table DB2.' || tabname || '
with distribution and detailed indexes all;'
from syscat.tables where tabschema='DB2' and type='T';
db2 -tf temp.sql>runstats.sql
1.14.21自动生成建表(视图)语句
在服务器上:C:\sqllib\misc目录中
db2 connect to o_yd user db2 using pwd
db2look -d o_yd -u db2 -e -p -c c:\o_yd.txt
1.14.22显示当前用户所有表
list tables
1.14.23列出所有的系统表
db2 list tables --查看数据库中所有表结构 |
list tables for system --列出所有系统表 |
1.14.24查看表结构
db2 describe table <表名> --查看表结构 |
db2 describe select * from user.tables |
1.14.25查看所有连接
db2 list application --查看所有连接(需要连接到具体数据库才能查看) |
1.14.26数据库导出
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> --导出数据库中表和表数据 |
1.14.27数据库导入
db2 -tvf <脚本名称>.sql --把上述导出的表结构导入到数据库表结构 db2move <数据库名> load -lo replace --把上述“db2move <数据库名> export “导出的数据导入到数据库中并把相同的数据替换掉 在实际使用过程中,如果用到db2自增主键,需要使用by default, 而不是always,功能是一样的,但这样在数据移植时候会很方便! |
1.14.28修改编码
db2set db2codepage=1208 --修改页编码为1208 |
1.14.29查看表空间
db2 list tablespaces --列出表空间 |
1.14.30其他命令
1.14.30.1 db2 catalog
db2 catalog tcpip node <接点名称> remote <远程数据库地址> server <端口号> --把远程数据库映射到本地接点一般为50000 |
db2 catalog db <远程数据库名称> as <接点名称> at node PUB11 --远程数据库名称到本地接点 |
1.14.30.2 grant
grant dbadm on database to user bb |
1.14.30.3 其它
select * from czyxx fetch first 1 rows only |
db2look -d ylbx -u db2admin -w -asd -a -e -o a.txt |
fetch first 10 rows only --列出表中前10条数据 |
select * from <表名> fetch first 10 rows only |
1.14.31其它
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
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
连接数据库:
connect to [数据库名] user [操作用户名] 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 ;
1. 启动实例(db2inst1):
db2start
2. 停止实例(db2inst1):
db2stop
3. 列出所有实例(db2inst1)
db2ilist
5.列出当前实例:
db2 get instance
4. 察看示例配置文件:
db2 get dbm cfg|more
5. 更新数据库管理器参数信息:
db2 update dbm cfg using para_name para_value
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 connect 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 node_name remote server_ip server server_port
19.察看端口号
db2 get dbm cfg|grep 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_alias at node node_name
24.察看数据库的编目
db2 list db directory
25.连接数据库
db2 connect to db_alias user user_name using user_password
26.数据库反编目
db2 uncatalog db db_alias
27.导出数据
db2 export to myfile 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 -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\.列出容器的信息
db2 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 CODESET 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.columns for syscat.columns;
create alias guest.columns for syscat.columns;
5. 插入记录
insert into zjt_tables select * from tables;
insert into zjt_views select * from views;
6. 建立视图
create view V_zjt_tables as select tabschema,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=3]ON zjt_tables(tabname);
9. 查看表
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.department
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 from log_comm_failed
17. 重新连接
connect reset
18. 中断数据库连接
disconnect db2_gcb
19. view application
LIST APPLICATION;
20. kill 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 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. 启动实例
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 to user
37. 索引特权
grant control on index index-name to user
38. 信息帮助 (? XXXnnnnn )
例:? SQL30081
39. SQL 帮助(说明 SQL 语句的语法)
help statement
例如,help SELECT
40. SQLSTATE 帮助(说明 SQL 的状态和类别代码)
? sqlstate 或 ? class-code
41. 更改与"管理服务器"相关的口令
db2admin setid username password
42. 创建 SAMPLE 数据库
db2sampl
db2sampl 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 SPM_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 DISTINCT 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, GRANTEETYPE, 3
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_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','密码修改'),
('user07','发票打印'),
('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 PARALLELISM 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 tablespaces show detail 如: 详细说明: 装入暂挂 总页数 = 1652 可用页数 = 1652 已用页数 = 1652 空闲页数 = 不适用 高水位标记(页) = 不适用 页大小(字节) = 4096 盘区大小(页) = 32 预读取大小(页) = 32 容器数 = 1 状态更改表空间标识 = 2 状态更改对象标识 = 59
db2 select tabname,tableid from syscat.tables where tableid=59 查看是哪张表挂起
表名知道后到db2move.lst(在db2move YOURDB export的目录中)中找到相应的.ixf文件 db2 load from tab11.ixf of ixf terminate into db2admin.xxxxxxxxx tab11.ixf对应的是xxxxxxxxx表
数据库会恢复正常,可再用db2 list tablespaces show detail查看
30.不能通过GRANT授权的权限有哪种?
SYSAM
SYSCTRL
SYSMAINT
要更该述权限必须修改数据库管理器配置参数
31.表的类型有哪些?
永久表(基表)
临时表(说明表)
临时表(派生表)
32.如何知道一个用户有多少表?
SELECT*FROMSYSIBM.SYSTABLESWHERECREATOR='USER'
33.如何知道用户下的函数?
select*fromIWH.USERFUNCTION
select*fromsysibm.SYSFUNCTIONS
34.如何知道用户下的VIEW数?
select*fromsysibm.sysviewsWHERECREATOR='USER'
35.如何知道当前DB2的版本?
select*fromsysibm.sysvERSIONS
36.如何知道用户下的TRIGGER数?
select*fromsysibm.SYSTRIGGERSWHERESCHEMA='USER'
37.如何知道TABLESPACE的状况?
select*fromsysibm.SYSTABLESPACES
38.如何知道SEQUENCE的状况?
select*fromsysibm.SYSSEQUENCES
39.如何知道SCHEMA的状况?
select*fromsysibm.SYSSCHEMATA
40.如何知道INDEX的状况?
select*fromsysibm.SYSINDEXES
41.如何知道表的字段的状况?
select*fromsysibm.SYSCOLUMNSWHERETBNAME='AAAA'
42.如何知道DB2的数据类型?
select*fromsysibm.SYSDATATYPES
43.如何知道BUFFERPOOLS状况?
select*fromsysibm.SYSBUFFERPOOLS |
本文为张军原创文章,转载无需和我联系,但请注明来自张军的军军小站,个人博客http://www.zhangjunbk.com