db2 创建数据库及表空间语句
1、首先在windows安装完DB2以后,打开DB2的命令行,然后依次执行下面代码.(下面有一句话脚本会提示你一个类似异常的信息,不予以理会,继续执行下面别的代码)
- db2 "CREATE DB TestDB using codeset UTF-8 territory us"
- db2 "UPDATE DB CFG FOR TestDB USING applheapsz 4096"
- db2 "UPDATE DB CFG FOR TestDB USING app_ctl_heap_sz 1024"
- db2 "UPDATE DB CFG FOR TestDB USING stmtheap 8192"
- db2 "UPDATE DB CFG FOR TestDB USING dbheap 2400"
- db2 "UPDATE DB CFG FOR TestDB USING locklist 1000"
- db2 "UPDATE DB CFG FOR TestDB USING logfilsiz 1000"
- db2 "UPDATE DB CFG FOR TestDB USING logprimary 12"
- db2 "UPDATE DB CFG FOR TestDB USING logsecond 20"
- db2 "UPDATE DB CFG FOR TestDB USING logbufsz 32"
- db2 "UPDATE DB CFG FOR TestDB USING avg_appls 5"
- db2 "UPDATE DB CFG FOR TestDB USING locktimeout 30"
- db2 CONNECT TO TestDB
- db2 "CREATE BUFFERPOOL icmsbuffer SIZE 1000 PAGESIZE 32K"
- db2 "CREATE TABLESPACE icmsspace PAGESIZE 32K MANAGED BY SYSTEM USING ('D:\db2admin\sqlt0003.0') BUFFERPOOL icmsbuffer"(根据实际情况确定是否是D盘下的db2admin\sqlt0003.0目录,如果没有,请先创建)
- db2 "CREATE SYSTEM TEMPORARY TABLESPACE ICMSBUF PAGESIZE 32 K MANAGED BY SYSTEM USING ('D:\db2admin\sqlt0004.0') BUFFERPOOL ICMSBUFFER"(根据实际情况确定是否是D盘下的db2admin\ sqlt0004.0目录,如果没有,请先创建)
- db2 "DISCONNECT icms"
- db2 "TERMINATE"
下面说在linux下的创建方法:其实脚本一样
数据库是从 DB2 命令界面创建的。在启动命令界面之前,必须符合以下条件:
1、DB2必须是活动的。
2、对于 AIX、Linux和 Solaris, DB2 实例拥有者标识(例如 db2inst1)必须是 db2admin组的一部分。db2admin组是在 DB2通用数据库安装过程中创建的。
3、修改修改环境变量,能够正确执行db2的命令
4、根据实际环境修改标红色的路径,比如:/home/icms/。
5、因在执行的过程中脚本出错,后续回滚将会非常非常,建议一个个脚本执行。
- db2 "CREATE DB icms using codeset UTF-8 territory us"
- db2 "UPDATE DB CFG FOR icms USING applheapsz 4096"
- db2 "UPDATE DB CFG FOR icms USING app_ctl_heap_sz 1024"
- db2 "UPDATE DB CFG FOR icms USING stmtheap 8192"
- db2 "UPDATE DB CFG FOR icms USING dbheap 2400"
- db2 "UPDATE DB CFG FOR icms USING locklist 1000"
- db2 "UPDATE DB CFG FOR icms USING logfilsiz 1000"
- db2 "UPDATE DB CFG FOR icms USING logprimary 12"
- db2 "UPDATE DB CFG FOR icms USING logsecond 20"
- db2 "UPDATE DB CFG FOR icms USING logbufsz 32"
- db2 "UPDATE DB CFG FOR icms USING avg_appls 5"
- db2 "UPDATE DB CFG FOR icms USING locktimeout 30"
- db2 CONNECT TO icms
- db2 "CREATE BUFFERPOOL icmsbuffer SIZE 1000 PAGESIZE 32K"
- db2 "CREATE TABLESPACE icmsspace PAGESIZE 32K MANAGED BY SYSTEM USING ('/home/icms/sqlt0003.0') BUFFERPOOL icmsbuffer"
- db2 "CREATE SYSTEM TEMPORARY TABLESPACE ICMSBUF PAGESIZE 32 K MANAGED BY SYSTEM USING ('/home/icms/sqlt0004') BUFFERPOOL ICMSBUFFER"
- db2 "DISCONNECT icms"
- db2 "TERMINATE"