oracle数据库导入导出 - teeth
用户没有对应权限。
sqlplus sys/密码 as sysdba
impdp system/testpassword directory=expdp_dir dumpfile=testdata30624.dmp logfile=testdata60624.log remap_schema=testdata3:testdata6 remap_tablespace=TESTOSOA_T_DATA:TESTOSOA6_DATA table_exists_action=replace
(system/ttestpassword 表示拥有导出导出权限的用户。导出的时候最好指定用户权限。)
impdp system/testpassword directory=expdp_dir dumpfile=testdata30624.dmp logfile=testdata60624.log remap_schema=testdata3:testdata6 remap_tablespace=TESTOSOA_T_DATA:TESTOSOA6_DATA table_exists_action=replace
expdp system/testpassword directory=expdp_dir dumpfile=testdata30624.dmp logfile=testdata30624.log schemas=testdata3;
从综合库导出数据
root操作
mkdir -p /srv/data/back
chmod -R 777 /srv/data/back
oracle到sqlplus执行
create directory back_dir2 as \’/srv/data/back\’;
grant read,write on directory back_dir2 to testweb;
oracle在终端执行
expdp testweb/testweb DIRECTORY=back_dir2 dumpfile=testweb2016.dmp
expdp testweb/testweb directory=back_dir2 dumpfile=testweb2016.dmp logfile=full20150821.log
导入初始化库
testweb2016.DMP拷贝到/srv/data/init
mkdir -p /srv/data/init
chmod -R 777 /srv/data/init
oracle到sqlplus执行
create directory init_dir as \’/srv/data/init\’;
grant read,write on directory init_dir to testweb;
oracle在终端执行
impdp testweb/testweb remap_tablespace=TEST_WEB_DATA:TEST_WEB_DATA remap_schema=testweb:testweb DIRECTORY=init_dir DUMPFILE=testweb2016.dmp logfile=inittg.log
expdp system/testpassword directory=expdp_dir dumpfile=testdata30624.dmp logfile=testdata30624.log schemas=testdata3;
(system/testpassword表示拥有导出导出权限的用户。导出的时候最好指定用户权限。)
expdp system/testpassword directory=expdp_dir dumpfile=testdata30624.dmp logfile=testdata30624.log schemas=testdata3;
Oracle数据导入导出imp/exp
exp testdata/testpassword@10.1.100.100/orcl file=G:/testdata20140808.dmp
exp testdata3/testpassword@10.1.100.100/orcl file=G:/testdata20160606.dmp
exp testweb/testpassword@10.1.100.100/orcl file=G:/testweb2016.dmp
部分表
exp testdata3/testpassword@10.1.100.100/orcl file=c:\TestCompany.dmp log=c:\TestCompany.log tables=(t_accepted_tpbank,t_econtract_content)
imp testdata43/testpassword@10.1.100.100/orcl file=c:\TestCompany20160606.dmp
imp testweb/testpassword@10.1.100.100/orcl file=G:/testweb2016.dmp
imp testweb/testpassword@10.1.100.100/orcl file=G:\20151104.dmp ignore=y full=y
imp testpassword/testpassword@10.1.100.100/orcl file=G:\xzzg20151222.dmp ignore=y full=y
imp testpassword/testpassword@192.168.0.145/orcl file=G:\TestCompany201511282222.dmp ignore=y full=y
exp userid=testweb/testpassword tables=(\’t_template\’) file = g:\TestCompany_template.dmp
imp system/testpassword@10.1.100.100/orcl file=G:/TestCompany201511282222.dmp log=TestCompany201511282222.log fromuser=htcms touser=htcms
exp testdata/testpassword@10.1.100.100/orcl file=G:/TestCompany20151222.dmp
su -oracle
exp testdata3/TestCompany2014.Kh file=data20140808.dmp
exp testdata3/TestCompany2014.Kh file=data20140808.dmp
12月5日
exp testdata3/TestCompany2014.Kh file=data20141205.dmp
exp testdata3/TestCompany2014.Kh file=cert20141205.dmp
12月6日
exp testdata3/TestCompany2014.Kh file=data20141206.dmp
exp testdata3/TestCompany2014.Kh file=cert20141206.dmp
imp testdata3/TestCompany2014.Kh file=osoa20141205.dmp ignore=y full=y DESTROY=Y
imp testdata3/testpassword file=G:\20151104.dmp ignore=y full=y
fromuser就是把当前的dmp文件中的某一个用户下的数据取出。
touser就是把现在dmp文件中的数据导入到目标库的指定user下。
具体命令这样。
exp userid=system/manager owner=username1 file=expfile.dmp
imp userid=system/manager fromuser=username1 touser=username2 ignore=y file=expfile.dmp full=y
功能:Oracle数据导入导出imp/exp就相当与oracle数据还原与备份。
大多情况都可以用Oracle数据导入导出完成数据的备份和还原(不会造成数据的丢失)。
Oracle有个好处,虽然你的电脑不是服务器,但是你装了oracle客户端,并建立了连接
(通过Net Configuration Assistant添加正确的服务命名,其实你可以想成是客户端与服务器端 修了条路,然后数据就可以被拉过来了)
这样你可以把数据导出到本地,虽然可能服务器离你很远。
你同样可以把dmp文件从本地导入到远处的数据库服务器中。
利用这个功能你可以构建俩个相同的数据库,一个用来测试,一个用来正式使用。
执行环境:可以在SQLPLUS.EXE或者DOS(命令行)中执行,
DOS中可以执行时由于 在oracle 8i 中 安装目录\$ora10g\BIN被设置为全局路径,
该目录下有EXP.EXE与IMP.EXE文件被用来执行导入导出。
oracle用java编写,我想SQLPLUS.EXE、EXP.EXE、IMP.EXE这俩个文件是被包装后的类文件。
SQLPLUS.EXE调用EXP.EXE、IMP.EXE他们所包裹的类,完成导入导出功能。
下面介绍的是导入导出的实例,向导入导出看实例基本上就可以完成,因为导入导出很简单。
数据导出:
1 将数据库TEST完全导出,用户名system 密码manager 导出到D:\daochu.dmp中
exp system/manager@TEST file=d:\daochu.dmp full=y
2 将数据库中system用户与sys用户的表导出
exp system/manager@TEST file=d:\daochu.dmp owner=(system,sys)
3 将数据库中的表table1 、table2导出
exp system/manager@TEST file=d:\daochu.dmp tables=(table1,table2)
4 将数据库中的表table1中的字段filed1以“00”打头的数据导出
exp system/manager@TEST file=d:\daochu.dmp tables=(table1) query=\” where filed1 like \’00%\’\”
上面是常用的导出,对于压缩我不太在意,用winzip把dmp文件可以很好的压缩。
不过在上面命令后面 加上 compress=y 就可以了
数据的导入
1 将D:\daochu.dmp 中的数据导入 TEST数据库中。
imp system/manager@TEST file=d:\daochu.dmp
上面可能有点问题,因为有的表已经存在,然后它就报错,对该表就不进行导入。
在后面加上 ignore=y 就可以了。
2 将d:\daochu.dmp中的表table1 导入
imp system/manager@TEST file=d:\daochu.dmp tables=(table1)
基本上上面的导入导出够用了。不少情况我是将表彻底删除,然后导入。
注意:
你要有足够的权限,权限不够它会提示你。
数据库时可以连上的。可以用tnsping TEST 来获得数据库TEST能否连上。
数据导出:
exp hkb/hkb@boss_14 full=y file=c:\orabackup\hkbfull.dmp log=c:\orabackup\hkbfull.log;
导出注意事项:导出的是当前用户的的数据,当前用户如果有DBA的权限,则导出所有数据!
同名用户之间的数据导入:
imp hkb/hkb@xe file=c:\orabackup\hkbfull.dmp log=c:\orabackup\hkbimp.log full=y
不同名之间的数据导入:
imp system/test@xe fromuser=hkb touser=hkb_new file=c:\orabackup\hkbfull.dmp
log=c:\orabackup\hkbimp.log;
imp system/11111 fromuser=osoa3data touser=
sqlplus 下host保持链接