1. 程式人生 > >12c容器資料庫匯入操作_筆記(Linux/oracle借用shell工具匯入資料檔案操作)

12c容器資料庫匯入操作_筆記(Linux/oracle借用shell工具匯入資料檔案操作)

Linux/oracle借用shell工具匯入資料檔案操作

一、使用shell工具,遠端連線到Linux下的oracle資料庫服務上

Xshell 6 (Build 0095)

Copyright (c) 2002 NetSarang Computer, Inc. All rights reserved.

Type `help' to learn how to use Xshell prompt.

[C:\~]$

Connecting to 192.168.1.90:22...

Connection established.

To escape to local shell, press 'Ctrl+Alt+]'.

Last login: Wed Oct 10 08:57:38 2018 from 192.168.1.12

[[email protected] ~]# su - oracle

[[email protected] ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 12.2.0.1.0 Production on Wed Oct 10 17:05:29 2018

 

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

 

SQL>

檢視容器

SQL> show pdbs

 

    CON_ID CON_NAME   OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

 2 PDB$SEED   READ ONLY  NO

 3 CDB   READ WRITE NO

 4 AJHDB   READ WRITE NO

SQL> --啟動(開啟)資料庫的容器

SQL>alter pluggable database ajhdb open ;

alter pluggable database ajhdb open

*

ERROR at line 1:

ORA-65019: pluggable database AJHDB already open

 

 

SQL>  --啟動資料庫                                   

SQL> startup

ORA-01081: cannot start already-running ORACLE - shut it down first

SQL>--切換到指定的容器下

SQL> alter session set container=ajhdb;

 

Session altered.

 

SQL> alter pluggable database ajhdb open ;   ---》再次開啟容器

alter pluggable database ajhdb open

*

ERROR at line 1:

ORA-65019: pluggable database AJHDB already open

SQL> drop user hthse cascade; ---》刪除使用者 hthse

Connection closed.

SQL> --檢視 。。。名稱

SQL> show con_name; 

 

CON_NAME

------------------------------

AJHDB

切換到指定的(ajhdb)容器下

SQL> alter session set container=ajhdb;

 

Session altered.

 

SQL> --建立使用者(hthse1009 並賦予密碼

SQL> create user hthse1009 identified by hthse;

 

User created.

給剛建立的使用者賦許可權(dba, 資料庫連線、資料庫資源

SQL> grant dba,connect,resource to hthse1009 ;

 

Grant succeeded.

 

SQL> --給剛建立的使用者指定資料預設空間

SQL> alter user hthse1009 default tablespace data;

 

User altered.

退出

SQL> Quit

Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

[[email protected] ~]$ lsnrctl start

 

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 10-OCT-2018 17:35:25

 

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

 

TNS-01106: Listener using listener name LISTENER has already been started

[[email protected] ~]$

 

 

二、準備資料庫檔案的上傳、賦許可權、解壓

SQL> Quit   ---- 退出

Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

[[email protected] ~]$ lsnrctl start   ---- 啟動監聽

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 10-OCT-2018 17:35:25

 

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

 

TNS-01106: Listener using listener name LISTENER has already been started

[[email protected] ~]$

[[email protected] ~]$ lsnrctl status      ---- 檢視監聽狀態

 

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 10-OCT-2018 17:35:45

 

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle12c)(PORT=1521)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production

Start Date                10-OCT-2018 08:57:59

Uptime                    0 days 8 hr. 37 min. 47 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /home/u01/app/oracle/product/12.2.0/db_1/network/admin/listener.ora

Listener Log File         /home/u01/app/oracle/diag/tnslsnr/oracle12c/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle12c)(PORT=1521)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Services Summary...

Service "73fd43c6319f2e8ee0535a01a8c09536" has 1 instance(s).

  Instance "orcl", status READY, has 1 handler(s) for this service...

Service "73fe79106d53333ae0535a01a8c0477f" has 1 instance(s).

  Instance "orcl", status READY, has 1 handler(s) for this service...

Service "ajhdb" has 1 instance(s).

  Instance "orcl", status READY, has 1 handler(s) for this service...

Service "cdb" has 1 instance(s).

  Instance "orcl", status READY, has 1 handler(s) for this service...

Service "orcl" has 1 instance(s).

  Instance "orcl", status READY, has 1 handler(s) for this service...

Service "orclXDB" has 1 instance(s).

  Instance "orcl", status READY, has 1 handler(s) for this service...

The command completed successfully

[[email protected] ~]$

[[email protected] ~]$ sqlplus / as sysdba   ---- 連線到超級資料庫管理員使用者下

 

SQL*Plus: Release 12.2.0.1.0 Production on Wed Oct 10 17:35:59 2018

 

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

 

SQL>

 

 

三、可以重新開啟一個shell視窗;將資料庫檔案資料從Windows複製到Linux環境幾下,並解壓(備註:URL不能用中文。)如圖:(將。。。.zip 移動到Linux下,執行加壓命令。

備註:檔案上傳到 .../home/oradata/dir

 

 

Xshell 6 (Build 0095)

Copyright (c) 2002 NetSarang Computer, Inc. All rights reserved.

 

Type `help' to learn how to use Xshell prompt.

