远程导出数据库
环境背景:
本地 :IP:127.0.0.1 端口:1521 实例:orcl 用户:local_sys/123
远程服务器:IP:192.168.0.100 端口:1521 实例:orcl 用户:server_sys/123
目标:将服务器上 server_user1 用户导出到本地
1. 登录本地数据库
[sql] view plain copy
C:\Users\admin>sqlplus / as sysdba
2. 创建 dblink
语句:
[sql] view plain copy
create database link DBLINK_NAME connect to system identified by orcl using ‘TNS_NAME’;
示例:
[sql] view plain copy
create database link local_to_server connect to system identified by orcl using ‘TO_SERVER’;
说明:DBLINK_NAME 是自己为 dblink 命名,TNS_NAME 是已配置的 TNS 名,此处示例的 TNS 配置为:
create public database link hbcq
connect to UNIMAX_HBCQ identified by UNIMAX_HBCQ
using ‘10.1.1.157/orcl’;
[sql] view plain copy
TO_SERVER=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.100)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
创建完成后执行语句:
[sql] view plain copy
select * from dual@local_to_server;
结果:x
表示创建成功,如果遇到问题,请参考:http://blog.csdn.net/davidhsing/article/details/6408770
3. 创建数据库目录
语句:
[sql] view plain copy
create directory MY_DIR as ‘d:\dump’;
授权:
[sql] view plain copy
grant write,read on directory MY_DIR to local_sys;
创建完成后执行语句:
[sql] view plain copy
select * from dba_directories;
查看创建结果
4. 导出
语句:
[sql] view plain copy
expdp local_sys/123@127.0.0.1:1521/orcl network_link=local_to_server directory=MY_DIR dumpfile=result.dmp logfile=result.log SCHEMAS=server_user1
注意,此语句在 dos 窗口直接执行,执行完成后检查 d:\dump 有没有 result.dmp 和 result.log 文件,result.dmp 为目标文件,result.log 为日志文件
参考文章: