db2 9.7 for linux 5.4安裝詳細步驟
1、解壓縮安裝包
#gunzip v9.7_linuxia32_server.tar.gz
#tar -xvf v9.7_linuxia32_server.tar
2、進入解壓後的文件目錄,執行安裝:(我們選擇手動安裝)
注意:DB2_install為手動安裝 db2_setup為圖形安裝
www.2cto.com
#./Db2_install-------no-----aese
3、創建DB2運行所需的組和用戶:
#groupadd -g 901 db2grp
#groupadd -g 902 db2fgrp
#groupadd -g 903 db2agrp
#useradd -g db2grp -u 801 -d /home/db2inst1-m -s /bin/bash db2inst1 --管理當前實例
#useradd -g db2fgrp -u 802 -d /home/db2fenc-m -s /bin/bash db2fenc
#useradd -g db2agrp -u 803 -d /home/db2das-m -s /bin/bash db2das --管理所有實例
4、設置密碼:
passwd db2inst1
passwd db2fenc
passwd db2das
5、創建實例
#cd /opt/ibm/db2/V9.7/instance
#./dascrt -u db2das
#./db2icrt -u db2inst1 db2inst1
注意:DBI1922N The host name is not valid.報無法解析錯誤,在/etc/hosts文件中添加解析參數即可 www.2cto.com
注釋:
Dascrt:創建的是DB2 adminstration server,每台服務器只有一個這種server,為進行DB2管理(比如運行控制中心)所必須,同時指定其管理用戶是db2das。
db2icrt:創建的是實例,其名字一般和管理用戶名一樣,這裡均為db2inst1。
6、啟動DB2
# su - db2das
$ db2admin start ----啟動DB2管理服務器
SQL4409W The DB2 Administration Server is already active.
$su - db2inst1
$ db2start ----啟動數據庫實例
05/07/2012 01:30:04 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
7、檢查DB2是否起來,狀態如下:
[db2inst1@jetsen ~]$ ps -ef|grep db2
db2das 10828 1 0 01:23 ? 00:00:00 /home/db2das/das/adm/db2dasrrm
root 11345 1 0 01:23 ? 00:00:00 /opt/ibm/db2/V9.7/bin/db2fmcd
db2das 11354 1 0 01:23 ? 00:00:00/opt/ibm/db2/V9.7/das/bin/db2fmd -i db2das -m/opt/ibm/db2/V9.7/das/lib/libdb2dasgcf.so.1
root 17267 2768 0 01:29 pts/1 00:00:00 su - db2das
db2das 17268 17267 0 01:29 pts/1 00:00:00 -bash
root 17329 17268 0 01:29 pts/1 00:00:00 su - db2inst1
db2inst1 17332 17329 0 01:29 pts/1 00:00:00 -bash
root 17446 1 1 01:29 pts/1 00:00:01 db2wdog 0
db2inst1 17448 17446 1 01:29 pts/1 00:00:01 db2sysc 0
root 17449 17448 0 01:29 pts/1 00:00:00 db2ckpwd 0
root 17450 17448 0 01:29 pts/1 00:00:00 db2ckpwd 0 www.2cto.com
root 17451 17448 0 01:29 pts/1 00:00:00 db2ckpwd 0
db2inst1 17455 17448 1 01:30 pts/1 00:00:01 db2vend (PD Vendor Process -1)
db2inst1 17462 17446 0 01:30 pts/1 00:00:01 db2acd 0,0,0,0,1,0,0,0000,1,0,8a67a4,14,1e014,2,0,1,11fd0,0x125f0000,0x125f0000,1600000,588003,2,b5800b
db2inst1 17494 17332 0 01:32 pts/1 00:00:00 ps -ef
db2inst1 17495 17332 0 01:32 pts/1 00:00:00 grep db2
[db2inst1@jetsen ~]$
8、配置DB2自動啟動,用root用戶登錄
#cd /opt/ibm/db2/V9.7/instance/
# ./db2iauto -on db2inst1
9、配置網絡
#su - db2inst1
$db2 update dbm cfg using SVCENAME50000 ----改變DB2的遠程訪問端口,默認是5000
$db2set DB2COMM=TCPIP ----修改DB2的連接方式為TCPIP,
注意:也可以通過JDBC,ODBC等方式來訪問DB2數據庫
10、實例的啟動和關閉
#su - db2inst1
$db2 force applications all ----關閉所有和DB2相關的應用程序
$db2stop ----關閉數據庫實例
$db2start ----啟動數據庫實例
11、創建數據庫
#su - db2inst1
$db2 create database test ----創建數據庫實例
DB20000I The CREATE DATABASE command completed successfully.
12、連接到我們剛才創建的數據庫
#su - db2inst1
$db2 www.2cto.com
db2 => Connect to test user db2inst1
Enter current password for db2inst1:
Database Connection Information
Database server = DB2/LINUX 9.7.5
SQLauthorization ID = DB2INST1
Local database alias = TEST
db2 =>
附錄:
1、創建演示數據庫
#su - db2inst1
$ $cd /opt/ibm/db2/V9.7/bin
$ ./db2sampl
Creating database "SAMPLE"...
Connecting to database "SAMPLE"...
Creating tables and data in schema "DB2INST1"...
Creating tables with XML columns and XML data in schema"DB2INST1"...
'db2sampl' processing complete.
2、訪問剛創建的數據庫
$ db2
www.2cto.com
db2 => connect to sample
Database Connection Information
Database server = DB2/LINUX 9.7.5
SQLauthorization ID = DB2INST1
Local database alias = SAMPLE
db2 =>
3、常用操作命令
db2 =>connect to sample ---連接到sample數據庫
db2 =>list tables ---查看庫下面的所有表
db2 => select * from staff wheredept=10 ---查詢某張表dept等於10的所有記錄
db2 => quit www.2cto.com ---退出db2
DB20000I The QUIT command completed successfully.
$ db2ilist; ---查看實例列表
db2inst1
$ db2 get instance ---查看當前所運行的實例
Thecurrent database manager instance is: db2inst1
作者 吳偉龍