[C:\~]$

 

Connecting to 192.168.1.90:22...

Connection established.

To escape to local shell, press Ctrl+Alt+].

 

Last login: Wed Oct 10 17:18:29 2018 from 192.168.1.36

[[email protected] ~]# su - oracle    ---- 切換到Oracle

[[email protected] ~]$ sqlplus / as sysdba  ---- 連線到超級資料庫管理員使用者下

 

 

 

SQL*Plus: Release 12.2.0.1.0 Production on Wed Oct 10 17:38:18 2018

 

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

 

SQL>

SQL> alter session set container=ajhdb;   ----切換到指定的(ajhdb)容器下

 

Session altered.

 

SQL>

顯示12c多組戶架構中當前Container的名稱,如果是非多組戶架構資料庫,返回:“Non Consolidated”

SQL> show con_name;   ----檢視12c的多組戶架構Con的名稱

 

CON_NAME

------------------------------

AJHDB

SQL> --建立 或替換目錄(dir)

SQL> create or replace directory dir as '/oradata/dir';

 

Directory created.

 

給指定目錄dir到使用者讀、寫賦許可權

SQL> grant read ,write on directory dir to hthse1009; 

 

Grant succeeded.

 

SQL>  

SQL> exit

Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

[[email protected] ~]$ su - root

密碼:000000

[[email protected] ~]# cd /   ----進入所有的上一級目錄

[[email protected] /]# ll   ----檢視目錄中的內容詳情

總用量 98

dr-xr-xr-x.   2 root root  4096 8月  23 09:14 bin

dr-xr-xr-x.   5 root root  1024 8月  22 07:46 boot

drwxr-xr-x.  20 root root  3780 10月 10 08:45 dev

drwxr-xr-x. 119 root root 12288 10月 10 08:45 etc

drwxr-xr-x.   7 root root  4096 8月  22 09:26 home

dr-xr-xr-x.  13 root root  4096 8月  23 09:14 lib

dr-xr-xr-x.   9 root root 12288 8月  23 09:14 lib64

drwx------.   2 root root 16384 8月  22 07:29 lost+found

drwxr-xr-x.   2 root root  4096 9月  23 2011 media

drwxr-xr-x.   2 root root     0 10月 10 08:45 misc

drwxr-xr-x.   2 root root  4096 9月  23 2011 mnt

drwxr-xr-x.   2 root root     0 10月 10 08:45 net

drwxr-xr-x.   4 root root  4096 8月  22 09:10 opt

dr-xr-xr-x. 510 root root     0 10月 10 08:44 proc

dr-xr-x---.  27 root root  4096 10月 10 17:37 root

dr-xr-xr-x.   2 root root 12288 8月  23 09:14 sbin

drwxr-xr-x.   7 root root     0 10月 10 08:44 selinux

drwxr-xr-x.   2 root root  4096 9月  23 2011 srv

drwxr-xr-x   13 root root     0 10月 10 08:44 sys

drwxrwxrwt.   9 root root  4096 10月 10 09:20 tmp

drwxr-xr-x.  13 root root  4096 8月  22 07:32 usr

drwxr-xr-x.  22 root root  4096 8月  22 07:40 var

[[email protected] /]# cd /home/   ----進入到home目錄下

[[email protected] home]# ls   ----檢視

lost+found  oracle  oradata  software  u01

[[email protected] home]# cd .oracle

-bash: cd: .oracle: 沒有那個檔案或目錄

[[email protected] home]# cd /oracle

-bash: cd: /oracle: 沒有那個檔案或目錄

[[email protected] home]# cd oracle   ----進入Oracle目錄下

[[email protected] oracle]# ls   ----檢視檔案

dir  公共的  模板  視訊  圖片  文件  下載  音樂  桌面

