DB2學習文檔
(一)DB2的安裝說明:
===========================================
[root@fedora home]# ./db2_install
Specify one or more of the following keywords,
separated by spaces, to install DB2 products.
Keyword Product Description
DB2.ESE DB2 Enterprise Server Edition for LINUX
DB2.ADMCL DB2 Administration Client for LINUX
DB2.ADCL DB2 Application Development Client for LINUX
Enter "help" to redisplay product names.
Enter "quit" to exit.
***********************************************************
DB2.ESE
The installation logfile can be found in /tmp/db2_install_log.3439.
db2_install program completed successfully.
(二)實例的相關說明
================================================
(1.)在建立實例前,首先要創建組和用戶
[root@fedora home]# groupadd wangzm
[root@fedora home]# groupadd wzm
[root@fedora home]# useradd -g wangzm -d -m /home/wangzm -p 123456 wangzm
[root@fedora home]# useradd -g wzm -m -d /home/wzm -p 123456 wzm
(2.)實例的創建
[root@fedora home]# /opt/IBM/db2/V8.1/instance/db2icrt -u wangzm wzm
DBI1070I Program db2icrt completed successfully.
(3.)數據庫的啟動
[root@fedora home]# su - wzm
[wzm@fedora ~]$ db2start
05/20/2006 14:27:39 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
(4.)db2的進程
wzm 5981 0.0 14.1 121364 17808 pts/0 S 14:27 0:00 db2sysc
wzm 5987 0.0 13.6 121364 17108 pts/0 S 14:27 0:00 db2ipccm
wzm 5988 0.0 14.1 121364 17808 pts/0 S 14:27 0:00 db2resync
wzm 5989 0.0 12.9 118820 16228 pts/0 S 14:27 0:00 db2srvlst
wzm 5991 0.2 18.8 138584 23760 pts/0 Sl 14:27 0:01 db2hmon ,0,0,0,1,0,0,0,1e014,2,0,1,9fe0,0x11250000,0x11250000,15fc000,98006,2,138017
wzm 6204 0.0 6.0 35996 7624 pts/0 S 14:31 0:00 /home/wzm/sqllib/bin/db2bp 5846A513 5 A
wzm 6285 0.0 14.2 121364 17864 pts/0 S 14:32 0:00 db2agent (idle)
(5.)實例的顯示----顯示所有的
[wzm@fedora ~]$ db2ilist
db2inst1
dl
qing
wzm
(6.)顯示當前的實例
[wzm@fedora ~]$ db2 get instance
The current database manager instance is: wzm
[wzm@fedora ~]$
(7.)刪除一個實例
[root@fedora ~]# /opt/IBM/db2/V8.1/instance/db2idrop qing
DBI1070I Program db2idrop completed successfully.
(8.)列出當前實例中有哪些數據庫
[wzm@fedora ~]$ db2 list db directory
System Database Directory
Number of entries in the directory = 1
Database 1 entry:
Database alias = WZMDB
Database name = WZMDB
Local database directory = /home/wzm
Database release level = a.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
(三.)數據庫的操作說明
===========================================================
(1.) 數據庫的創建
[wzm@fedora ~]$ db2 "create database wzmdb"
DB20000I The CREATE DATABASE command completed successfully.
(2.)連接數據庫
[wzm@fedora ~]$ db2 connect to wzmdb
Database Connection Information
Database server = DB2/LINUX 8.2.0
SQL authorization ID = WZM
Local database alias = WZMDB
()查看表的空間
db2 list tablespaces (show detail)
db2pd -tablespaces -db <數據庫名>
(3.)表的創建
[wzm@fedora ~]$ db2 "create table wzmtb (id int,name varchar(30))"
DB20000I The SQL command completed successfully.
(4.) 顯示數據庫裡有那些表
[wzm@fedora ~]$ db2 list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
WZMTB WZM T 2006-05-20-14.46.34.953560
1 record(s) selected.
(5.) 向表裡添加數據
[wzm@fedora ~]$ db2 "insert into wzmtb values (1,''wzm'')"
DB20000I The SQL command completed successfully.
(6.)顯示表的內容
[wzm@fedora ~]$ db2 "select * from wzmtb"
ID NAME
----------- ------------------------------
1 wzm
1 record(s) selected.
(7.)斷開數據庫的連接
[wzm@fedora ~]$ db2 disconnect wzmdb
DB20000I The SQL DISCONNECT command completed successfully.
(8.)顯示當前數據庫連接的有哪些應用程序
[wzm@fedora ~]$ db2 list application
Auth Id Application Appl. Application Id DB # of
Name Handle Name Agents
-------- -------------- ---------- ------------------------------ -------- -----
WZM db2bp 44 *LOCAL.wzm.060520074504 WZMDB 1
(9.)db2的停止
[wzm@fedora ~]$ db2stop
05/20/2006 15:50:47 0 0 SQL1064N DB2STOP processing was successful.
SQL1064N DB2STOP processing was successful.
(10.)db2的強制停止