日期:2014-05-16  浏览次数:20498 次

db2 命令(for linux)
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 wz