数据库一般操作
数据库还原备份相关
create tablespace jsyzt datafile 'E:\app\Administrator\oradata\orcl\jsyzt.dbf' size 400M autoextend on next 10m maxsize unlimited; --1,创建表空间
create user jsyzt identified by jsyzt default tablespace jsyzt ; --2,创建用户
GRANT CREATE USER,DROP USER,ALTER USER,CREATE ANY VIEW,DROP ANY VIEW,EXP_FULL_DATABASE,IMP_FULL_DATABASE,DBA,CONNECT,RESOURCE,CREATE SESSION TO jsyzt; --3,用户授权
--创建泵目录:
create directory data_mypump_dir as 'C:\DATA';
--泵目录授权:
grant read, write on directory data_mypump_dir to yayzt;
数据导出dmp:
exp yayzt12172/yayzt12172@orcl file=c:/shuju/lyyzt(211)1015.dmp owner=(yayzt)
exp jsyzt/Jsgt_March@2015_11@orcl tables=(OA2_ROLESYS) file="d:/1.dmp" log="d:/1.log"
expdp nmyzt/nmyzt@orcl DIRECTORY=GG dumpfile=NMYZT1.dmp logfile=NMYZT.log
expdp jsyzt2/jsyzt2@orcl DIRECTORY=ORACLEDMP dumpfile=2.dmp logfile=2.log
数据库还原操作说明:
cmd窗口导入dmp数据
imp jsyzt/jsyzt@orcl file=C:\databackup\16-10-31政务平台数据库备份还原.dmp fromuser=jsyzt touser=jsyzt
dmp导入某张表
imp jsyzt/jsyzt@orcl tables = gw_swbwc file=C:\databackup\3.dmp fromuser=jsyzt touser=jsyzt
imp zzyzt/zzyzt@orcl full=y file=C:\长沙一张图\数据库备\zzjsyzt1119.dmp
imp LYYZT/LYYZT@orcl full=y file=d:\data\1.dmp log=d:\data\1.log fromuser=nmyzt touser=LYYZT
泵导入
impdp nmyzt/nmyzt@/orcl DIRECTORY=DX DUMPFILE=JXYXOA0828.DMP remap_schema=nmyzt:LYYZT remap_tablespace=nmyzt:LYYZT
impdp wcyzt/wcyzt@orcl directory=DATA_PUMP_DIR dumpfile=WCYZT20160616.dmp full=y
impdp csyzt/csyzt@orcl directory=dx schemas=csyzt logfile=csyzt_16_9_23.log dumpfile=csyzt_16_9_23.dmp
删除
drop user lyyzt cascade;--删除用户
DROP TABLESPACE lyyzt INCLUDING CONTENTS AND DATAFILES;--删除表空间
--注意:数据库中修改数据时要记得提交
/*一键清库*/
select '--清表'
from dual
union all
select 'drop table ' || a.TABLE_NAME || '' || ';'
from user_tables a
union all
select '--清序列'
from dual --清序列
union all
select 'drop sequence ' || a.sequence_name || '' || ';'
from user_sequences a --清存储过程
union all
select '--清存储过程'
from dual
union all
select 'drop procedure ' || a.object_name || '' || ';'
from user_procedures a
where a.object_type = 'PROCEDURE' --清包
union all
select '--清包'
from dual
union all
select distinct 'drop PACKAGE ' || a.object_name || '' || ';'
from user_procedures a
where a.object_type = 'PACKAGE'
union all
select '--清自定义函数'
from dual
union all
select 'drop FUNCTION ' || a.object_name || '' || ';'
from user_procedures a
where a.object_type = 'FUNCTION';
--查看泵目录:
select * from dba_directories;
1、备份前检查是否有空表
SQL>select table_name from user_tables where NUM_ROWS=0;
根据上述查询,可以构建针对空表分配空间的命令语句,如下:
SQL>Select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0 or num_rows is null
将查询出的所有sql语句执行
2、导入时设置deferred_segment_creation 参数:
在sqlplus中,执行如下命令:
SQL>alter system set deferred_segment_creation=false;
查看:
SQL>show parameter deferred_segment_creation;
注意:该值设置后只对后面新增的表产生作用,对之前建立的空表(已经存在的)不起作用,仍不能导出。
并且要重新启动数据库,让参数生效。