oracle常用命令
程序员文章站
2022-05-08 16:25:18
...
1 创建临时表空间
create temporary tablespace user_temp
tempfile 'D:\oracle\oradata\Oracle9i\user_temp.dbf'
size 50m
autoextend on
next 50m maxsize 20480m
extent management local;
2 创建数据库表空间
create tablespace user_data
logging
datafile 'D:\oracle\oradata\Oracle9i\user_data.dbf'
size 50m
autoextend on
next 50m maxsize 20480m
extent management local;
3 创建用户并指定表空间
create user username identified by password
default tablespace user_data
temporary tablespace user_temp;
4 给用户授权
grant connect,resource,dba to username;
5 锁定用户
alter user username account lock
6 解锁用户
alter user username account unlock
7 限制sysdba远程登录
REMOTE_LOGIN_PASSWORDFILE=none
SQLNET.AUTHENTICATION_SERVICES= (NTS):
oracle安装用户本地sqlplus “/ as sysdba”能登录
非oracle安装用户本机sqlplus “sys/manager as sysdba”无法登录
非oracle安装用户远程sqlplus “/ as manager@sid as sysdba”无法登录
SQLNET.AUTHENTICATION_SERVICES=(NTS)在$ORACLE_HOME/network/admin目录下的sqlnet.ora配置,如果该目录下没有sqlnet.ora文件,拷贝sample目录下sqlnet.ora的文件大该目录下
8 启用数据字典保护
alter system set 07_DICTIONARY_ACCESSIBILITY=false scope=spfile
9 记录记录用户的登陆信息
1)创建一张记录登录TABLE
CREATE TABLE SYSTEM.LOGIN_LOG
(
SESSION_ID NUMBER(8,0) NOT NULL,
LOGIN_ON_TIME DATE,
LOGIN_OFF_TIME DATE,
USER_IN_DB VARCHAR2(50),
MACHINE VARCHAR2(50),
IP_ADDRESS VARCHAR2(20),
RUN_PROGRAM VARCHAR2(50)
);
2)创建两个trigger(触发器)
--记录登录触发器
CREATE OR REPLACE TRIGGER SYS.LOGIN_ON_INFO
AFTER LOGON
ON DATABASE
BEGIN
INSERT INTO SYSTEM.LOGIN_LOG (session_id,login_on_time,login_off_time,user_in_db,machine,ip_address,run_program) SELECT AUDSID,sysdate,null,sys.login_user,machine,SYS_CONTEXT('USERENV','IP_ADDRESS'),program FROM v$session WHERE AUDSID=USERENV('SESSIONID');
END;
--记录登出触发器
--记录登出信息触发器
CREATE OR REPLACE TRIGGER SYS.LOGIN_OFF_INFO
BEFORE LOGOFF
ON DATABASE
Begin
update system.login_log set login_off_time=sysdate where session_id=USERENV('SESSIONID');
exception when others then
null;
END;
如果使用sqlplus创建触发器存储过程的话,需要在结尾添加/结束
create temporary tablespace user_temp
tempfile 'D:\oracle\oradata\Oracle9i\user_temp.dbf'
size 50m
autoextend on
next 50m maxsize 20480m
extent management local;
2 创建数据库表空间
create tablespace user_data
logging
datafile 'D:\oracle\oradata\Oracle9i\user_data.dbf'
size 50m
autoextend on
next 50m maxsize 20480m
extent management local;
3 创建用户并指定表空间
create user username identified by password
default tablespace user_data
temporary tablespace user_temp;
4 给用户授权
grant connect,resource,dba to username;
5 锁定用户
alter user username account lock
6 解锁用户
alter user username account unlock
7 限制sysdba远程登录
REMOTE_LOGIN_PASSWORDFILE=none
SQLNET.AUTHENTICATION_SERVICES= (NTS):
oracle安装用户本地sqlplus “/ as sysdba”能登录
非oracle安装用户本机sqlplus “sys/manager as sysdba”无法登录
非oracle安装用户远程sqlplus “/ as manager@sid as sysdba”无法登录
SQLNET.AUTHENTICATION_SERVICES=(NTS)在$ORACLE_HOME/network/admin目录下的sqlnet.ora配置,如果该目录下没有sqlnet.ora文件,拷贝sample目录下sqlnet.ora的文件大该目录下
8 启用数据字典保护
alter system set 07_DICTIONARY_ACCESSIBILITY=false scope=spfile
9 记录记录用户的登陆信息
1)创建一张记录登录TABLE
CREATE TABLE SYSTEM.LOGIN_LOG
(
SESSION_ID NUMBER(8,0) NOT NULL,
LOGIN_ON_TIME DATE,
LOGIN_OFF_TIME DATE,
USER_IN_DB VARCHAR2(50),
MACHINE VARCHAR2(50),
IP_ADDRESS VARCHAR2(20),
RUN_PROGRAM VARCHAR2(50)
);
2)创建两个trigger(触发器)
--记录登录触发器
CREATE OR REPLACE TRIGGER SYS.LOGIN_ON_INFO
AFTER LOGON
ON DATABASE
BEGIN
INSERT INTO SYSTEM.LOGIN_LOG (session_id,login_on_time,login_off_time,user_in_db,machine,ip_address,run_program) SELECT AUDSID,sysdate,null,sys.login_user,machine,SYS_CONTEXT('USERENV','IP_ADDRESS'),program FROM v$session WHERE AUDSID=USERENV('SESSIONID');
END;
--记录登出触发器
--记录登出信息触发器
CREATE OR REPLACE TRIGGER SYS.LOGIN_OFF_INFO
BEFORE LOGOFF
ON DATABASE
Begin
update system.login_log set login_off_time=sysdate where session_id=USERENV('SESSIONID');
exception when others then
null;
END;
如果使用sqlplus创建触发器存储过程的话,需要在结尾添加/结束