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 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 10月 16 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 10月 15 14:18 hthse1015.zip
-rw-r--r--. 1 root root 1518010368 10月 22 12:23 hthse1022.dmp
-rw-r--r--. 1 root root 103699 10月 22 12:17 hthse1022.log
-rwxrwxr-x. 1 oracle oinstall 347346047 10月 23 15:14 hthse1022.zip
-rwxr-xr-x. 1 root root 750 9月 7 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 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 10月 16 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 10月 15 14:18 hthse1015.zip
-rwxrwxr-x. 1 oracle oinstall 1518010368 10月 22 12:23 hthse1022.dmp
-rwxrwxr-x. 1 oracle oinstall 103699 10月 22 12:17 hthse1022.log
-rwxrwxr-x. 1 oracle oinstall 347346047 10月 23 15:14 hthse1022.zip
-rwxr-xr-x. 1 root root 750 9月 7 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