DB2 命令
1. 客户端命令: db2 该命令类于oracle的sqlplus, mysql的mysql命令 可以在db2命令后直接跟查询命令,如 db2 list db directory 也可以先运行db2命令,程序启动后,再运行list db directory 2. 列出所有数据库: list db directory 3. 连接数据库: connect to [
1. 客户端命令: "db2"该命令类似于oracle的"sqlplus", mysql的"mysql命令"
可以在"db2"命令后直接跟查询命令,如 "db2 list db directory"
也可以先运行"db2"命令,程序启动后,再运行"list db directory"
2. 列出所有数据库: "list db directory"
3. 连接数据库: "connect to [dbname] user [username] using [password]"
例如 "connect to SAMPLE",连接成功后显示如下信息
-------------------------------------------------------------
Database Connection Information
Database server = DB2/LINUXX8664 10.5.4
SQL authorization ID = DB2INST2
Local database alias = SAMPLE
-------------------------------------------------------------
4. 断开数据库连接: connect reset
5. 创建数据库: create database [dbname]
6. 删除数据库: drop database [dbname]
7. 查询数据库下有哪些表
1) 列出所有表: "list tables for all"2) 列出所有系统表: "list tables for system"
3) 列出所有用户表: "list tables" / "list tables for user"
4) 列出特定用户表: "list tables for schema [user]"
8. 显示表结构: "describe table tablename"
9. 表的创建/插入/修改/查询,标准sql
10. 显示当前数据库管理实例: "get instance"
11. 启用归档日志
老版本(V8.2): db2 update db cfg for [dbname] using LOGRETAIN ON
新版本(V8.2之后): db2 update db cfg for [dbname] using LOGARCHMETH1 LOGRETAIN
12. 离线备份: backup database [dbname] to [path]
如: "backup database sample to /db2/db2inst2/duanbb/backup"
13. 在线备份(要求启用归档日志): backup database [dbname] online to [path]
如: "backup database sample to online /db2/db2inst2/duanbb/backup"
14. 恢复数据库: restore database [dbname] from [path]
如: "restore database sample from /db2/db2inst2/duanbb/backup"