2011年12月20日 星期二

How to create Instance and Database in DB2

DB2 - in linux platform
1) Create a instance
db2icrt -u instance_name instance_name
* My DB2 location is /DB2/V9.7

Example:
[root@VM01 instance]# /DB2/V9.7/instance/db2icrt -u db2inst1 db2inst1
DBI1070I  Program db2icrt completed successfully.


2) Create Databae
su - instance_owner
export db2instance=instance_name
db2start
db2 create database database_name

Example:
[root@VM01 instance]# su - db2inst1
[db2inst1@VM01 ~]$ export db2instance=db2inst1
[db2inst1@VM01 ~]$ echo $db2instance
db2inst1
[db2inst1@VM01 ~]$ db2start
SQL1063N  DB2START processing was successful.
[db2inst1@VM01 ~]$ db2 create database test_db

DB20000I  The CREATE DATABASE command completed successfully.

command for Oracle and DB2 startup

Start/Stop instance command

Oracle DB - 1 instance = 1 database
startup (nomount, mount, open) Simple 'startup' is same as 'startup open'
shutdown (normal, immediate, abort) normally we use shutdown immediate for normal db shutdown

DB2 - 1 instance = Muti database
db2starup (start instance)
db2stop (stop instance)
base on the user name for each instance

Mysql - 1 instance = Muti database
instance contain one database storing login/tablespace/table info


Connect to Database

Oracle DB - in account 'oracle'
sqlplus / as sysdba

DB2 - in account 'db2inst1'
db2 connect to dbname

Exit from Database

Oracle DB
sql > exit

DB2
db2 terminate

新開的BLOG~

做了千百年的伸手黨~才發覺有個BLOG記事比較方便~所以就建一個了