码迷,mamicode.com
首页 > 数据库 > 详细

数据库建用户脚本install.sh

时间:2017-10-01 00:30:32      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:tab   恢复   根据   immediate   exec   lin   tables   数据   手工   


--创建oracle用户和表空间, 仅首次安装系统时需要执行.
--若之前已创建同名的表空间或用户, 则对应脚本会被忽略.
declare
---------------------------------------------------------------
-- 以下配置请根据实际部署情况手工修改
---------------------------------------------------------------
--用户名
v_username varchar2(1000) := ‘test‘;
--密码
v_password varchar2(1000) := ‘1‘;
--数据文件目录, 这个目录在ORACLE服务器, 需要和DBA确认.
v_datafile_path varchar2(1000) := ‘/home/oracle/app/oradata/orcl‘;

--存放数据泵备份文件的目录, 这个目录在ORACLE服务器, 需要和DBA确认. 对应linux系统的目录需要手工创建?
--v_directory_path varchar2(1000) := ‘/home/oracle/product/admin/ora11g/dpdump‘;
---------------------------------------------------------------
-- 以下信息请勿修改
---------------------------------------------------------------
v_count number;
v_dir_name varchar2(1000); --目录名称
v_ts_name varchar2(1000); --当前库表空间
begin
v_username := LOWER(v_username);
v_dir_name := LOWER(‘fmdmp_‘ || v_username);
v_ts_name := LOWER(v_username);

????--创建数据备份与恢复目录
????select count(1) into v_count from dba_directories a where a.directory_name = UPPER(v_dir_name);
????if v_count = 0 then
???? execute immediate ‘create directory ‘ || v_dir_name || ‘ as ‘‘‘ || v_directory_path || ‘/‘ || v_username || ‘‘‘‘;
????end if;

????--创建当前库表空间
????select count(*) into v_count from dba_tablespaces a where a.tablespace_name = UPPER(v_ts_name);
????if (v_count = 0) then
????????execute immediate ‘create tablespace ‘
|| v_ts_name || ‘ logging datafile ‘‘‘ || v_datafile_path || ‘/‘ || v_ts_name || ‘.dbf‘‘ size 512M‘
|| ‘ autoextend on next 512M‘
|| ‘ extent management local‘
|| ‘ segment space management auto‘;
????end if;
????
????--创建当前库用户
????select count(*) into v_count from dba_users a where a.username = UPPER(v_username);
????if (v_count = 0) then
????????execute immediate ‘create user ‘ || v_username || ‘ identified by ‘ || v_password || ‘ default tablespace ‘ || v_ts_name || ‘ temporary tablespace TEMP‘;
????end if;
execute immediate ‘grant connect, resource, dba, unlimited tablespace, create any table, select any table, grant any object privilege, create any synonym, drop any synonym to ‘ || v_username;
execute immediate ‘grant execute on utl_file to ‘ || v_username;
--授权目录给当前库用户
????execute immediate ‘grant read,write on directory ‘ || v_dir_name || ‘ to ‘ || v_username;
????
????--授权查询dba_directories给当前用户
????execute immediate ‘grant select on sys.DBA_DIRECTORIES to ‘ || v_username;
end;
/

数据库建用户脚本install.sh

标签:tab   恢复   根据   immediate   exec   lin   tables   数据   手工   

原文地址:http://www.cnblogs.com/skiing886/p/7616340.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!