前言
- db2版本:10.5
- 实例所有者:db2inst1
- 待新建数据库:ticm,授权用户:ticm/123456。(用户是系统用户)
创建数据库
- 建库
# create database ticm: 创建名为ticm的数据库 # automatic storage yes: 自动存储器 # on '/home/ticm' dbpath on '/home/ticm': 存储路径和数据库路径 # using codeset gbk territory cn: 使用gbk编码,地域为中国。(也可以使用UTF-8编码) # collate using system: 排序类型。system表示以系统代码集排序 # pagesize 16384: 默认页大小为16KB db2 create database ticm automatic storage yes on '/home/ticm' dbpath on '/home/ticm' using codeset gbk territory cn collate using system pagesize 16384
- 查看数据库信息:
db2 list db directory
- 连接数据库测试
db2 connect to ticm user ticm using 123456
- 使用db2inst1用户进行授权
db2 terminate db2 connect to ticm db2 grant dbadm on database to user ticm
- 创建表空间
# 使用db2instl1连接数据库 db2 connect to ticm user db2inst1 using 123456 # 查看表空间(一般会自动创建四个) db2 list tablespaces # 创建缓冲池 db2 create bufferpool ticm_pool size 8000 pagesize 32k # 创建表空间:TICM_DATA_TBS、 TICM_IDX_TBS和TICM_TEMP db2 create large tablespace TICM_DATA_TBS pagesize 32k managed by automatic storage extentsize 32 overhead 10.5 prefetchsize 32 transferrate 0.14 bufferpool ticm_pool db2 create regular tablespace TICM_IDX_TBS pagesize 32k managed by automatic storage extentsize 32 overhead 10.5 prefetchsize 32 transferrate 0.14 bufferpool ticm_pool db2 create user temporary tablespace TICM_TEMP pagesize 32k managed by automatic storage extentsize 32 overhead 10.5 prefetchsize 32 transferrate 0.14 bufferpool ticm_pool # 为表空间赋权 db2 grant use of tablespace TICM_DATA_TBS TO user ticm with grant option db2 grant use of tablespace TICM_IDX_TBS TO user ticm with grant option db2 grant use of tablespace TICM_TEMP TO user ticm with grant option
删除数据库
# 一般步骤。注意修改数据库名 db2 terminate db2 drop db dbname # 强删。注意修改数据库名 db2 force application all; db2 terminate; db2 drop db dbname