Oracle数据库的使用

Oracle数据库的安装
    系统默认创建两个用户:sys 和 system

访问oracle:
    使用oracle自带的sqlplus(前提条件:在path中添加D:\JavaSoft\Oracle\app\oracle\product\11.2.0\server\bin)
    window+R:打开运行窗口
    输入sqlplus 回车
    sys和密码不能直接登录数据库,而system和密码可以
    说明:这种方式只能允许 可以以普通用户身份登录的办法    
    如果想以数据超级管理员(sysdba)的身份登录
    window+R 输入 sqlplus sys/密码 as sysdba; 回车
    
查看当前用户:    show user;


sys可以启动和关闭数据库
system 不行

关闭数据库    shutdown immediate
启动数据库    startup open

数据库用户的操作
    创建用户: create user cry identified by 1;
    用户创建之后默认是被锁住的,并且没有分配任何角色
    
    为用户解锁:    alter user cry account unlock;
    为用户分配角色:    grant connect to cry;
    
    此时,就可以使用cry用户登录数据库
    conn cry/1;
    show user;    
    //使用sysdba身份给用户分配角色
    grant resource to cry;
    这是就可以在当前cry用户下,进行对象操作,
    
    如果需要将某个用户变成超级管理员:
    grant sysdba to cry;
    conn cry/1 as sysdba;
    
    删除用户: 
    drop user cry;
    
    将用户所创建的所有对象全部删除:
    drop user cry cascade;
    
    从用户身上回收sysdba角色
    revoke sysdba from cry;
    
    查找当前用户角色下的所有表名称
    select table_name from user_tables;
    
    CRUD:增删改查
    C:create;
    R:read;
    U:update;
    D:delete;
    
=========================================================================================================================

    表空间 tablespace
    是Oracle数据库中最大的逻辑结构
    从逻辑上说,Oracle数据库是由若干个表空间组成
    
    表空间与数据库的物理结构有着十分密切的关系,他与磁盘上若干个数据文件相对应
    从物理上说,数据库的数据被存放在数据文件中
    从逻辑上说,数据是被存放在表空间中
    一个数据文件只能属于一个表空间,一个表空间可以有多个数据文件
    oracle数据把方案对象(表\视图\索引\序列)逻辑的存储在表空间中
    
    创建临时表空间
    create temporary tablespace
    cry_temp                                    ---表空间名
    tempfile 'D:\JavaLife\oracle\cry_temp.dbf'    ---该路径要真实存在
    size 100m                                    ---初始大小
    autoextend on                                ---开启自动扩展
    next 10m maxsize 1000m                        ---每次扩展大小和最大空间
    
    创建数据表空间文件
    create tablespace
    cry_data                                    ---表空间名
    datafile 'D:\JavaLife\oracle\cry_data.dbf'    ---该路径要真实存在
    size 500m                                    ---初始大小
    autoextend on                                ---开启自动扩展
    next 20m maxsize 2000m                        ---每次扩展大小和最大空间
    
    创建用户并指定表空间
    create user cp identified by 1
    default tablespace cry_data
    temporary tablespace cry_temp;
    
    给用户解锁
    alter user cry account unlock;
    
    给用户授权
    grant connect, resource to cry;
    
    以sysdba角色查询指定用户的表空间名称(username必须大写,并使用单引号)
    select user_id,username, default_tablespace from dba_users where username='CRY';
    
    查询所有表空间的信息
    select tablespace_name, status, allocation_type from dba_tablespaces;
    
    修改表空间名称
    alter tablespace_name cry_data rename to new_cry_data;
    
    删除表空间记录
    drop tablespace cry_data;
    
    删除表空间及表空间文件
    drop tablespace cry_data including contents and datafiles;
    
    =================================================================================================================
    实体(表\视图\索引\序列)权限
    select update, insert,alter,index, delete,all(all 包括所有权限)
    
    
    创建用户cww;
    
    sys给用户cww用户授予select t_test表的权限
    grant select on t_test to cww;
    
    conn cww/1;
    
    //查询该表
    select * from sys.t_test;
    
    给用户授予这张表的所有操作权限
    grant all on t_test to cww;
    
    
    
    create tablespace
    cry_data                                    
    datafile 'D:\JavaLife\oracle\cry_data.dbf'    
    size 500m                                    
    autoextend on                                
    next 20m maxsize 2000m;    
    
 

 

posted @ 2015-10-10 19:23  病了?来串代码吧!  阅读(152)  评论(0编辑  收藏  举报