DB2建立資料庫,建立表空間
首先得開啟 db manager
[db2inst1@localhost ~]$ db2 start db manager
DB20000I The START DATABASE MANAGER command completed successfully.
否則會有如下提示:
[db2inst1@localhost ~]$ db2 create database mydb
SQL1032N No start database manager command was issued. SQLSTATE=57019
開始建立資料庫
[db2inst1@localhost ~]$ db2 create database mydb on '/xxx'
DB20000I The CREATE DATABASE command completed successfully.
注意以上命令沒有指定資料庫路徑
可以用 [db2inst1@localhost V10.1]$ db2 get dbm cfg 檢視資料庫預設建立路徑
我這邊查到的是: Default database path (DFTDBPATH) = /home/db2inst1
把資料庫建立在指定路徑:
[root@localhost db2]# chown -R db2inst1:db2inst1 /db2/shijiaweidb [root@localhost db2]# su - db2inst1 [db2inst1@localhost ~]$ db2 create database mydb1 on /db2/shijiaweidb DB20000I The CREATE DATABASE command completed successfully. |
資料庫建立完成以後出現下面的檔案:
[db2inst1@localhost shijiaweidb]$ du -h 129M ./db2inst1/NODE0000/MYDB1/T0000000 8.0K ./db2inst1/NODE0000/MYDB1/T0000001/C0000000.TMP 12K ./db2inst1/NODE0000/MYDB1/T0000001 33M ./db2inst1/NODE0000/MYDB1/T0000002 161M ./db2inst1/NODE0000/MYDB1 16K ./db2inst1/NODE0000/sqldbdir 4.0K ./db2inst1/NODE0000/SQL00001/MEMBER0000/HADR/TAKEOVER 4.0K ./db2inst1/NODE0000/SQL00001/MEMBER0000/HADR/LOGSPOOL 12K ./db2inst1/NODE0000/SQL00001/MEMBER0000/HADR 12K ./db2inst1/NODE0000/SQL00001/MEMBER0000/db2event/db2detaildeadlock 16K ./db2inst1/NODE0000/SQL00001/MEMBER0000/db2event 116K ./db2inst1/NODE0000/SQL00001/MEMBER0000 4.0K ./db2inst1/NODE0000/SQL00001/HADR/TAKEOVER 4.0K ./db2inst1/NODE0000/SQL00001/HADR/LOGSPOOL 12K ./db2inst1/NODE0000/SQL00001/HADR 12M ./db2inst1/NODE0000/SQL00001/LOGSTREAM0000 14M ./db2inst1/NODE0000/SQL00001 174M ./db2inst1/NODE0000 174M ./db2inst1 174M . |
選擇自動儲存(預設設定)將允許DBA為資料庫設定在建立所有表空間容器時可以使用的儲存路徑。BDA不必定義表空見的大小和位置,系統將自動的分配表空間。例如,下面的資料庫建立語句將為資料庫中的所有表空間設定自動儲存。 [db2inst1@localhost db2]$ db2 create database mydb2 automatic storage yes on /db2/mydbpath001,/db2/mydbpath002,/db2/mydbpath003 DB20000I The CREATE DATABASE command completed successfully. 在ON選項後面,給出了3個檔案目錄(路徑)。這3個路徑是表空間容器的位置,資料庫路徑預設放在第一個路徑下。當使用AUTOMATIC STORAGE定義表空間時,不需要提供其它引數: |
若要顯示所有已建立的資料庫,執行:
[db2inst1@localhost ~]$ db2 list db directory
System Database Directory
Number of entries in the directory = 1
Database 1 entry:
Database alias = MYDB Database name = MYDB Local database directory = /home/db2inst1 Database release level = f.00 Comment = Directory entry type = Indirect Catalog database partition number = 0 Alternate server hostname = Alternate server port number = |
若要刪除一個資料庫可以用下面的命令
db2 drop database
選擇Automatic storage(預設設定)允許DBA為資料庫設定在建立所有表空間時可以使用 可以使用的儲存路徑。
建立表空間的時候出錯,可以看到是沒有連線到資料庫
用如下命令連線到 MYDB 資料庫
成功建立表空間 | ||
|
d b2 force application all -- 強迫所有應用斷開資料庫連線
[db2inst1@localhost bin]$ db2 force application all DB20000I The FORCE APPLICATION command completed successfully. DB21024I This command is asynchronous and may not be effective immediately. |
算開與資料庫MYDB的連線
[db2inst1@localhost bin]$ db2 disconnect MYDB DB20000I The SQL DISCONNECT command completed successfully. |
假如要建立一個同時支援XML和SQL的資料庫,執行下面的命令:
[db2inst1@localhost bin]$ db2 create database xmldb using codeset UTF-8 territory us DB20000I The CREATE DATABASE command completed successfully. |
[db2inst1@localhost bin]$ db2 connect to xmldb
Database Connection Information
Database server = DB2/LINUXX8664 10.1.0 SQL authorization ID = DB2INST1 Local database alias = XMLDB
[db2inst1@localhost bin]$ db2 connect to MYDB
Database Connection Information
Database server = DB2/LINUXX8664 10.1.0 SQL authorization ID = DB2INST1 Local database alias = MYDB |
建立使用者表空間
[db2inst1@localhost ~]$ db2 "create tablespace shijiawei managed by system using ('/db2/shijiawei')"
DB20000I The SQL command completed successfully.
建立DMS自動儲存表空間
要使用命令列自動建立儲存表空間,輸入下面任意語句:
[db2inst1@localhost ~]$ db2 create tablespace test1 DB20000I The SQL command completed successfully.
[db2inst1@localhost ~]$ db2 create tablespace test2 managed by automatic storage DB20000I The SQL command completed successfully. |
建立系統臨時表空間
[db2inst1@localhost ~]$ db2 "create system temporary tablespace tmp_tbsp managed by system using ('/data1/tmp_tbsp','/data2/tmp_tbsp')"
DB20000I The SQL command completed successfully.
建立使用者臨時表空間:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23825935/viewspace-2775007/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- db2 建立bufferpool,表空間DB2
- Oracle建立表空間、建立資料庫使用者、賦許可權Oracle資料庫
- 2.5.9 在資料庫建立期間支援大檔案表空間資料庫
- oracle建立臨時表空間和資料表空間以及刪除Oracle
- oracle建立表空間Oracle
- 建立加密表空間加密
- MySQL 建立資料庫 建立表MySql資料庫
- 建立資料庫表資料庫
- 根據源庫表空間實際使用建立表空間指令碼指令碼
- [DB2]線上備份資料庫與表空間DB2資料庫
- 達夢(DM)資料庫的表空間建立和遷移維護資料庫
- DB2建立聯邦資料庫DB2資料庫
- [DB2]資料庫建立實驗DB2資料庫
- db2 建立資料庫與資料放置DB2資料庫
- 【儲存管理】建立臨時表空間組、建立臨時表空間組及使用
- dbca靜默silent建立資料庫_空間不足出錯資料庫
- PostgreSQL:表空間-->資料庫-->表SQL資料庫
- Oracle建立表空間、建立使用者以及授權Oracle
- PLSQL來Oracle建立表空間和建立使用者SQLOracle
- Oracle OCP(47):表空間的建立Oracle
- 【儲存管理】建立永久表空間
- Oracle表空間建立引數解析Oracle
- Linux下建立Oracle表空間LinuxOracle
- 表空間的建立修改等操作
- oracle 建立表空間完整版Oracle
- 命令建立表空間的基本格式
- SQL建立資料庫和表SQL資料庫
- 指令碼建立表空間、使用者、表指令碼
- 複製建立已有資料庫使用者、表空間、許可權的指令碼資料庫指令碼
- 建立表空間、使用者、擴容、移動資料檔案
- 關於Sybase資料庫中時間表的建立和生成!資料庫
- Oracle建立表空間和使用者Oracle
- oracle 建立表空間和使用者Oracle
- ORACLE表空間的建立修改刪除Oracle
- Oracle 表空間 建立引數 說明Oracle
- db2表空間DB2
- SQL Server 2008 空間資料庫 --- 空間索引概念及建立(取自幫助)SQLServer資料庫索引
- 檢視資料庫表空間資料庫