zoukankan      html  css  js  c++  java
  • DB2 db2move导入导出数据及使用dblook导出表结构DDL

    DB2 db2move导入导出数据及使用dblook导出表结构


    —导出数据,先cd到指定目录下(全库导出)
    db2move dbname export  -u userid -p password

    db2move dbname export  -u db2inst1 -p password


    —导出数据,先cd到指定目录下(-sn schema name)
    db2move dbname export  -u userid -p password -sn user1

    —导出单表表结构,先cd到指定目录下(-e 生成DDL文件, -a 所有用户的对象DDL信息, -x 生成授权DDL, -o 输出的文件名, -t 指定表名称)
    db2look -d dbname -i userid -w password -e -a -x -o table1.sql -t "TABLE1"

    —导入数据,先cd到指定目录下
    db2 import from tab1.ixf of ixf messages table1.log insert into table1


    db2move 官方说明
    db2move -h

    # db2move - database movement tool

    --------db2move - database movement tool--------

     Usage: "db2move <dbname> <action> [options]"

      <dbname> is the name of the database.

      <action> is one of:
         EXPORT - Export all tables that meet the filtering criteria in [options]
                  (If no [options] specified, export all tables).
                  Internal staging information is stored in file 'db2move.lst'.
                  Messages are stored in 'EXPORT.msg'.

         IMPORT - Import all tables listed in the staging file 'db2move.lst'.
                  Messages are stored in 'IMPORT.msg'..
                  Use the -io option for IMPORT specific actions.

         LOAD   - Load all tables listed in the staging file 'db2move.lst'.
                  Messages are stored in 'LOAD.msg'.
                  Use the -lo option for LOAD specific actions.

         COPY   - Duplicate a schema(s) into a target database.
                  Use the -sn option to specify one or more schemas.
                  See the -co option for COPY specific options.
                  Use the -tn or -tf option to filter tables in LOAD_ONLY mode.
                  Messages are stored in 'COPY.<timestamp>.msg'
                  Error only messages in 'COPY.<timestamp>.err'
                  Load messages in 'LOADTABLE.<timestamp>.msg'
                  List of tables that failed Load in 'LOADTABLE.<timestamp>.err'


      [options] are one or more of:

        Option      Description                  Use for   Notes
                                                 Action
      ------------------------------------------------------------------------
      -tc <value>  Table Definers. Filter on     EXPORT   Comma seperated list,
                    SYSCAT.TABLES.DEFINER                 Wildcard (*) allowed.

      -tn <value>  Table Names. Filter on        EXPORT   Comma seperated list,
                    SYSCAT.TABLES.TABNAME        COPY     Wildcard (*) allowed for
                                                          EXPORT (not COPY).

      -sn <value>  Schema Names. Filter on       EXPORT,  Comma seperated list,
                    SYSCAT.TABLES.TABSCHEMA      COPY     Wildcard (*) allowed for
                                                          EXPORT (not COPY).

      -ts <value>  Tablespace Names. Filter on   EXPORT   Comma seperated list,
                    SYSCAT.TABLES.TBSPACE                 Wildcard (*) allowed.

      -tf <file>   Fully qualified list of       EXPORT   one table per line,like:
                    table names in <file>        COPY      "MYSCHEMA1"."TAB1"
                                                           "MY SCHEMA2"."TAB2"

      -aw          Allow warnings                EXPORT   Don't disclude tables
                                                          that encounter warnings.

      -io <value>  IMPORT specific actions.      IMPORT   One of: INSERT,
                   Default is REPLACE_CREATE               INSERT_UPDATE, REPLACE,
                   (see docs for limitations               CREATE, REPLACE_CREATE
                    of Import create function)

      -lo <value>  LOAD specific options.        LOAD     One of: INSERT,
                    Default is INSERT                      REPLACE

      -l <path>    Path to lobfiles.             EXPORT,  Comma seperated list,
                    Default is cwd               IMPORT,  no space characters
                                                 LOAD

      -u <value>   Userid to connect to db.      ALL
                    Default is current user

      -p <value>   Password to connect to db.    ALL

      -co <opt>    COPY specific options.        COPY     See options listed below.

          TARGET_DB <dbname> [USER <userid> [USING <passwd>]
             This mandatory option specifies the target database (and optional
             user/passwd) where the schema(s) will be created. (Default
             user/passwd are current user/passwd).
          MODE <value>
             The mode is one of DDL_AND_LOAD (default), DDL_ONLY, or LOAD_ONLY.
          SCHEMA_MAP <value>
             To rename the schema on the target db. For example, to rename schema
             'srcsch1' to 'tgtsch1', and schema 'srcsch2' to 'tgtsch2', use:
             "((srcsch1,tgtsch1), (scrsch2,tgtsch2))".
          TABLESPACE_MAP <value>
             To override tablespaces on the target db. For example, to
             recreate all tables that reside in TS1 on the source db, into TS2 on
             the target db, and all other tablespaces to use the default tablespace
             on the target, use: "((TS1,TS2), SYS_ANY)".
          NONRECOVERABLE
             To override the default Load recoverability action COPY-NO, to
             NONRECOVERABLE.
          OWNER <owner-name>
             To override the owner of each new object created on the target db.


    Examples:
      1) Use db2move to Export all tables:
          >db2move dbname EXPORT
      2) Use db2move to Export all tables, filtering on table-name with 'mytab*'
         and table-definer with 'USER1', and lobs in /bigfs/mydir/:
          >db2move dbname EXPORT -tn mytab* -tc USER1 -l /bigfs/mydir/
      3) Use db2move to Import (recreate and repopulate) all previously exported
         tables:
          >db2move dbname IMPORT
      4) Use db2move to Load (repopulate) all previously exported tables:
          >db2move dbname LOAD
      5) Use db2move to Load (append) all previously exported tables, where
         lobfiles reside in /bigfs/mydir:
          >db2move dbname LOAD -lo INSERT -l /bigfs/mydir
      6) Use db2move to duplicate schema 'schema1' from source database 'dbsrc'
         to target database 'dbtgt':
          >db2move dbsrc COPY -sn schema1 -co TARGET_DB dbtgt
            USER myuser1 USING mypass1
      7) Use db2move to duplicate schema 'schema1' from source database 'dbsrc'
         to target database 'dbtgt', rename the schema to 'newschema1' on the
         target, and map source tablespace 'ts1' to 'ts2' on the target:
          >db2move dbsrc COPY -sn schema1 -co TARGET_DB dbtgt
            USER myuser1 USING mypass1 SCHEMA_MAP ((schema1,newschema1))
            TABLESPACE_MAP ((ts1,ts2), SYS_ANY))

    For more information, please see the DB2 documentation.

    db2look 官方说明

    ----------------------------
    https://www.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0002051.html

    db2look:生成 DDL 以便重新创建在数据库中定义的对象
    命令:db2look -d DBname -a -e -p -i userID -w password -o d:/sample.sql

    语法: db2look -d DBname [-e] [-u Creator] [-z Schema] [-t Tname1 Tname2...TnameN] [-h] [-o Fname] [-a]
                         [-m] [-c] [-r] [-l] [-x] [-xd] [-f] [-td x] [-noview] [-i userID] [-w password]
                         [-wrapper WrapperName] [-server ServerName] [-nofed]

             db2look -d DBname [-u Creator] [-s] [-g] [-a] [-t Tname1 Tname2...TnameN]
                         [-p] [-o Fname] [-i userID] [-w password]

             db2look [-h]

            -d: 数据库名:这必须指定
            -e: 抽取复制数据库所需要的 DDL 文件
                 此选项将生成包含 DDL 语句的脚本
                 可以对另一个数据库运行此脚本以便重新创建数据库对象
                 此选项可以和 -m 选项一起使用
            -u: 创建程序标识:若 -u 和 -a 都未指定,则将使用 $USER
                 若指定了 -a 选项,则将忽略 -u 选项
            -z: 模式名:如果同时指定了 -z 和 -a,则将忽略 -z
                 联合部分的模式名被忽略
             -t: 生成指定表的统计信息
                 可以指定的表的数目最多为 30
            -h: 更详细的帮助消息
            -o: 将输出重定向到给定的文件名
                若未指定 -o 选项,则输出将转到 stdout
            -a: 为所有创建程序生成统计信息
                 若指定了此选项,则将忽略 -u 选项
           -m: 在模拟方式下运行 db2look 实用程序
                此选项将生成包含 SQL UPDATE 语句的脚本
                这些 SQL UPDATE 语句捕获所有统计信息
                可以对另一个数据库运行此脚本以便复制初始的那一个
                当指定了 -m 选项时,将忽略 -p、-g 和 -s 选项
           -c: 不要生成模拟的 COMMIT 语句
                除非指定了 -m 或 -e,否则将忽略此选项
                将不生成 CONNECT 和 CONNECT RESET 语句
           -r: 不要生成模拟的 RUNSTATS 语句
                缺省值为 RUNSTATS。仅当指定了 -m 时,此选项才有效
            -l: 生成数据库布局:数据库分区组、缓冲池和表空间。
           -x: 如果指定了此选项,则 db2look 实用程序将生成授权 DDL
                对于现有已授权特权,不包括对象的原始定义器
         -xd: 如果指定了此选项,则 db2look 实用程序将生成授权 DDL
                对于现有已授权特权,包括对象的原始定义器
           -f: 抽取配置参数和环境变量
                如果指定此选项,将忽略 -wrapper 和 -server 选项
          -td: 将 x 指定为语句定界符(缺省定界符为分号(;))
                应该与 -e 选项一起使用(如果触发器或者 SQL 例程存在的话)
           -p: 使用简单文本格式
           -s: 生成 postscript 文件
                此选项将为您生成 postscript 文件
                当设置了此选项时,将除去所有 latex 和 tmp ps 文件
                所需的(非 IBM)软件:LaTeX 和 dvips
                注意:文件 psfig.tex 必须在 LaTeX 输入路径中
           -g: 使用图形来显示索引的页取装对
                必须安装 Gnuplot,并且 <psfig.tex> 必须在您的 LaTeX 输入路径中
                还将随 LaTeX 文件一起生成 <filename.ps> 文件
           -i: 登录到数据库驻留的服务器时所使用的用户标识
         -w: 登录到数据库驻留的服务器时所使用的密码
       -noview: 不要生成 CREATE VIEW ddl 语句
      -wrapper: 为适用于此包装器的联合对象生成 DDL
                生成的对象可能包含下列各项:
                包装器、服务器、用户映射、别名、类型映射、
                函数模板、函数映射和索引规范
       -server: 为适用于此服务器的联合对象生成 DDL
                生成的对象可能包含下列各项:
                包装器、服务器、用户映射、别名、类型映射、
                函数模板、函数映射和索引规范
        -nofed: 不要生成 Federated DDL
                如果指定此选项,将忽略 -wrapper 和 -server 选项

    LaTeX 排字: latex filename.tex 以获得 filename.dvi

    示例: db2look -d DEPARTMENT -u walid -e -o db2look.sql

     -- 这将生成由用户 WALID 创建的所有表和联合对象的 DDL 语句
     -- db2look 输出被发送到名为 db2look.sql 的文件中

    示例: db2look -d DEPARTMENT -z myscm1 -e -o db2look.sql

     -- 这将为模式名为 MYSCM1 的所有表生成 DDL 语句
     -- 还将生成 $USER 创建的所有联合对象的 DDL。
     -- db2look 输出被发送到名为 db2look.sql 的文件中

    示例: db2look -d DEPARTMENT -u walid -m -o db2look.sql

     -- 这将生成 UPDATE 语句以捕获关于用户 WALID 创建的表/别名的统计信息
     -- db2look 输出被发送到名为 db2look.sql 的文件中

    示例: db2look -d DEPARTMENT -u walid -e -wrapper W1 -o db2look.sql

     -- 这将生成由用户 WALID 创建的所有表的 DDL 语句
     -- 还将生成适用于包装器 W1 的用户 WALID 所创建所有联合对象的 DDL
     -- db2look 输出被发送到名为 db2look.sql 的文件中

    示例: db2look -d DEPARTMENT -u walid -e -server S1 -o db2look.sql

     -- 这将生成由用户 WALID 创建的所有表的 DDL 语句
     -- 还将生成适用于服务器 S1 的用户 WALID 所创建所有联合对象的 DDL
     -- db2look 输出被发送到名为 db2look.sql 的文件中

  • 相关阅读:
    域渗透基础(二)
    域渗透基础(一)
    域环境搭建
    java基础(五)-----new一个对象的具体过程
    数据结构(八)-----散列表
    数据结构(七)-----跳表
    数据结构(六)-----队列
    数据结构(五)-----栈
    数据结构(四)-----链表
    数据结构(三)-----数组
  • 原文地址:https://www.cnblogs.com/fengaix6/p/8066102.html
Copyright © 2011-2022 走看看