Import and Export DB2 Data
In the DB2 database, we can import and export the data through the commands. The following introduces the two process in detail.
Export data from the database
- Sign in the operating system as the DB2 database user.
- Create a new empty folder, which is used to store the data exported from the server database.
- Execute the db2cmd command in the Run to enter the command window. And use the cd command to enter the folder which is stores the data (namely the new folder).
- Execute the following command and export the statement:
Copy
db2look -d dbname -e -c -o *.sql -i username -w password
- dbname: The name of server database.
- *.wql: The sql file of exported statements for building table.
- username: The user name of server database.
- password: The password of server database.
- Execute the following command and export the data of data table:
Copy
db2move dbname export>*.log -u username -p password
- After execute these commands, the data will be imported to the new folder.
Import the data into the database
- Sign in the operating system as the DB2 database user.
- Create a new empty folder, which is used to store the data imported to the server database.
- Execute the db2cmd command in the Run to enter the command window. And use the cd command to enter the folder which is stores the data (namely the new folder).
- Execute the following command and import to the datasheet:
Copy
db2 -tvf *.sql
- Execute the following command and import to the data of data table:
Copy
db2move dbname import -u username -p password
- After execute the command, the data will be imported into the database of server.
Note
About authorization. When export the DB2 database, it needs to give the corresponding permissions to the users. Here it gives the administrator permission of db2admin.