一、系统命令
·1.登录 dba用户命令
sqlplus / as sysdba
2.用户命令
-
删除用户
DROP USER **** CASCADE;
DROP SCHEMA **** CASCADE;
-
创建用户
create user username identified by password;
-
用户权限
grant create session,create table,unlimited tablespace,dba to username;
-
配置用户表空间
alter user username default tablespace ****;
alter user username temporary tablespace ****;3.表空间
-
查询表空间数据库文件信息
select * from dba_data_files;
-
查询表空间使用信息
1 SELECT UPPER(F.TABLESPACE_NAME) "表空间名", 2 D.TOT_GROOTTE_MB "表空间大小(M)", 3 D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)", 4 TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,2),'990.99') || '%' "使用比", 5 F.TOTAL_BYTES "空闲空间(M)", 6 F.MAX_BYTES "最大块(M)" 7 FROM (SELECT TABLESPACE_NAME, 8 ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES, 9 ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES10 FROM SYS.DBA_FREE_SPACE11 GROUP BY TABLESPACE_NAME) F,12 (SELECT DD.TABLESPACE_NAME,13 ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB14 FROM SYS.DBA_DATA_FILES DD15 GROUP BY DD.TABLESPACE_NAME) D16 WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME17 ORDER BY 1;
-
创建表空间
CREATE TABLESPACE **** datafile '****.dbf' SIZE 500M AUTOEXTEND ON NEXT 50M MAXSIZE 5G;
-
创建临时表空间
CREATE TEMPORARY TABLESPACE **** TEMPFILE '****.dbf' SIZE 50M AUTOEXTEND ON NEXT 50M MAXSIZE 2G;
-
扩展表空间
ALTER TABLESPACE **** ADD DATAFILE '****.dbf' SIZE 5G AUTOEXTEND ON NEXT 50M MAXSIZE 20G;
4.数据导入导出
-
创建数据泵 目录路径
create directory export_data as '服务器路径';
-
分配目录读写权限
grant read,write on directory export_data to username;
-
创建远程数据库连接
1 create database link ****2 connect to username identified by password3 using '(DESCRIPTION =4 (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.10)(PORT = 1521))5 (CONNECT_DATA = (SERVICE_NAME = orcl)6 )7 )';
-
导出命令
-
利用远程数据库连接导出数据库
impdp username/password directory=export_data remap_schema=username:new_username remap_tablespace=tablespace:new_tablespace NETWORK_LINK=**** logfile=impdpdblink.log
-
导出dmp文件
impdp username/password directory=export_data remap_schema=username:new_username remap_tablespace=tablespace:new_tablespace dumpfile=impdp.dmp logfile=impdp.log
-
导入命令
expdp username/password directory=export_data dumpfile=impdp.dmp logfile=expdp.log schemas=schemas
-
根据表导出表数据
expdp username/password directory=export_data dumpfile=impdp.dmp Tables=Table
-
根据表名导出表结构
expdp username/password directory=export_data CONTENT=METADATA_ONLY dumpfile=impdp.dmp Tables=Table