Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

DB2 on Linux 核心操作指令速查:安裝、實例/資料庫/表管理、啟停、權限、常用維護命令

編輯:Linux 教學

1. 安裝

./db2_install
# 選擇產品關鍵字:DB2.ESE (企業版)、DB2.ADMCL (管理客戶端)、DB2.ADCL (開發客戶端)
# 範例輸入:DB2.ESE
# 日誌:/tmp/db2_install_log.xxxx

2. 實例管理

建立實例前建用戶/群組

groupadd db2iadm1   # 實例擁有者群組
groupadd db2fadm1   # Fenced 用戶群組
useradd -g db2iadm1 -m -d /home/db2inst1 -p password db2inst1
useradd -g db2fadm1 -m -d /home/db2fenc1 -p password db2fenc1

建立實例

/opt/ibm/db2/V11.5/instance/db2icrt -u db2fenc1 db2inst1
# -u 指定 fenced 用戶

啟動/停止實例

su - db2inst1
db2start
db2stop
# 強制停止
db2stop force

查看實例

db2ilist                 # 列出所有實例
db2 get instance         # 當前實例
# 輸出:The current database manager instance is: db2inst1

刪除實例

/opt/ibm/db2/V11.5/instance/db2idrop inst_name

3. 資料庫操作

建立資料庫

db2 "create database mydb automatic storage yes"
# 或指定代碼頁/編碼
db2 "create database mydb using codeset utf-8 territory CN"

連線/斷開

db2 connect to mydb
db2 connect reset

列出資料庫

db2 list db directory

表空間查看

db2 list tablespaces show detail
db2pd -tablespaces -db mydb

4. 表與資料操作

# 建表
db2 "create table mytable (id int not null primary key, name varchar(30))"

# 列表
db2 list tables

# 插入
db2 "insert into mytable values (1, 'test')"

# 查詢
db2 "select * from mytable"

# 授權 (範例)
db2 "grant select on table mytable to user appuser"

5. 應用/連線監控

db2 list applications
# 輸出含 Auth ID, Application Name, Handle, Application ID, DB, #Agents

6. 進程檢視

ps -ef | grep db2
# 關鍵進程:db2sysc (主引擎)、db2ipccm (IPC)、db2resync (重同步)、db2agent (代理)、db2hmon (健康監控)

7. 版本與修補

db2level                # 顯示版本/修補包資訊
db2ls                   # 列出安裝路徑/版本

避坑提醒

  • 實例擁有者需具備 CAP_IPC_LOCK 等權限,建議用 root 執行 db2icrt。
  • 資料庫建立後預設啟用自動存儲,表空間自動擴展。
  • 生產環境務必配置 db2updatecfg 定期離線/線上備份。
  • 中文環境注意 LANG=zh_CN.UTF-8 避免 CLI 亂碼。
Copyright © Windows教程網 All Rights Reserved