1. 程式人生 > >12c容器數據庫導入操作_筆記(Linux/oracle借用shell工具導入數據文件操作)

12c容器數據庫導入操作_筆記(Linux/oracle借用shell工具導入數據文件操作)

ftw alt dir acl soft lte counter rst point

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

[root@oracle12c ~]# su - oracle

[oracle@oracle12c ~]$ 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

[oracle@oracle12c ~]$ 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

[oracle@oracle12c ~]$

二、準備數據庫文件的上傳、賦權限、解壓

SQL> Quit ---- 退出

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

[oracle@oracle12c ~]$ 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

[oracle@oracle12c ~]$

[oracle@oracle12c ~]$ 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

[oracle@oracle12c ~]$

[oracle@oracle12c ~]$ 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

[root@oracle12c ~]# su - oracle ---- 切換到Oracle

[oracle@oracle12c ~]$ 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

[oracle@oracle12c ~]$ su - root

密碼:000000

[root@oracle12c ~]# cd / ----進入所有的上一級目錄

[root@oracle12c /]# 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

[root@oracle12c /]# cd /home/ ----進入到home目錄下

[root@oracle12c home]# ls ----查看

lost+found oracle oradata software u01

[root@oracle12c home]# cd .oracle

-bash: cd: .oracle: 沒有那個文件或目錄

[root@oracle12c home]# cd /oracle

-bash: cd: /oracle: 沒有那個文件或目錄

[root@oracle12c home]# cd oracle ----進入Oracle目錄下

[root@oracle12c oracle]# ls ----查看文件

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

[root@oracle12c 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 桌面

[root@oracle12c oracle]# cd dir ----進入dir目錄下

[root@oracle12c dir]# ls

[root@oracle12c dir]# cd /

[root@oracle12c /]# ls

bin dev home lib64 media mnt opt root selinux sys usr

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

[root@oracle12c /]# cd /home/oradata/dir ----進入dir目錄下

[root@oracle12c 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

[root@oracle12c dir]# su - oracle ----切換到Oracle用戶下

[oracle@oracle12c ~]$ ----設置導入數據的字節編碼方式

[oracle@oracle12c ~]$ export NLS_LANG=american_america.ZHS16GBK

[oracle@oracle12c ~]$ ---數據棒方式導入,暫時不用

[oracle@oracle12c ~]$ 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

[oracle@oracle12c ~]$

四、文件解壓 、導入(普通導入

oracle@oracle12c ~]$

SQL> exit

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

[oracle@oracle12c ~]$ 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

[oracle@oracle12c ~]$ cd / oradata/ ---進入到 oradata 目錄下

[oracle@oracle12c /]$ ls

bin dev home lib64 media mnt opt root selinux sys usr

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

[oracle@oracle12c /]$ su - root

密碼:000000

[root@oracle12c ~]# cd /home ---進入到 home 目錄下

[root@oracle12c home]# ls

lost+found oracle oradata software u01

[root@oracle12c home]# cd oradata ---進入到 oradata 目錄下

[root@oracle12c oradata]# ls

data01.dbf data02.dbf data20181017.dbf dir

[root@oracle12c oradata]# cd dir ---進入到 dir 目錄下

[root@oracle12c 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

[root@oracle12c dir]# rm hthse1022.dmp ---刪除多余或不用的數據文件

rm:是否刪除普通文件 "hthse1022.dmp"y

[root@oracle12c dir]# rm hthse1022.log ---刪除多余或不用的日誌文件

rm:是否刪除普通文件 "hthse1022.log"y

[root@oracle12c dir]# rm hthse1022_sys.sql ---刪除多余或不用的sql文件

rm:是否刪除普通空文件 "hthse1022_sys.sql"y

[root@oracle12c 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

[root@oracle12c dir]# chown oracle:oinstall hthse1022.zip ---給oracle用戶下的 *.zip壓縮包授予 oinstall 權限

[root@oracle12c 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 所有用戶都可讀可寫可執行。)

[root@oracle12c dir]# unzip hthse1022.zip ---執行解壓命令: 將 *.zip 文件 壓縮

Archive: hthse1022.zip

inflating: hthse1022.dmp

inflating: hthse1022.log

[root@oracle12c dir]# ll ---查看詳細內容

總用量 6014056

-rw-r--r--. 1 root root 1485414400 97 18:45 123.dmp

-rw-r--r--. 1 root root 103628 97 18:45 123.log

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

drwxr-xr-x. 2 root root 4096 910 17:14 2018.9.10

-rw-r--r--. 1 root root 10828928 910 17:03 2018.9.10.zip

drwxr-xr-x. 2 root root 4096 928 14:25 Desktop0927

-rw-r--r--. 1 root root 286156188 826 18:31 Desktop.rar

-rwxrwxr-x. 1 oracle oinstall 1483939840 86 19:21 hthse0806.dmp

-rwxrwxr-x. 1 oracle oinstall 105366 822 12:14 hthse0806.log

-rw-r--r--. 1 oracle oinstall 0 822 11:25 hthse0806_sys.sql

-rwxrwxr-x. 1 oracle oinstall 334248322 822 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 97 18:43 orabak.sh

[root@oracle12c dir]# chown oracle:oinstall hthse1022* --- ---給oracle用戶下的 *.zip 授權

[root@oracle12c dir]# chmod 775 hthse1022* --- ---給oracle用戶下的 *.zip壓縮包授予 775 權限(即:775 讀、寫、可執行)

[root@oracle12c dir]# ll ---查看詳細內容

總用量 6014056

-rw-r--r--. 1 root root 1485414400 97 18:45 123.dmp

-rw-r--r--. 1 root root 103628 97 18:45 123.log

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

drwxr-xr-x. 2 root root 4096 910 17:14 2018.9.10

-rw-r--r--. 1 root root 10828928 910 17:03 2018.9.10.zip

drwxr-xr-x. 2 root root 4096 928 14:25 Desktop0927

-rw-r--r--. 1 root root 286156188 826 18:31 Desktop.rar

-rwxrwxr-x. 1 oracle oinstall 1483939840 86 19:21 hthse0806.dmp

-rwxrwxr-x. 1 oracle oinstall 105366 822 12:14 hthse0806.log

-rw-r--r--. 1 oracle oinstall 0 822 11:25 hthse0806_sys.sql

-rwxrwxr-x. 1 oracle oinstall 334248322 822 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 97 18:43 orabak.sh

[root@oracle12c dir]# su - oracle ---切換到oracle用戶下

[oracle@oracle12c ~]$ export NLS_LANG=american_america.ZHS16GBK ---設置下dump的源數據庫字符集ZHS16GBK

[oracle@oracle12c ~]$ 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

12c容器數據庫導入操作_筆記(Linux/oracle借用shell工具導入數據文件操作)