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://m.eyofj.com
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