[[email protected] oracle]# ll   ----檢視所有檔案

總用量 36

drwxr-xr-x. 2 oracle oinstall 4096 9月  28 12:16 dir

drwxr-xr-x. 2 oracle oinstall 4096 8月  22 08:55 公共的

drwxr-xr-x. 2 oracle oinstall 4096 8月  22 08:55 模板

drwxr-xr-x. 2 oracle oinstall 4096 8月  22 08:55 視訊

drwxr-xr-x. 2 oracle oinstall 4096 8月  22 08:55 圖片

drwxr-xr-x. 2 oracle oinstall 4096 8月  22 08:55 文件

drwxr-xr-x. 2 oracle oinstall 4096 8月  22 08:55 下載

drwxr-xr-x. 2 oracle oinstall 4096 8月  22 08:55 音樂

drwxr-xr-x. 2 oracle oinstall 4096 8月  22 08:55 桌面

[[email protected] oracle]# cd dir   ----進入dir目錄下

[[email protected] dir]# ls

[[email protected] dir]# cd /

[[email protected] /]# ls

bin   dev  home  lib64       media  mnt  opt   root  selinux  sys  usr

boot  etc  lib   lost+found  misc   net  proc  sbin  srv      tmp  var

[[email protected] /]# cd /home/oradata/dir   ----進入dir目錄下

[[email protected] dir]# ls

123.dmp       2018.9.10.zip    hthse0806.log      hthse0826_sys.sql  hthse0912.log      hthse1009.zip

123.log       Desktop0927      hthse0806_sys.sql  hthse0910.dmp      hthse0912_sys.sql  orabak.sh

20180910.zip  Desktop0927.zip  hthse0806.zip      hthse0910.log      hthse0927.dmp

20180912.zip  Desktop.rar      hthse0826.dmp      hthse0910_sys.sql  hthse0927.log

2018.9.10     hthse0806.dmp    hthse0826.log      hthse0912.dmp      hthse0927_sys.sql

 

[[email protected] dir]#  su - oracle  ----切換到Oracle使用者下

[[email protected] ~]$ ----設定匯入資料的位元組編碼方式

[[email protected] ~]$ export NLS_LANG=american_america.ZHS16GBK 

[[email protected] ~]$ ---資料棒方式匯入,暫時不用

[[email protected] ~]$ impdp hthse1009/[email protected]:1521/ajhdb directory=dir dumpfile=20180321AJH.DMP logfile=impdp1.log schemas=hthse1009

 

Import: Release 12.2.0.1.0 - Production on Wed Oct 10 18:06:33 2018

 

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

 

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

ORA-39002: invalid operation

ORA-39070: Unable to open the log file.

ORA-29283: invalid file operation

ORA-29283: invalid file operation

 

 

[[email protected] ~]$

 

四、檔案解壓 、匯入(普通匯入

[email protected] ~]$

SQL> exit

Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

[[email protected] ~]$ lsnrctl status

 

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 23-OCT-2018 15:52:41

 

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle12c)(PORT=1521)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production

Start Date                23-OCT-2018 10:36:29

Uptime                    0 days 5 hr. 16 min. 15 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /home/u01/app/oracle/product/12.2.0/db_1/network/admin/listener.ora

Listener Log File         /home/u01/app/oracle/diag/tnslsnr/oracle12c/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle12c)(PORT=1521)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Services Summary...

Service "73fd43c6319f2e8ee0535a01a8c09536" has 1 instance(s).

  Instance "orcl", status READY, has 1 handler(s) for this service...

Service "73fe79106d53333ae0535a01a8c0477f" has 1 instance(s).

  Instance "orcl", status READY, has 1 handler(s) for this service...

Service "ajhdb" has 1 instance(s).

  Instance "orcl", status READY, has 1 handler(s) for this service...

Service "cdb" has 1 instance(s).

  Instance "orcl", status READY, has 1 handler(s) for this service...

Service "orcl" has 1 instance(s).

  Instance "orcl", status READY, has 1 handler(s) for this service...

Service "orclXDB" has 1 instance(s).

  Instance "orcl", status READY, has 1 handler(s) for this service...

The command completed successfully

[[email protected] ~]$ cd / oradata/    ---進入到 oradata 目錄下

[[email protected] /]$ ls

bin   dev  home  lib64       media  mnt  opt   root  selinux  sys  usr

boot  etc  lib   lost+found  misc   net  proc  sbin  srv      tmp  var

