1. 配置
ORACLE_CLIENT:
- 系统环境变量
1 2 3 4
| NLS_LANG -> AMERICAN_AMERICA.ZHS16GBK TNS_ADMIN -> 安装目录下的app\product\11.2.0\client_1\network\admin,即tns配置文件 PATH -> 添加Oracle的Home目录下的BIN目录 %ORACLE_HOME%\BIN ORACLE_HOME -> (可选)ORACLE的Home目录,也可直接在PATH中添加 app\product\11.2.0\client_1
|
- 权限配置
Oracle的Home目录下的BIN目录,添加Authenticated Users权限
ORACLE_SERVER:
Database Control URL 为 https://localhost:1158/em
管理资料档案库已置于安全模式下, 在此模式下将对 Enterprise Manager 数据进行加密。加密密钥已放置在文件 C:/app/Administrator/product/11.2.0/dbhome_1/jw-pc_orcl/sysman/config/emkey.ora 中。请务必备份此文件, 因为如果此文件丢失, 则加密数据将不可用。
2. 数据库/表空间
数据库实例:可创建多个实例,用于连接访问数据库的名称,即实例名
表空间:通过表空间存储物理表,一个数据库实例有多个表空间(默认有USERS、SYSAUX),一个表空间有多张表,每个数据库至少有一个表空间:system 表空间
数据库:
1 2 3 4 5
| select name from v$database;
select instance_name from v$instance;
|
数据表空间:
1 2 3 4 5 6 7 8 9 10
| select d.default_tablespace, d.temporary_tablespace, d.username from dba_users d;
create tablespace 表空间名称 datafile '数据文件路径及文件名' size 表空间大小; create tablespace data_test datafile 'E:\data\data_1.dbf' size 20M; create tablespace idx_test datafile 'E:\data\idx_1.dbf' size 20M;
create tablespace atablespace datafile 'e:/data/oracle/tablespace/atablespace.dbf' size 20M autoextend on;
|
数据表:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| sqlplusw study/study@test
select * from atable;
select * from auser.atable;
select * from user_tables;
create table 数据表名 create table test_user ( no number(5) not null , username varchar2(30) not null , passpord varchar2(30) not null , constraint pk_connectdb primary key(no) ) storage (initial 10k next 10k pctincrease 0);
create table atable(id int primary key, name varchar2(50) not null, age int);
|
id 字段自增长:
1 2 3 4 5
| create sequence atable_id_sequence minvalue 1 maxvalue 99999999 start with 1 increment by 1 cache 20; create or replace trigger atable_trigger before insert on atable for each row begin select atable_id_sequence.nextval into :new.id from dual; end;
|
删除自增长:
1
| drop sequence atable_id_sequence;
|
3. 用户
用户:必须先创建用户,并为用户指定表空间
查看用户
1 2 3 4 5 6 7 8 9
| SELECT * FROM ALL_USERS; SELECT * FROM DBA_USERS; SELECT * FROM DBA_TS_QUOTAS;
conn auser/auser;
select * from user_users;
|
创建用户
1 2 3 4 5 6
| create user 用户名 identified by 密码 default tablespace 表空间表; create user 用户名 identified by 密码 default tablespace 表空间(默认USERS) temporary tablespace 临时表空间(默认TEMP);
create user auser identified by 123456 default tablespace atablespace temporary tablespace TEMP; create user study identified by study default tablespace data_test;
|
修改用户
1 2 3 4 5 6 7
| ALTER USER avyrros IDENTIFIED EXTERNALLY DEFAULT TABLESPACE data_ts TEMPORARY TABLESPACE temp_ts QUOTA 100M ON data_ts QUOTA 0 ON test_ts PROFILE clerk;
|
删除用户
1 2
| DROP USER username [CASCADE]
|
摘要文件
1 2 3 4 5 6
| create profile aprofile limit FAILED_LOGIN_ATTEMPTS 3PASSWORD_LOCK_TIME 1;
alter user auser profile aprofile;
select username, profile from dba_users;
|
检验aprofile效果:
1 2 3 4 5 6 7 8 9
| sys@ORCL> conn auser/1 ERROR:ORA-01017: invalid username/password; logon denied警告: 您不再连接到 ORACLE。 sys@ORCL> conn auser/2 ERROR:ORA-01017: invalid username/password; logon denied sys@ORCL> conn auser/3ERROR:ORA-01017: invalid username/password; logon denied sys@ORCL> conn auser/4ERROR:ORA-28000: the account is locked sys@ORCL>
|
连续输错四次密码,令账户被锁:
sysdba身份登录查看:
1 2 3 4 5
| sys@ORCL> conn sys/** ** as sysdba已连接。 sys@ORCL> select username,account_status from dba_users where username='auser'; USERNAME ACCOUNT_STATUS-----------------------------------------------------------U2 LOCKED(TIMED) sys@ORCL>
|
1 2
| alter user auser account unlock;
|
4. 权限
权限查询
1 2 3 4 5 6 7 8 9 10 11 12
| select * from user_sys_privs;
select * from user_tab_privs_made;
select * from all_tab_privs_made;
select owner, object_name, object_type, status from dba_objects where owner='auser'
select * from user_tab_privs_recd;
select * from all_tab_privs_recd;
|
权限分配
1 2 3 4 5 6 7 8 9 10
| grant connect to auser;
grant resource to auser;
grant connect,resource to auser;
grant create session,create table to auser;
grant dba to study;
|
5. 角色
创建口令文件
1
| orapwd file='..........\pwd{SID}.ora' password='***(sys的密码)' tntries=10(口令文件最大的用户数量)
|
1 2 3 4 5 6
| grant sysdba to auser;
revoke sysdba from auser;
select * from v$pwfile_users;
|
6. GUID
1 2 3 4 5 6 7 8 9 10 11
| declare v_guid varchar2(50):=sys_guid(); sql_guid varchar2(50); begin sql_guid:= substr(v_guid, 1, 8) || '-' || substr(v_guid, 9, 4) || '-' || substr(v_guid, 13, 4) || '-' || substr(v_guid, 17, 4) || '-' || substr(v_guid, 21, 12); dbms_output.put_line(sql_guid); end;
|