Oracle常用操作
创建表空间 create tablespace [tablespace_name] datafile 'e:\oracle\oradata\test\data_1.dbf' size 2000M;
删除表空间 DROP TABLESPACE [tablespace_name] INCLUDING CONTENTS AND DATAFILES;
创建数据库 CREATE DATABASE [database_name];
删除数据库 DROP DATABASE [database_name];
创建表 CREATE TABLE [tabname];
删除表 DROP TABLE [tabname];
创建用户,并指定表空间 create user [username] identified by [password] default tablespace [tablesapce_name];
删除用户 drop user [username] cascade;
解除账户被锁状态 alter user [username] account unlock;
修改账户密码 alter user [username] identified by [new_password];
无需密码登录管理员账户 sqlplus / as sysdba;
关闭数据库:shutdown immediate;
打开数据库:startup
导出dump文件:
expdp epichust/epichust@127.0.0.1/orcl directory=DATA_PUMP_DIR dumpfile=20210330.dmp
logfile=20210330.log schemas=epichust version=11.2.0.1.0
将导出的dump文件导入Oracle数据库:
-- 创建表空间 create tablespace EPICHUST datafile 'D:\app\15735400536\oradata\EPICHUST.DBF' size 6000M; -- 创建用户 create user epichust identified by epichust default tablespace EPICHUST; -- 设置表空间自动扩容 ALTER DATABASE DATAFILE 'D:\app\15735400536\oradata\EPICHUST.DBF' AUTOEXTEND ON NEXT 500M; -- 查看表空间是否自动扩容 SELECT FILE_NAME,TABLESPACE_NAME,AUTOEXTENSIBLE FROM dba_data_files; -- 给创建的用户权限 GRANT CREATE VIEW,CREATE DATABASE LINK,UNLIMITED TABLESPACE,CONNECT,RESOURCE TO epichust; grant dba to epichust; grant sysdba to epichust; Grant read,write on directory data_pump_dir to epichust; -- 查看dump文件路径 select * from dba_directories; -- 将dump文件放入Oracle dump文件路径 -- 导入dump语句 $impdp epichust/epichust@127.0.0.1/orcl DIRECTORY=data_pump_dir DUMPFILE=20210330.DMP
logfile=20210330.log remap_SCHEMA=unimax_jsdj_cs:epichust remap_tablespace=MESTAR_DATA:EPICHUST
删除表空间语句
--删除空的表空间,但是不包含物理文件 drop tablespace tablespace_name; --删除非空表空间,但是不包含物理文件 drop tablespace tablespace_name including contents; --删除空表空间,包含物理文件 drop tablespace tablespace_name including datafiles; --删除非空表空间,包含物理文件 drop tablespace tablespace_name including contents and datafiles; --如果其他表空间中的表有外键等约束关联到了本表空间中的表的字段,就要加上CASCADE CONSTRAINTS drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;
删除有权限的用户
drop user user_name cascade;
设置表空间可扩展,并指定扩展容量大小
ALTER DATABASE DATAFILE 'E:\ORACLE_DB\DATABASE.DBF' AUTOEXTEND ON NEXT 500M;
表分析
analyze table t1 compute statistics fortable; --针对表收集信息 analyze table t2 compute statistics for allcolumns; --针对表字段收集信息 analyze table t3 compute statistics for all indexescolumns; --收集索引字段信息 analyze table t4 computestatistics; --收集表,表字段,索引信息 analyze table t5 compute statistics for all indexes; --收集索引信息 analyze table t6 compute statistics for table for all indexesfor allcolumns; --
推荐阅读:https://blog.csdn.net/weixin_30808693/article/details/95327455