--创建表空间
CREATE TABLESPACE FSNEW DATAFILE '/path/to/storeDataDir' SIZE 30G EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;
--查看当前用户所有表
select * from user_tables;
--查看所有用户及其表空间
select username,default_tablespace from dba_users ; select * from all_users;
--删除用户及其所有配置
drop user username CASCADE;
--修改用户的表空间
alter user username default tablespace tablespacename;
--删除表空间
drop tablespace tablespacename including contents and datafiles cascade constraint;
--修改表空间状态
alter tablespace tablespacename online; select * from dba_tablespaces; select name from v$datafile; alter tablespace tablespacename rename datafile '/old/path/to/dataStoreDir' to '/new/path/to/dataStoreDir'; alter database rename file '/new/path/to/dataStoreDir/SYSTEM01.DBF' to '/old/path/to/dataStoreDir/SYSTEM01.DBF';
--创建用户并赋权
CREATE USER case IDENTIFIED BY case DEFAULT TABLESPACE XXX; GRANT RESOURCE,DBA,CONNECT TO case ; grant alter any table to case with admin option; grant create session to case with admin option; grant delete any table to case with admin option; grant select any table to case with admin option; grant unlimited tablespace to case with admin option; grant update any table to case with admin option;
--同义词
select 'create or replace synonym ' || synonym_name || ' for dbname.' || table_name || ';' from user_synonyms; --create or replace synonym tablename for dbname.tablename;
--查看版本号
select banner||':'||(select utl_inaddr.get_host_name() from dual) version from v$version where rownum=1
--解决锁表
SELECT l.session_id sid, s.serial# FROM v$locked_object l, all_objects o, v$session s WHERE l.object_id = o.object_id AND l.session_id = s.sid ORDER BY sid, s.serial# ; alter system kill session '128,3778'; alter system kill session '153,2841';
--命令导出数据库
--使用exp
exp username/password@ip/oanet file=D:exportgd_base.dmp log=/path/to/exportlog/xxx.log full=y
--使用expdp导出数据
1. 准备工作
连接目标数据库,查看服务器端字符集
SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
----------------------------------------------------
SIMPLIFIED CHINESE_CHINA.ZHS16GBK
SQL>
2. 退出当前会话,设置客户端字符集使之与服务端字符集一致
SQL> exit
从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options 断开
C:>SET NLS_LANG= SIMPLIFIED CHINESE_CHINA.ZHS16GBK
3. 创建逻辑目录,并赋予Oracle对其的读写权限
使用EXPDP工具时,其转存储文件只能被存放在directory对象对应的OS目录中,而不能直接指定转存储文件所在的OS目录。在此,先在操作系统创建目录C:dump
以system等管理员身份登录sqlplus,授予用户test对目录对象dmp_dir的读写权限。
create directory dmp_dir as 'C:dump'
grant read, write on directory dmp_dir to hlsbi;
创建路径需要sys权限,需要有create any directory权限才可以创建路径。
选项:DIRECTORY=directory_object
Directory_object用于指定目录对象名称。需要注意,目录对象是使用CREATE DIRECTORY语句建立的对象,而不是OS目录。