1.登录oracle
sqlplus /nolog
connect sys as sysdba
connect sys/sys@SUGDB as sysdba;
2.创建表空间,以及对应的用户和权限
创建表空间
create tablespace hldev datafile
'F:\ORACLE\PRODUCT\10.2.0\ORADATA\SUGDB\hldev.ora' size 500m reuse
autoextend on maxsize unlimited default storage(initial 320k
next 320k minextents 1 maxextents unlimited pctincrease 0);
创建用户
create user hldev identified by hldev
default tablespace hldev
temporary tablespace temp;
授权
grant dba to hldev;
3.首先查看表空间的名字和所属文件
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
4.增加数据文件
ALTER TABLESPACE game
ADD DATAFILE '/oracle/oradata/db/GAME02.dbf' SIZE 1000M;
5.手动增加数据文件尺寸
ALTER DATABASE DATAFILE '/oracle/oradata/db/GAME.dbf'
RESIZE 4000M;
6.设定数据文件自动扩展
ALTER DATABASE DATAFILE '/oracle/oradata/db/GAME.dbf
AUTOEXTEND ON NEXT 100M
MAXSIZE 10000M;
7.查看数据库名
select name from v$database;
8.查看实例名
select instance_name from v$instance;
9.window上安装的oracle数据备份操作(dmp命令)
- 找到oracle在系统中的安装路径,并找到oracle\app\product\11.2.0(版本信息)\dbhome_1\BIN>
- 在此目录执行cmd命令
- 调整该命令
exp 用户名/密码@ORCL file=D:/备份名称.dmp log=D:/20170417.log
10.备份远程 oracle 数据库(dmp命令)
相同版本之间备份
- 本地安装过oracle数据库,并且远程的数据库和本地的数据库版本相同
查看oracle数据库版本
select * from v$version
- 执行该命令
exp 用户名/密码@远程oralce数据库的IP:端口号/实例 file=存放位置:\文件名.dmp full = y;
例如:
exp name/pwd@ip:1521/test file=D:\1.dmp version=11.2.0.4.0 full = y;
11.oracle数据回复操作(dmp命令)
恢复命令,切换到oracle安装目录,oracle\app\product\11.2.0(版本信息)\dbhome_1\BIN>,在该目录cmd,执行下面命令
imp 用户名\密码@ORCL file=D:/XXX.dmp fromuser=A touser=B log=路径
fromuser:从哪里导出来的额
touser:要导入到哪里
imp name\pwd@ORCL file=D:/XXX.dmp fromuser=bocglsugwl touser=bocglsugwl log=路径
(可以带的参数:full=y,ignore=y)
imp name\pwd@OL file=D:/20180512.dmp full=y;
fromuser、touser 说明
实际操作中会有这种情况,从某个地方备份下来数据库,使用的用户是A,需要将该将该备份文件导入到新的schema中,新建的用户是B,你重新创建了一个表空间用来存储该数据,在恢复数据的时候,可以使用fromuser、touser 这两个关键字
12. linux连接数据库
sqlplus user/pwd@ip/orcl
--执行脚本:
SQL>@/home/dmp/update_check.sql
13.删除空的表空间,但是不包含物理文件
drop tablespace tablespace_name;
14.删除非空表空间,但是不包含物理文件
drop tablespace tablespace_name including contents;
15.删除空表空间,包含物理文件
drop tablespace tablespace_name including datafiles;
16.删除非空表空间,包含物理文件
drop tablespace tablespace_name including contents and datafiles;
17.如果其他表空间中的表有外键等约束关联到了本表空间中的表的字段,就要加上CASCADE CONSTRAINTS
drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;
18.以system用户登录,查找需要删除的用户
查找用户
select * from dba_users;
查找工作空间的路径
select * from dba_data_files;
删除用户
drop user 用户名称 cascade;
删除表空间
drop tablespace 表空间名称 including contents and datafiles cascade constraint;
例如:删除用户名成为ABC,表空间名称为ABC
--删除用户,及级联关系也删除掉
drop user ABC cascade;
--删除表空间,及对应的表空间文件也删除掉
drop tablespace ABC including contents and datafiles cascade constraint;
删除无任何数据对象的表空间:
首先使用PL/SQL界面化工具,或者使用oracle自带的SQL PLUS工具,连接需要删除的表空间的oracle数据局库。
确认当前用户是否有删除表空间的权限,如果没有 drop tablespace,请先用更高级的用户(如sys)给予授权或者直接用更高级的用户。
用drop tablespace xxx ,删除需要删除的表空间。
删除有任何数据对象的表空间
使用drop tablespace xxx including contents and datafiles;来删除表空间。
注意事项
如果drop tablespace语句中含有datafiles,那datafiles之前必须有contents关键字,不然会提示ora-01911错误
19. expdp/impdp高版本导入到低版本
20. Oracle创建只有查看权限的用户
create user 用户名 identifed by 密码
grant connect,select any table to 用户名这样创建的用户就可以连接数据库和只有对任何表有查询权限了
create user lisuser identified by lisuser;
grant connect,select any table to lisuser
select * from bocglsugwl2.lsuser
21. oracle 创建dblink
select * from all_db_links;
drop database link link_name;
create database link link名称 connect to 用户名 identified by 密码 using '远程的数据库ip:端口/实例名称';
create database link wlint connect to wlint identified by wlint using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 远程的数据库ip )(PORT = 端口))
)
(CONNECT_DATA =
(SERVICE_NAME = 实例名称 )
)
)';
查看远程数据库的表
select * from 表名@link名称;
22. 使用expdp/impdp备份和恢复数据
恢复数据
create directory dump_test as 'D:\test\dump';
impdp username/pwd schemas=实例名称 directory=dump_test dumpfile=AAA20170907.DMP logfile=AAA20170907.log