[[email protected] /]$ su - root

密碼:000000

[[email protected] ~]#  cd /home   ---進入到 home 目錄下

[[email protected] home]# ls

lost+found  oracle  oradata  software  u01

[[email protected] home]# cd oradata    ---進入到 oradata 目錄下

[[email protected] oradata]# ls

data01.dbf  data02.dbf  data20181017.dbf  dir

[[email protected] oradata]# cd dir    ---進入到 dir 目錄下

[[email protected] dir]# ls

123.dmp       2018.9.10      Desktop.rar    hthse0806_sys.sql  hthse1022.dmp      hthse1022.zip

123.log       2018.9.10.zip  hthse0806.dmp  hthse0806.zip      hthse1022.log      orabak.sh

20181016.zip  Desktop0927    hthse0806.log  hthse1015.zip      hthse1022_sys.sql

[[email protected] dir]# rm hthse1022.dmp    ---刪除多餘或不用的資料檔案

rm:是否刪除普通檔案 "hthse1022.dmp"y

[[email protected] dir]# rm hthse1022.log   ---刪除多餘或不用的日誌檔案

rm:是否刪除普通檔案 "hthse1022.log"y

[[email protected] dir]# rm hthse1022_sys.sql   ---刪除多餘或不用的sql檔案

rm:是否刪除普通空檔案 "hthse1022_sys.sql"y

 

[[email protected] dir]# ls

123.dmp  20181016.zip  2018.9.10.zip  Desktop.rar    hthse0806.log      hthse0806.zip  hthse1022.zip

123.log  2018.9.10     Desktop0927    hthse0806.dmp  hthse0806_sys.sql  hthse1015.zip  orabak.sh

[[email protected] dir]# chown oracle:oinstall hthse1022.zip   ---給oracle使用者下的 *.zip壓縮包授予 oinstall 許可權

[[email protected] dir]# chmod 775  hthse1022.zip   ---給oracle使用者下的 *.zip壓縮包授予 775 許可權(即:775 讀、寫、可執行)

(備註:在linux終端先輸入ll,可以看到如:
  -rwx-r--r-- (一共10個引數) 表示檔案所屬組和使用者的對應許可權。
  第一個跟引數屬於管理員,跟chmod無關,先不管.
  2-4引數:屬於user
  5-7引數:屬於group
  8-10引數:屬於others
  接下來就簡單了:r==>可讀 w==>可寫 x==>可執行
  r=4      w=2      x=1
  所以755代表 rwxr-xr-x
  777 代表 rwxr-rwx-rwx 所有使用者都可讀可寫可執行。)

[[email protected] dir]# unzip  hthse1022.zip  ---執行解壓命令: 將 *.zip 檔案 壓縮

Archive:  hthse1022.zip

  inflating: hthse1022.dmp           

  inflating: hthse1022.log           

[[email protected] dir]# ll   ---檢視詳細內容

總用量 6014056

-rw-r--r--. 1 root   root     1485414400 9月   7 18:45 123.dmp

-rw-r--r--. 1 root   root         103628 9月   7 18:45 123.log

-rwxrwxr-x. 1 oracle oinstall  346044546 1016 10:54 20181016.zip

drwxr-xr-x. 2 root   root           4096 9月  10 17:14 2018.9.10

-rw-r--r--. 1 root   root       10828928 9月  10 17:03 2018.9.10.zip

drwxr-xr-x. 2 root   root           4096 9月  28 14:25 Desktop0927

-rw-r--r--. 1 root   root      286156188 8月  26 18:31 Desktop.rar

-rwxrwxr-x. 1 oracle oinstall 1483939840 8月   6 19:21 hthse0806.dmp

-rwxrwxr-x. 1 oracle oinstall     105366 8月  22 12:14 hthse0806.log

-rw-r--r--. 1 oracle oinstall          0 8月  22 11:25 hthse0806_sys.sql

-rwxrwxr-x. 1 oracle oinstall  334248322 8月  22 11:20 hthse0806.zip

-rwxrwxr-x. 1 oracle oinstall  346044546 1015 14:18 hthse1015.zip

-rw-r--r--. 1 root   root     1518010368 1022 12:23 hthse1022.dmp

-rw-r--r--. 1 root   root         103699 1022 12:17 hthse1022.log

-rwxrwxr-x. 1 oracle oinstall  347346047 1023 15:14 hthse1022.zip

-rwxr-xr-x. 1 root   root            750 9月   7 18:43 orabak.sh

