• oracle常用管理命令


    启动数据库和监听

    lsnrctl start
    sqlplus /nolog
    conn sys/as sysdba
    startup

     查看当前的实例名

    show parameter instance_name;

    查看当前登陆的用户

    show user;

    修改密码

    修改用户的密码

    password username

    或者:

    conn system/manager
    alter user scott identified by 123456;

    设置显示行的宽度

    show linesize;  --默认是80
    set linesize 100

    设置每页显示的行数

    show pagesize;   --默认是14
    set pageszie 10

    设置字段显示的长度

    col ename for a10;

    创建临时表空间

    create temporary tablespace Tblspace_TEMP TEMPFILE 'D:APPADMINISTRATORORADATAYDEVTblspace_TEMP.DBF' SIZE 32m REUSE 
    AUTOEXTEND ON NEXT  512k  MAXSIZE UNLIMITED;

    创建表空间

    create tablespace LISTP datafile 'D:APPADMINISTRATORORADATAYDEVLISTP.DBF' size 32m reuse autoextend on next 50m maxsize unlimited  default storage(initial 512k next 512k   minextents 1   maxextents unlimited   pctincrease 0);

    删除表空间

    DROP TABLESPACE tablespace_name INCLUDING CONTENTS AND DATAFILES;

    改变表空间的状态

    alter tablespace ZYTP offline;   --脱机
    alter tablespace ZYTP online; --联机
    alter tablespace ZYTP read only; --只读

     拓展表空间

    alter tablespace LISTP 'D:APPADMINISTRATORORADATAYDEVLISTP.DBF' resize 100m;   --增加数据文件的大小
    alter tablespace LISTP add datafile 'D:APPADMINISTRATORORADATAYDEVLISTP1.DBF'  --增加数据文件
    alter tablespace LISTP 'D:APPADMINISTRATORORADATAYDEVLISTP.DBF'  autoextend on next 10m maxsize 500m;  --设置自动增长

    移动数据文件(有时一个磁盘的I/O过于繁忙或者损坏,我们需要移动数据文件)

    --移动回系统表空间的数据文件
    select tablespace_name from dba_data_files where file_name='J:DISK1TEST.DBF';    --查询出表空间的名字
    alter tablespace test offline;      --使表空间脱机
    host move J:DISK1TEST.DBF   J:DISK2TEST.DBF   --在物理上完成移动
    alter tablespace test rename datafile 'J:DISK1TEST.DBF' to 'J:DISK2TEST.DBF';   --从逻辑上移动
    alter tablespace test online;      --使表空间联机
    
    --移动系统表空间,重做日志文件也是相同的步骤
    shutdown immediate   --关闭数据库
    startup mount     --将数据库置为加载状态
    host copy D:appzyoradatamydevSYSTEM01.DBF J:DISK1
    alter database rename file 'D:appzyoradatamydevSYSTEM01.DBF' to 'J:DISK1SYSTEM01.DBF';   
    alter database open;

    创建单列索引

    create index myemp_idx1 on myemp(ename);     --按照ename查找将大大加快

    创建复合索引

    create index myemp_idx2 on myemp(ename,job);   --与(job,ename)是两个不相同的索引

    创建用户

    create user test1 identified by test1 default tablespace LISTP temporary tablespace Tblspace_TEMP;

    删除用户

    drop user user_name cascade;     --如果该用户已经创建了表,就要使用cascade参数

     给用户授权

    数据库权限分为:

         系统权限:用户对数据库的相关权限

      对象权限:用户对其它用户的数据对象操作的权限;数据对象是指:比如视图,表,过程

    grant connect to test1;    --connect其实是预定义角色(还有一种叫自定义角色),包含7种权限,允许用户连接数据库
    grant resource to test1; --允许用户创建表,序列等
    garnt select on scott.emp to test1; --允许test1用户查询scott.emp表,授权的用户位dba或者Scott
    grant all on scott.emp to test1; --把emp表的insert,update,drop,select权限给test1用户
    grant select any table to test1; --授权查询所有用户的表
    grant all on scott.emp to test1 with grant option; --给test1用户授权的同时也给test1用户给其它用户授权这张表的权限,如果test1的权限回收,其它用户也将被回收

     回收权限

    revoke all on scott.emp from test11;    --谁受的权限,就得由谁收回,DBA用户也能代替

    角色

    角色分为自定义角色预定义角色,预定义角色最常见的三个角色是connect,resource和dba,一般的用户具有前两个角色就可以了

    查看角色有哪些权限

    select * from dba_sys_privs where GRANTEE='RESOURCE';     --查看角色所拥有的权限或者一个用户所具有的权限
    select * from dba_role_privs where grantee='SCOTT'      --查看一个用户所具有的角色
    select * from dba_roles;          --查看所有角

    创建自定义角色

    create role myrole not identified;                         --不需要验证的角色,也可以不写,默认的是不要密码的
    grant create session,create view to myrole with admin option; --给角色授权,系统权限,并且可以传递
    grant select on scott.emp to myrole;                     --授予角色对象的权限
    grant select any table,myrole to scott;                   --同时将系统权限和角色赋予scott用户

     

    使用profile管理用户口令

    create profile lock_account limit failed_login_attempts 3 password_lock_time 2;   --尝试3次,锁定2天
    alter user test1 profile lock_account; --test1使用lock_account
    create profile limit_account limit password_life_time 10 password_grace_time 2 password_reuse_time 10; --10天修改密码,宽限两天,10天之内不可重用密码 (默认180天,宽限7天)
    alter user test1 account unlock; --解锁用户
    drop profile lock_account cascade; --删除profile文件,删除后所有的限制将被取消
  • 相关阅读:
    Django学习2
    Django学习1
    python 基于tcp协议的文件传输3_解决粘包问题
    python socketserver
    python hashlib
    python struct模块
    python json 模块
    python socket模块
    13暑假集训#10 总结
    hdu 4493 卡输入输出
  • 原文地址:https://www.cnblogs.com/zydev/p/5248522.html
Copyright © 2020-2023  润新知