1. oracle 创建用户(test01/test)并授予权限:
create user test01 identified by 'test'
default tablespace users01
temporary tablespace temp01
quota 100m on users01
password expire
ACCOUNT UNLOCK;
如果不指定default tablespace,那么将会使用系统表空间system tablespace。password expire 表示第一次登录时必须更改密码
如果没有account unlock,那么该用户创建完毕后处于lock状态,无法登录。可使用下面语句解锁:
alter user test01 unlock;
光创建用户还不行,至少还得赋予用户一些最基本的权限,如创建会话、索引:
grant connect,resource to test01;
更改用户相关信息:
alter user test01
quota 200m on users;
2. 在临时表空间限制空间限额不会真实生效,在undotablespace上不允许设置空间限额。临时表空间主要用于排序,UNDOTABS表空间是数据恢复时用到
字典管理方式和自动管理方式。自动管理方式采用位图管理extent,减少字典之间的竞争,同时避免了碎片
3. 删除用户:
正在连接中的用户不能被删除,该用户有数据对象时必须指定cascade才可以删除用户
DROP USER test01 CASCADE;
4. 设置系统参数(排版,设置行和列):
现查看系统默认值:
SQL> show linesize;
linesize 80
SQL> show pagesize;
pagesize 14
SQL> set linesize 120; #不是SQL语句
SQL> set pagesize 200; #不是SQL语句
vim ~oracle/login.sql #可把常用的设置项添加到此文件,逐渐丰富
或vi /u01/app/oracle/product/10.2.0/db_1/sqlplus/admin/glogin.sql
login.sql只对某特定用户生效,它的优先级高于glogin.sql,glogin.sql是全局设置。
SQL> column ename format a50; #调整某一列列显示效果,“ename”是列的名称。column和format都可以缩写,比如col和for。
5. 查看有哪些数据文件及其状态信息:
SQL> select file#,name,status from v$datafile;
FILE# NAME STATUS
------ ------------------------------------------------- -------
1 /u01/app/oracle/oradata/test01/system01.dbf SYSTEM
2 /u01/app/oracle/oradata/test01/undotbs01.dbf ONLINE
3 /u01/app/oracle/oradata/test01/sysaux01.dbf ONLINE
4 /u01/app/oracle/oradata/test01/users01.dbf ONLINE
6. 查看控制文件及其信息:
SQL> select name from v$controlfile;
NAME
-------------------------------------------------
/u01/app/oracle/oradata/test01/control01.ctl
/u01/app/oracle/oradata/test01/control02.ctl
/u01/app/oracle/oradata/test01/control03.ctl
试图也是表,想查看有些什么列名称,可以使用desc
7. 查看表空间信息:
SQL> select tablespace_name,block_size,status,ALLOCATION_TYPE from dba_tablespaces;
TABLESPACE_NAME BLOCK_SIZE STATUS ALLOCATIO
------------------------------ ---------- --------- ---------
SYSTEM 8192 ONLINE SYSTEM
UNDOTBS1 8192 ONLINE SYSTEM
SYSAUX 8192 ONLINE SYSTEM
TEMP 8192 ONLINE UNIFORM
USERS 8192 ONLINE SYSTEM
EXAMPLE 8192 ONLINE SYSTEM
6 rows selected.
SQL> set timing on #支持显示查询使用的时间
使用rownum来限制select 显示的行数:
比如我只想显示匹配结果的前2行,那么应该使用rownum < 3,而不是rownum = 3.
SQL> select tablespace_name,block_size,status,ALLOCATION_TYPE from dba_tablespaces where rownum < 3;
TABLESPACE_NAME BLOCK_SIZE STATUS ALLOCATIO
------------------------------ ---------- --------- ---------
SYSTEM 8192 ONLINE SYSTEM
UNDOTBS1 8192 ONLINE SYSTEM
SQL> select tablespace_name,block_size,status,ALLOCATION_TYPE from dba_tablespaces where rownum < 7 order by tablespace_name;
TABLESPACE_NAME BLOCK_SIZE STATUS ALLOCATIO
------------------------------ ---------- --------- ---------
EXAMPLE 8192 ONLINE SYSTEM
SYSAUX 8192 ONLINE SYSTEM
SYSTEM 8192 ONLINE SYSTEM
TEMP 8192 ONLINE UNIFORM
UNDOTBS1 8192 ONLINE SYSTEM
USERS 8192 ONLINE SYSTEM
6 rows selected.
8. 创建永久表空间:
SQL> create tablespace demo01 2 datafile '/u01/app/oracle/oradata/test01/demo01.dbf' 3 size 64M;Tablespace created.Elapsed: 00:00:01.34注意在创建后,该表空间的名称为大写,其他表空间也是如此,所以在查询时注意名称的大写。
9. 创建临时表空间:
SQL> create temporary tablespace temp02 tempfile '/u01/app/oracle/oradata/test01/temp02.dbf' size 3M;Tablespace created.15. 查看instance当前所处的状态,即是nomount,mount,或是open状态:
SQL> select status from v$instance;
STATUS
------------
OPEN
So what exactly is in those CONNECT and RESOURCE Oracle roles? The
ship with every Oracle database and many apps require they be granted.
I did a little digging and found the following:
In Oracle 10gR2 things are fairly sane:
CONNECT role has only CREATE SESSION
RESOURCE has CREATE CLUSTER, CREATE INDEXTYPE, CREATE
OPERATOR, CREATE PROCEDURE, CREATE SEQUENCE, CREATE TABLE, CREATE
TRIGGER and CREATE TYPE
In Oracle 9iR2 things get a little scary:
CONNECT has ALTER SESSION, CREATE CLUSTER, CREATE
DATABASE LINK, CREATE SEQUENCE, CREATE SESSION, CREATE SYNONYM, CREATE
TABLE and CREATE VIEW. Rather a scary lot for a role called ‘connect’
RESOURCE has CREATE CLUSTER, CREATE INDEXTYPE, CREATE
OPERATOR, CREATE PROCEDURE, CREATE SEQUENCE, CREATE TABLE, CREATE
TRIGGER and CREATE TYPE
To find these privileges you can query the DBA_SYS_PRIVS table with a query like this:
select grantee, privilege, admin_option from dba_sys_privs where grantee='CONNECT';
OEM的访问地址:
查看OEM服务是否起来:
emctl status dbconsole
或者查看1158端口是否监听:
netstat -an|grep :1158
启动OEM服务:
emctl start dbconsole