建立表空间和用户的步骤: 用户 建立:create user 用户名 identified by "密码"; 授权:grant create session to 用户名; grant create table to 用户名; grant create tablespace to 用户名; grant create view to 用户名;
表空间 建立表空间(一般建N个存数据的表空间和一个索引空间): create tablespace 表空间名 datafile ' 路径(要先建好路径)\***.dbf ' size *M tempfile ' 路径\***.dbf ' size *M autoextend on --自动增长 --还有一些定义大小的命令,看需要 default storage( initial 100K, next 100k, );
例子:创建表空间 create tablespace DEMOSPACE datafile 'E:/oracle_tablespaces/DEMOSPACE_TBSPACE.dbf' size 1500M autoextend on next 5M maxsize 3000M; 删除表空间 drop tablespace DEMOSPACE including contents and datafiles
用户权限 授予用户使用表空间的权限: alter user 用户名 quota unlimited on 表空间; 或 alter user 用户名 quota *M on 表空间;
--表空间 CREATE TABLESPACE sdt DATAFILE 'F:\tablespace\demo' size 800M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO; --索引表空间 CREATE TABLESPACE sdt_Index DATAFILE 'F:\tablespace\demo' size 512M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO; --2.建用户 create user demo identified by demo default tablespace std; --3.赋权 grant connect,resource to demo; grant create any sequence to demo; grant create any table to demo; grant delete any table to demo; grant insert any table to demo; grant select any table to demo; grant unlimited tablespace to demo; grant execute any procedure to demo; grant update any table to demo; grant create any view to demo;
grant dba to demo ; --导入导出命令 ip导出方式: exp demo/demo@127.0.0.1:1521/orcl file=f:/f.dmp full=y exp demo/demo@orcl file=f:/f.dmp full=y imp demo/demo@orcl file=f:/f.dmp full=y ignore=y
1、首先我们可以用scott用户以sysdba的身份登录oracle conn scott/tiger as sysdba; 2、创建用户 create user erpsys identified by erpsys; 3、修改用户的密码 alter user erpsys identified by erpsys123; 4、查看一下所有用户所在的表空间 select username,default_tablespace from dba_users; 5、创建一个表空间(注:datafile后面是表空间的物理存储路径,文件名的后缀可以随便. ) ----create tablespace DB_ERP datafile 'E:\Program Files\MyERP\OracleDB\ERP_data.dbf' size 200M;
/*创建数据表空间*/
create tablespace DB_ERP_Data
datafile 'E:\Program Files\MyERP\OracleDB\ERP_data.dbf'
size 200M
autoextend on next 5M maxsize 3000M;
create tablespace erpsys
datafile 'E:\Program Files\MyERP\OracleDB\erpsys_data.dbf'
size 200M
autoextend on next 5M maxsize 3000M;
/*创建临时表空间*/
create tablespace DB_ERP_Temp
datafile 'E:\Program Files\MyERP\OracleDB\ERP_temp.dbf'
size 200M
autoextend on next 5M maxsize 3000M;
6、将表空间分配给用户 alter user erpsys default tablespace DB_ERP_Data;
alter user erpsys default tablespace erpsys;
7、给用户分配了表空间,用户还不能登陆(没有登录权限),因此还需要为用户分配权限
grant create session,create table,create view,create sequence,unlimited tablespace to erpsys;
grant create session,create table,create any view,drop any view,create user,create sequence,unlimited tablespace,drop user,alter user,exp_full_database,imp_full_database,dba,connect,resource to erpsys; 8、给用户分配了权限之后我们就可以用erpsys用户来登录 conn erpsys/erpsys123; 9、登录之后我们也可以来查询用户所具有的权限 select *from session_privs; 10、删除用户及其相关对象 drop user erpsys cascade;
11、导出数据
12、导入数据库
12.1、新建directory
create or replace directory dump_dir as 'E:\dump';
12.2、查询有哪些directory
select * from dba_directories;
12.3、赋权
grant read,write on directory dump_dir to user01;
12.4、删除directory
drop directory dump_dir;
执行导入:
create or replace directory dump_dir as 'E:\dump';
impdp erpsys/erpsys123@orcl DIRECTORY=dump_dir DUMPFILE=EXPDP20160317.dmp FULL=y;
create user hs_srch identified by hundsun; grant connect to hs_srch;--授予connect权限 grant select on hs_acct.customer to hs_srch;--给表授予select(只读)权限
select 'grant select on hs_acct.' || table_name || ' to hs_srch;' from user_tables a; grant select on hs_acct.view_allbranch to hs_srch;--给视图授予select(只读)权限,注意:该用户登录后是看不到视图的,可以通过语句来查询,如果想看到视图需要给它一个show的权限 grant select any table to hs_srch; --授予查询任何表 grant select any dictionary to hs_srch;--授予 查询任何字典
查看Orcle实例名称
echo $ORACLE_SID
---查看所有数据库DBLink链接 select * from dba_db_links; ---创建数据库DBLink create public database link TestDblink connect to dbName identified by dbPassword using '(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)))'; 解释 TestDblink : 表示dblink名字 dbName :表示 远程数据库的用户 dbPassword:表示 远程数据库的密码 HOST : 表示远程数据库IP PORT : 表示远程数据库端口 SERVICE_NAME : 远程数据库的实例名 ---删除数据库DBLink drop public database link TestDblink; ---如果想在本地数据库中通过dblink访问远程数据库'orcl'中dbName.tb_test表,sql语句如下所示: select * from db.tb_test@TestDblink;