文章分类:数据库
详细步骤:
1.命令行输入 dbca,通过图形创建数据库实例(实例名:mib0725,SID:mib0725; system用户密码是mib0725);
2.导入数据库环境变量 import ORACLE_SID=mib0725;
3.命令行输入 sqlplus / as sysdba;
4.SQL命令行输入 create tablespace mib0725 logging datafile 'E:\oracle\product\10.2.0\oradata\orcl/mib0725.dbf' size 200M autoextend on;
5.SQL命令行输入 create user mib0725 identified by mib0725 default tablespace mib0725;
6.SQL命令行输入 grant connect,resource,dba to mib0725;
7.SQL命令行输入 quit;
8.在命令行输入 sqlplus mib0725/mib0725@mib0725
如在第8步能连接上,表示成功,否则失败。
导出: exp username/pwd@orcl2 file=e:\daochu.dmp
导入: imp gzqo/gzqo@orcl2 full=y file=H:\xiaoli\gzqo_0217.dmp
强制关闭
shutdown abort;
startup;
1、查询剩余表空间
select sum(bytes)/(1024*1024*1024) free_space,tablespace_name
from dba_free_space
group by tablespace_name;
2、统计表空间多大
select t.tablespace_name, round(sum(bytes/(1024*1024*1024)),0) ts_size
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
group by t.tablespace_name;
第一步:创建表空间CREATE TABLESPACE tbs_metadata DATAFILE 'D:\oracle\product\10.2.0\oradata\orcl\TBS_META.dbf' SIZE 1000M autoextend on
next 200m maxsize unlimited EXTENT management local;
第二步:创建用户create user psnc_bj identified by psnc_bj default tablespace tbs_metadata;
第三步:授权grant connect,resource to psnc_ln;赋权
第四部:导入命令
C:\Users\Administrator>imp psnc_bj/psnc_bj file=E:\mong_psnc_bj_bak_20110905.dmp buffer=65536 feedback=100000 【fromuser=psnc_bj touser=psnc_bj statistics=none】适时的改为full=y;
表空间扩充方法 http://www.2cto.com/database/201110/109669.html
Oracle PL/SQL 编程手册(SQL大全) PLSQL操作手册
http://www.open-open.com/home/space-20397-do-blog-id-4229.html
SYS用户在CMD下以DBA身份登陆:
在CMD中打sqlplus /nolog
然后再
conn / as sysdba
//创建临时表空间
create temporary tablespace user_temp
tempfile 'D:\oracle\oradata\Oracle9i\user_temp.dbf'
size 50m
autoextend on
next 50m maxsize 20480m
extent management local;
//创建数据表空间
create tablespace test_data
logging
datafile 'D:\oracle\oradata\Oracle9i\user_data.dbf'
size 50m
autoextend on
next 50m maxsize 20480m
extent management local;
//创建用户并指定表空间
create user username identified by password
default tablespace user_data
temporary tablespace user_temp;
//给用户授予权限
grant connect,resource to username;
//以后以该用户登录,创建的任何数据库对象都属于user_temp 和user_data表空间,
这就不用在每创建一个对象给其指定表空间了
撤权:
revoke 权限... from 用户名;
删除用户命令
drop user user_name cascade;
建立表空间
CREATE TABLESPACE data01
DATAFILE '/oracle/oradata/db/DATA01.dbf' SIZE 500M
UNIFORM SIZE 128k; #指定区尺寸为128k,如不指定,区尺寸默认为64k
删除表空间
DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;
一、建立表空间
CREATE TABLESPACE data01
DATAFILE '/oracle/oradata/db/DATA01.dbf' SIZE 500M
UNIFORM SIZE 128k; #指定区尺寸为128k,如不指定,区尺寸默认为64k
二、建立UNDO表空间
CREATE UNDO TABLESPACE UNDOTBS02
DATAFILE '/oracle/oradata/db/UNDOTBS02.dbf' SIZE 50M
#注意:在OPEN状态下某些时刻只能用一个UNDO表空间,如果要用新建的表空间,必须切换到该表空间:
ALTER SYSTEM SET undo_tablespace=UNDOTBS02;
三、建立临时表空间
CREATE TEMPORARY TABLESPACE temp_data
TEMPFILE '/oracle/oradata/db/TEMP_DATA.dbf' SIZE 50M
四、改变表空间状态
1.使表空间脱机
ALTER TABLESPACE game OFFLINE;
如果是意外删除了数据文件,则必须带有RECOVER选项
ALTER TABLESPACE game OFFLINE FOR RECOVER;
2.使表空间联机
ALTER TABLESPACE game ONLINE;
3.使数据文件脱机
ALTER DATABASE DATAFILE 3 OFFLINE;
4.使数据文件联机
ALTER DATABASE DATAFILE 3 ONLINE;
5.使表空间只读
ALTER TABLESPACE game READ ONLY;
6.使表空间可读写
ALTER TABLESPACE game READ WRITE;
五、删除表空间
DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;
六、扩展表空间
首先查看表空间的名字和所属文件
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
1.增加数据文件
ALTER TABLESPACE game
ADD DATAFILE '/oracle/oradata/db/GAME02.dbf' SIZE 1000M;
2.手动增加数据文件尺寸
ALTER DATABASE DATAFILE '/oracle/oradata/db/GAME.dbf'
RESIZE 4000M;
3.设定数据文件自动扩展
ALTER DATABASE DATAFILE '/oracle/oradata/db/GAME.dbf
AUTOEXTEND ON NEXT 100M
MAXSIZE 10000M;
设定后查看表空间信息
SELECT A.TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES USED, C.BYTES FREE,
(B.BYTES*100)/A.BYTES "% USED",(C.BYTES*100)/A.BYTES "% FREE"
FROM SYS.SM$TS_AVAIL A,SYS.SM$TS_USED B,SYS.SM$TS_FREE C
WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME AND A.TABLESPACE_NAME=C.TABLESPACE
应用
create tablespace metadata datafile 'D:\oracle\product\10.2.0\oradata\orcl\tbs_metadata.dbf' size 10240m autoextend on next 50M maxsize unlimited
create tablespace metadata logging datafile 'D:\test\oracle\2012606\metadata_20120606.dbf' size 200m autoextend on next 32m maxsize 1024m extent management local;
CREATE USER mo_20120606 IDENTIFIED BY mo_20120606 DEFAULT TABLESPACE metadata TEMPORARY TABLESPACE TEMP;
grant dba to mo_20120606;
CREATE USER qo_20120606 IDENTIFIED BY qo_20120606 DEFAULT TABLESPACE metadata TEMPORARY TABLESPACE TEMP;
grant dba to qo_20120606
imp mo_20120606/mo_20120606 fromuser=metadata touser=mo_20120606 file=D:\test\oracle\20120606\metadata.dmp
imp qo_20120606/qo_20120606 full=y file=D:\test\oracle\20120606\dataqual.dmp
shutdown abort;
startup
如果上面语句失败,尝试用下面语句
创建表空间,修改表空间,创建用户;
create tablespace tbs_bicptest_01 datafile 'D:\test\oracle\xl\tbs_bicptest_01.dbf' size 1024m autoextend on;
alter tablespace tbs_bicptest_01 add datafile 'D:\test\oracle\xl\TBS_BICPTEST_02.DBF' size 1024m autoextend on;
create user mo identified by mo default tablespace tbs_bicptest_01 quota unlimited on tbs_bicptest_01;
导入文件;
imp file=D:\test\oracle\helan\mo_20120606.dmp touser=mo fromuser=mo
imp file=D:\test\oracle\helan\qo_20120606.dmp touser=qo fromuser=qo
drop user mo_20120606 cascade;
drop user qo_20120606 cascade;
DROP TABLESPACE metadata INCLUDING CONTENTS AND DATAFILES;