[[email protected] dir]# chown oracle:oinstall hthse1022* --- ---給oracle使用者下的 *.zip 授權

[[email protected] dir]# chmod 775 hthse1022* --- ---給oracle使用者下的 *.zip壓縮包授予 775 許可權(即:775 讀、寫、可執行)

[[email protected] dir]# ll ---檢視詳細內容

總用量 6014056

-rw-r--r--. 1 root   root     1485414400 9月   7 18:45 123.dmp

-rw-r--r--. 1 root   root         103628 9月   7 18:45 123.log

-rwxrwxr-x. 1 oracle oinstall  346044546 1016 10:54 20181016.zip

drwxr-xr-x. 2 root   root           4096 9月  10 17:14 2018.9.10

-rw-r--r--. 1 root   root       10828928 9月  10 17:03 2018.9.10.zip

drwxr-xr-x. 2 root   root           4096 9月  28 14:25 Desktop0927

-rw-r--r--. 1 root   root      286156188 8月  26 18:31 Desktop.rar

-rwxrwxr-x. 1 oracle oinstall 1483939840 8月   6 19:21 hthse0806.dmp

-rwxrwxr-x. 1 oracle oinstall     105366 8月  22 12:14 hthse0806.log

-rw-r--r--. 1 oracle oinstall          0 8月  22 11:25 hthse0806_sys.sql

-rwxrwxr-x. 1 oracle oinstall  334248322 8月  22 11:20 hthse0806.zip

-rwxrwxr-x. 1 oracle oinstall  346044546 1015 14:18 hthse1015.zip

-rwxrwxr-x. 1 oracle oinstall 1518010368 1022 12:23 hthse1022.dmp

-rwxrwxr-x. 1 oracle oinstall     103699 1022 12:17 hthse1022.log

-rwxrwxr-x. 1 oracle oinstall  347346047 1023 15:14 hthse1022.zip

-rwxr-xr-x. 1 root   root            750 9月   7 18:43 orabak.sh

[[email protected] dir]# su - oracle ---切換到oracle使用者下

[[email protected] ~]$ export NLS_LANG=american_america.ZHS16GBK ---設定下dump的源資料庫字符集ZHS16GBK

 

 

[[email protected] ~]$ imp hthse1023/[email protected]:1521/ajhdb file=/home/oradata/dir/hthse1022.dmp fromuser=hthse  touser=hthse1023  log=/home/oradata/dir/hthse1022.log ---執行普通匯入命令

 

 

Import: Release 12.2.0.1.0 - Production on Tue Oct 23 15:57:20 2018

 

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

 

 

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

 

Export file created by EXPORT:V12.02.00 via conventional path

 

Warning: the objects were exported by HTHSE, not by you

 

import done in ZHS16GBK character set and AL16UTF16 NCHAR character set

export server uses UTF8 NCHAR character set (possible ncharset conversion)

IMP-00403:

 

Warning: This import generated a separate SQL file "/home/oradata/dir/hthse1022_sys.sql" which contains DDL that failed due to a privilege issue.

 

IMP-00017: following statement failed with ORACLE error 2304:

 "CREATE TYPE "WM_CONCAT_IMPL" TIMESTAMP '2018-09-11:23:03:01' OID '759AC527E"

 "9DEBF0BE053716B0B0A5071'   AS OBJECT"

 "-- AUTHID CURRENT_USER AS OBJECT"

 "("

 "CURR_STR VARCHAR2(32767),"

 "STATIC FUNCTION ODCIAGGREGATEINITIALIZE(SCTX IN OUT WM_CONCAT_IMPL) RETURN "

 "NUMBER,"

 "MEMBER FUNCTION ODCIAGGREGATEITERATE(SELF IN OUT WM_CONCAT_IMPL,"

 "P1 IN VARCHAR2) RETURN NUMBER,"

 "MEMBER FUNCTION ODCIAGGREGATETERMINATE(SELF IN WM_CONCAT_IMPL,"

 "RETURNVALUE OUT VARCHAR2,"

 "FLAGS IN NUMBER)"

 "RETURN NUMBER,"

 "MEMBER FUNCTION ODCIAGGREGATEMERGE(SELF IN OUT WM_CONCAT_IMPL,"

 "SCTX2 IN WM_CONCAT_IMPL) RETURN NUMBER"

 ")"

IMP-00003: ORACLE error 2304 encountered

ORA-02304: invalid object identifier literal