Extracting database structure DDL using Db2look
Extracting DDL
$ db2look–d testdb–a–e–x–o testdb.sql
To export all the data in the specified database:
$ db2move testdb export–u db2inst1–p thepasswd
Exporting data using the DB2 export directive
Unlike the export features of the db2move mentioned above, DB2 export is a more granular exporting tool that supports three types of data file formats: DEL, WSF, IXF.
The following example exports the data from table Mytbl in database TestDB and stores it under Directory/home/backup.
To establish a connection to the database:
$ db2
DB2 = Connect to TestDB user Db2inst1 using thepasswd
Export in del format:
DB2 = Export To/home/backup/mytbl.txt of del select * Frommytbl
Export in IXF format:
DB2 = export TO/HOME/BACKUP/MYTBL.IXF of IXF SELECT * FROMMYTBL
Importing data using the DB2 import directive
Import and export are a pair of directives that have a corresponding relationship, and a little different is that import supports four formats: ASC, DEL, WSF, IXF, and export only supports three (see the description of the corresponding section above).
The following example imports the data file/home/movedata/mytbl.ixf into the database mytestdb.
$ db2
DB2 = Connect to mytestdb user Db2inst1 using THEPASSWD
DB2 = Import from/home/movedata/mytbl.ixf of ixf insert Intomytbl
DB2 = Commit Work
DB2 = Connect Reset
DB2 = quit
DB2 Database Operations