oracle随笔

Oracle新建数据库(新用户)

1.首先,创建(新)用户:
create user username identified by password;
username:新用户名的用户名
password: 新用户的密码
也可以不创建新用户,而仍然用以前的用户,如:继续利用scott用户

2.创建表空间:
create tablespace tablespacename datafile 'd:data.dbf' size xxxm;
tablespacename:表空间的名字
d:data.dbf':表空间的存储位置
xxx表空间的大小,m单位为兆(M)
3.将空间分配给用户:
alter user username default tablespace tablespacename;
将名字为tablespacename的表空间分配给username

4.给用户授权:
grant create session,create table,unlimited tablespace to username;

5.然后再以楼主自己创建的用户登录,登录之后创建表即可。
conn username/password;

如果SQL*Plus工具启动在服务器上,并且服务器上只有一个数据库实例的情况下,连接字符串可以缺省,在连接字符串中包括连接服务器的协议,服务器的地址,服务器的端口等设置,Oracle服务名等,该配置文件在Oracle安装目录下的:network/ADMIN/tnsnames.ora

运行cmd命令行

  录入 sqlplus /nolog  无用户名登录

        conn /as sysdba  连接到数据本地数据

        alter user system identified by password;   修改System 密码  为password

或者打开sqlplus软件:

窗口用户名录入:/nolog

  

D:oracleora92in>sqlplus /nolog

SQL*Plus: Release 9.2.0.1.0 - Production on 星期四 8月 16 11:32:22 2007

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

SQL> conn /as sysdba
已连接。
SQL> alter user system identified by password;

用户已更改。

SQL> alter user sys identified by password;

用户已更改。

SQL> alter user system identified by manger;

解锁方法
 alter user system account unlock;

 

这样密码修改成功了

Oracle 创建普通用户,并赋予权限

    1. 采用sys or system / manager as sysdba; 连接数据库

    2. 创建普通用户konglin: create user konglin identified by pwd_oracle;

      删除用户, drop user konglin;

    3. 授予用户登录数据库的权限: grant create session to konglin;

    4. 授予用户操作表空间的权限:


      grant unlimited tablespace to konglin;

      grant create tablespace to konglin;

      grant alter tablespace to konglin;

      grant drop tablespace to konglin;

      grant manage tablespace to konglin;

    5. 授予用户操作表的权限:


      grant create table to konglin; (包含有create index权限, alter table, drop table权限)

    6. 授予用户操作视图的权限:

      grant create view to konglin; (包含有alter view, drop view权限)

    7. 授予用户操作触发器的权限:

      grant create trigger to konglin; (包含有alter trigger, drop trigger权限)

    8. 授予用户操作存储过程的权限:

      grant create procedure to konglin;(包含有alter procedure, drop procedure 和function 以及 package权限)

    9. 授予用户操作序列的权限:

      grant create sequence to konglin; (包含有创建、修改、删除以及选择序列)

    10. 授予用户回退段权限:

      grant create rollback segment to konglin;

      grant alter rollback segment to konglin;

      grant drop rollback segment to konglin;

    11. 授予用户同义词权限:

      grant create synonym to konglin;(包含drop synonym权限)

      grant create public synonym to konglin;

      grant drop public synonym to konglin;

    12. 授予用户关于用户的权限:

      grant create user to konglin;

      grant alter user to konglin;

      grant become user to konglin;

      grant drop user to konglin;

    13. 授予用户关于角色的权限:

      grant create role to konglin;

    14. 授予用户操作概要文件的权限

      grant create profile to konglin;

      grant alter profile to konglin;

      grant drop profile to konglin;

    15. 允许从sys用户所拥有的数据字典表中进行选择

      grant select any dictionary to konglin;

    16. 权限:

        create session

        create table

        unlimited tablespace

        connect

        resource

        dba

        例:

        #sqlplus /nolog

        SQL> conn / as sysdba;

        SQL>create user username identified by password

        SQL> grant dba to username;

        SQL> conn username/password

        SQL> select * from user_sys_privs;

        我们将从创建Oracle用户权限表开始谈起,然后讲解登陆等一般性动作,使大家对Oracle用户权限表有个深入的了解。

        一、创建

        sys;//系统管理员,拥有最高权限

        system;//本地管理员,次高权限

        scott;//普通用户,密码默认为tiger,默认未解锁

        二、登陆

        sqlplus / as sysdba;//登陆sys帐户

        sqlplus sys as sysdba;//同上

        sqlplus scott/tiger;//登陆普通用户scott

        三、管理用户

        create user zhangsan;//在管理员帐户下,创建用户zhangsan

        alert user scott identified by tiger;//修改密码

        四,授予权限

        1、默认的普通用户scott默认未解锁,不能进行那个使用,新建的用户也没有任何权限,必须授予权限

        

        grant create session to zhangsan;//授予zhangsan用户创建session的权限,即登陆权限

        grant unlimited tablespace to zhangsan;//授予zhangsan用户使用表空间的权限

        grant create table to zhangsan;//授予创建表的权限

        grante drop table to zhangsan;//授予删除表的权限

        grant insert table to zhangsan;//插入表的权限

        grant update table to zhangsan;//修改表的权限

        grant all to public;//这条比较重要,授予所有权限(all)给所有用户(public)

        2、oralce对权限管理比较严谨,普通用户之间也是默认不能互相访问的,需要互相授权

        

        grant select on tablename to zhangsan;//授予zhangsan用户查看指定表的权限

        grant drop on tablename to zhangsan;//授予删除表的权限

        grant insert on tablename to zhangsan;//授予插入的权限

        grant update on tablename to zhangsan;//授予修改表的权限

        grant insert(id) on tablename to zhangsan;

        grant update(id) on tablename to zhangsan;//授予对指定表特定字段的插入和修改权限,注意,只能是insert和update

        grant alert all table to zhangsan;//授予zhangsan用户alert任意表的权限

        五、撤销权限

        基本语法同grant,关键字为revoke

        六、查看权限

        select * from user_sys_privs;//查看当前用户所有权限

        select * from user_tab_privs;//查看所用用户对表的权限

        七、操作表的用户的表

        

        select * from zhangsan.tablename

        八、权限传递

        即用户A将权限授予B,B可以将操作的权限再授予C,命令如下:

        grant alert table on tablename to zhangsan with admin option;//关键字 with admin option

        grant alert table on tablename to zhangsan with grant option;//关键字 with grant option效果和admin类似

        九、角色

        角色即权限的集合,可以把一个角色授予给用户

        create role myrole;//创建角色

        grant create session to myrole;//将创建session的权限授予myrole

        grant myrole to zhangsan;//授予zhangsan用户myrole的角色

        drop role myrole;删除角色

原文地址:https://www.cnblogs.com/raorao1994/p/6370579.html