Summary of problems in using the exp imp command

        exp imp is a common command for database export and import, but there are often some strange problems that make people very distressed. Today I record the problems I encountered here, hoping to help people who have the same confusion.

        In the case of the first version, we all back up a library from a server, and imp to the required database when needed. So we start with exp.

 

1. exp

  1.  How to write exp export basic commands
    exp username/password@database file=export file storage location\filename.dmp log=log file location\log filename.txt
     
    exp test/test@orcl file=D:\dmp\test.dmp log=D:\log\log.txt
    Note: orcl refers to the service name you are connecting to the database. Then the question comes, what if the service name is not configured.
    exp text/[email protected]:1521/orcltest file=D:\test.dmp log=D:\log.txt
     That is to say, you can use ip: database port number/database instance name to connect.

    Warm reminder, the log path here must exist. Otherwise, an error that the file cannot be opened will be reported.


     
  2. exp Empty table is not exported
    From the exported log, it may be found that the exported table is less than the table owned by the exporting user, because this table is an empty table.
    select t.SEGMENT_CREATED,t. * from user_tables t where num_rows = 0 or num_rows is null;
     SEGMENT_CREATED is listed separately because it indicates whether the table is allocated a segment, and it cannot be exported without allocation.



     Among them, TEST3 is an empty table, which cannot be exported when exporting.


     
    At this point, you need to set up the table and allocate space to the table.

    alter table tableName allocate extent;
     Because if there are many empty tables, how to set them in batches.
    select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows = 0 or num_rows is null;
     Execute the generated batch set statements together. Then you can export the empty table by executing the export statement.
  3. It should be noted that before exporting, look at the name of the user tablespace, so that the corresponding tablespace can be created in advance when importing, otherwise the report space will not exist and cannot be imported.
    select t.username,t.default_tablespace from dba_users t where t.username='TEST';
     

 2. imp 

  1. Before importing, if the user you want to import already exists in the library, you need to delete the user first. When it comes to deleting, someone will definitely encounter a prompt that the user has a connection and cannot be deleted.

     At this time, you have to kill the connected session first.
    select t.sid,t.serial# from V$session t where t.username='TEST';
    result:
            sid     serial#
    ----------   --------
    1	63	115
    
    alter system kill session 'sid,serial#';
    alter system kill session '63,115';
    
     If it is found that there are many sessions for this user, delete them in batches.
    select 'alter system kill session ',''''||trim(sid)||','||trim(serial#)||''';' from v$session where username='TEST'
     批量杀掉会话后就可以删掉这个用户了,然后重新创建用户。以备导入使用
  2.  如果导出时发现需要特定的表空间,那么就得创建表空间
    create tablespace Test datafile 'test.dbf' size 50M autoextend on next 1G;
     
  3. imp 基本命令导入
    imp test/test@orcl file=D:/test.dmp log=D:/log.txt fromuser=test touser=test full=y
     

 exp imp 命令的基本用法,和导出、导入容易遇到的问题,希望对你有所帮助!

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326678977&siteId=291194637