ORACLE 12C使用
orcl数据库服务器连接字符串
启动和关闭[12c 有误]
C:\Users\***>sqlplus /nolog
SQL*Plus: Release 12.1.0.1.0 Production on 星期日 3月 15 12:56:57 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL>
启动oracle:
SQL> startup open;
关闭oracle:
SQL> shutdown immediate;
关于权限和用户的创建、锁定、修改、赋予和回收权限等权限,必须在sysdba连接身份下执行:
SQL> conn system/******@orcl as system;
Connected to Oracle Database 12c Enterprise Edition Release 12.1.0.1.0
Connected as system@orcl
或者
SQL> conn sys/******@orcl as sysdba;
Connected to Oracle Database 12c Enterprise Edition Release 12.1.0.1.0
Connected as sys@orcl AS SYSDBA
注:as system不加可以,测试用。
查看Oracle数据库所有用户(sysdba):
SQL> SELECT * FROM DBA_USERS;
------------------------------
....
37 rows selected
查看你能管理的所有用户:
SQL> SELECT * FORM ALL_USERS;
查看当前用户信息:
SQL> SELECT * FROM USER_USERS;
创建用户[12c下c##开头创建]:
SQL> create user c##sharefile identified by c##sharefile;
User created
删除用户:
SQL> drop user c##sharefile cascade;
User dropped
解锁或者锁定[lock]用户:
SQL> alter user c##sharefile account unlock;
User altered
创建并解锁:
SQL> create user c##tskk identified by c##tskk1 account unlock;
User created
修改用户密码:
SQL> alter user c##tskk identified by c##tskk;
User altered
用户授权:
连接权限:
SQL> grant connect to c##sharefile;
Grant succeeded
增删改查权限:
SQL> grant resource to c##sharefile;
Grant succeeded
一次赋权:
SQL> grant connect,resource to c##sharefile;
Grant succeeded
回收用户权限:
SQL> revoke connect from c##sharefile;
Revoke succeeded
SQL> revoke resource from c##sharefile;
Revoke succeeded
SQL> revoke connect,resource from c##sharefile;
Revoke succeeded
登录数据库:
SQL> conn c##tskk/c##tskk@orcl as normal;
Connected to Oracle Database 12c Enterprise Edition Release 12.1.0.1.0
Connected as c##tskk@orcl
查看当前登陆的用户名:
SQL> select user from dual;
USER
------------------------------
C##TSKK
或者 [太长部分省略]
USERNAME USER_ID ACCOUNT_STATUS
-------------------------------------------------------------------------------- ---------- --------------------------------
C##TSKK 103 OPEN
查看当前用户拥有的角色和权限[空格已删除]:
SQL> select * from user_role_privs;
USERNAME GRANTED_ROLE ADMIN_OPTION DEFAULT_ROLE OS_GRANTED COMMON
----------------------- ------------------ ------------ ------------ ---------- ------
C##SHAREFILE CONNECT NO YES NO NO
C##SHAREFILE RESOURCE NO YES NO NO
或者
SQL> select * from session_privs;
PRIVILEGE
----------------------------------------
CREATE SESSION
CREATE TABLE
CREATE CLUSTER
CREATE SEQUENCE
CREATE PROCEDURE
CREATE TRIGGER
CREATE TYPE
CREATE OPERATOR
CREATE INDEXTYPE
SET CONTAINER
10 rows selected
用户其他的授权:
GRANT 赋于权限
CONNECT(基本的连接), RESOURCE(程序开发), DBA(数据库管理)
常用的数据对象权限有以下五个:
ALL ON 数据对象名, SELECT ON 数据对象名, UPDATE ON 数据对象名,
DELETE ON 数据对象名, INSERT ON 数据对象名, ALTER ON 数据对象名
GRANT CONNECT, RESOURCE TO 用户名;
GRANT SELECT ON 表名 TO 用户名;
GRANT SELECT, INSERT, DELETE ON表名 TO 用户名1, 用户名2;
2.REVOKE 回收权限
REVOKE CONNECT, RESOURCE FROM 用户名; REVOKE SELECT ON 表名 FROM 用户名; REVOKE SELECT, INSERT, DELETE ON表名 FROM 用户名1, 用户名2;