How to import an Oracle database from dmp file and log file?

前端 未结 3 1570
南笙
南笙 2021-01-29 19:18

How would I go about creating a database from a dump file? I do not have an existing database with the same structure on my system so it has to be complete with jobs, events, ta

相关标签:
3条回答
  • 2021-01-29 19:31

    All this peace of code put into *.bat file and run all at once:

    My code for creating user in oracle. crate_drop_user.sql file

    drop user "USER" cascade;
    DROP TABLESPACE "USER";
    
    CREATE TABLESPACE USER DATAFILE 'D:\ORA_DATA\ORA10\USER.ORA' SIZE 10M REUSE 
        AUTOEXTEND 
        ON NEXT  5M  EXTENT MANAGEMENT LOCAL 
        SEGMENT SPACE MANAGEMENT  AUTO
    / 
    
    CREATE  TEMPORARY TABLESPACE "USER_TEMP" TEMPFILE 
        'D:\ORA_DATA\ORA10\USER_TEMP.ORA' SIZE 10M REUSE AUTOEXTEND
        ON NEXT  5M  EXTENT MANAGEMENT LOCAL 
        UNIFORM SIZE 1M    
    /
    
    CREATE USER "USER"  PROFILE "DEFAULT" 
        IDENTIFIED BY "user_password" DEFAULT TABLESPACE "USER" 
        TEMPORARY TABLESPACE "USER_TEMP" 
    /    
    
    alter user USER quota unlimited on "USER";
    
    GRANT CREATE PROCEDURE TO "USER";
    GRANT CREATE PUBLIC SYNONYM TO "USER";
    GRANT CREATE SEQUENCE TO "USER";
    GRANT CREATE SNAPSHOT TO "USER";
    GRANT CREATE SYNONYM TO "USER";
    GRANT CREATE TABLE TO "USER";
    GRANT CREATE TRIGGER TO "USER";
    GRANT CREATE VIEW TO "USER";
    GRANT "CONNECT" TO "USER";
    GRANT SELECT ANY DICTIONARY to "USER";
    GRANT CREATE TYPE TO "USER";
    

    create file import.bat and put this lines in it:

    SQLPLUS SYSTEM/systempassword@ORA_alias @"crate_drop_user.SQL"
    IMP SYSTEM/systempassword@ORA_alias FILE=user.DMP FROMUSER=user TOUSER=user GRANTS=Y log =user.log
    

    Be carefull if you will import from one user to another. For example if you have user named user1 and you will import to user2 you may lost all grants , so you have to recreate it.

    Good luck, Ivan

    0 讨论(0)
  • 2021-01-29 19:36

    If you are using impdp command example from @sathyajith-bhat response:

    impdp <username>/<password> directory=<directoryname> dumpfile=<filename>.dmp logfile=<filename>.log full=y;
    

    you will need to use mandatory parameter directory and create and grant it as:

    CREATE OR REPLACE DIRECTORY DMP_DIR AS 'c:\Users\USER\Downloads';
    GRANT READ, WRITE ON DIRECTORY DMP_DIR TO {USER};
    

    or use one of defined:

    select * from DBA_DIRECTORIES;
    

    My ORACLE Express 11g R2 has default named DATA_PUMP_DIR (located at {inst_dir}\app\oracle/admin/xe/dpdump/) you sill need to grant it for your user.

    0 讨论(0)
  • 2021-01-29 19:49

    How was the database exported?

    • If it was exported using exp and a full schema was exported, then

      1. Create the user:

        create user <username> identified by <password> default tablespace <tablespacename> quota unlimited on <tablespacename>;
        
      2. Grant the rights:

        grant connect, create session, imp_full_database to <username>;
        
      3. Start the import with imp:

        imp <username>/<password>@<hostname> file=<filename>.dmp log=<filename>.log full=y;
        
    • If it was exported using expdp, then start the import with impdp:

      impdp <username>/<password> directory=<directoryname> dumpfile=<filename>.dmp logfile=<filename>.log full=y;
      

    Looking at the error log, it seems you have not specified the directory, so Oracle tries to find the dmp file in the default directory (i.e., E:\app\Vensi\admin\oratest\dpdump\).

    Either move the export file to the above path or create a directory object to pointing to the path where the dmp file is present and pass the object name to the impdp command above.

    0 讨论(0)
提交回复
热议问题