zoukankan      html  css  js  c++  java
  • Oralce常用维护命令

    1. sqlplus远程连接

    方式一:简易连接,不用进行网络配置,其实就是tnsname.ora文件,但只支持oracle10G以上。
    命令:sqlplus 用户名/密码@ip地址[:端口]/service_name [as sysdba]
    示例:sqlplus sys/pwd@ip:1521/test as sysdba
    备注:使用默认1521端口时可省略输入

    方式二:进行网络配置 oracle9i和以前的版本
    2.1图形化操作:Net Configuration Assistant--> 本地Net服务名配置-->添加->服务名->协议(选tcp)->主机名称->端口->完成。

    2.2文本化操作:编辑$ORACLE_HOME/NETWORK/ADMIN/tnsnames.ora文件
    test =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = ip或主机名称)(PORT = 1521))
    )
    (CONNECT_DATA =
    (SERVICE_NAME = 数据库的服务名称)
    )
    )

    2. exp,imp导入导出

    数据导出:
    1 将数据库TEST完全导出,用户名system 密码manager 导出到D:daochu.dmp中
    exp system/manager@TEST file=d:daochu.dmp full=y
    2 将数据库中system用户与sys用户的表导出
    exp system/manager@TEST file=d:daochu.dmp owner=(system,sys)
    3 将数据库中的表inner_notify、notify_staff_relat导出
    exp aichannel/aichannel@TESTDB2 file= d:datanewsmgnt.dmp tables=(inner_notify,notify_staff_relat)
    4 将数据库中的表table1中的字段filed1以"00"打头的数据导出
    exp system/manager@TEST file=d:daochu.dmp tables=(table1) query=" where filed1 like '00%'"

    上面是常用的导出,对于压缩,既用winzip把dmp文件可以很好的压缩。
    也可以在上面命令后面 加上 compress=y 来实现。

    数据的导入
    1 将D:daochu.dmp 中的数据导入 TEST数据库中。
    imp system/manager@TEST file=d:daochu.dmp
    imp aichannel/aichannel@TEST full=y file=d:datanewsmgnt.dmp ignore=y
    上面可能有点问题,因为有的表已经存在,然后它就报错,对该表就不进行导入。
    在后面加上 ignore=y 就可以了。
    2 将d:daochu.dmp中的表table1 导入
    imp system/manager@TEST file=d:daochu.dmp tables=(table1) 

    3. expdp,impdp导入导出

    使用EXPDP和IMPDP时应该注意的事项:

    EXP和IMP是客户端工具程序,它们既可以在客户端使用,也可以在服务端使用。

    EXPDP和IMPDP是服务端的工具程序,他们只能在ORACLE服务端使用,不能在客户端使用。

    IMP只适用于EXP导出的文件,不适用于EXPDP导出文件;IMPDP只适用于EXPDP导出的文件,而不适用于EXP导出文件。

    expdp或impdp命令时,可暂不指出用户名/密码@实例名 as 身份,然后根据提示再输入,如:

    expdp schemas=scott dumpfile=expdp.dmp DIRECTORY=dpdata1;

    一、创建逻辑目录,该命令不会在操作系统创建真正的目录,最好以system等管理员创建。

    create directory dpdata1 as 'd: estdump';

    二、查看管理理员目录(同时查看操作系统是否存在,因为Oracle并不关心该目录是否存在,如果不存在,则出错)

    select * from dba_directories;

    三、给scott用户赋予在指定目录的操作权限,最好以system等管理员赋予。

    grant read,write on directory dpdata1 to scott;

    四、导出数据

    1)按用户导
    
    expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp DIRECTORY=dpdata1;
    
    2)并行进程parallel
    
    expdp scott/tiger@orcl directory=dpdata1 dumpfile=scott3.dmp parallel=40 job_name=scott3
    
    3)按表名导
    
    expdp scott/tiger@orcl TABLES=emp,dept dumpfile=expdp.dmp DIRECTORY=dpdata1;
    
    4)按查询条件导
    
    expdp scott/tiger@orcl directory=dpdata1 dumpfile=expdp.dmp Tables=emp query='WHERE deptno=20';
    
    5)按表空间导
    
    expdp system/manager DIRECTORY=dpdata1 DUMPFILE=tablespace.dmp TABLESPACES=temp,example;
    
    6)导整个数据库
    
    expdp system/manager DIRECTORY=dpdata1 DUMPFILE=full.dmp FULL=y;

    五、还原数据

    1)导到指定用户下
    
    impdp scott/tiger DIRECTORY=dpdata1 DUMPFILE=expdp.dmp SCHEMAS=scott;
    
    2)改变表的owner
    
    impdp system/manager DIRECTORY=dpdata1 DUMPFILE=expdp.dmp TABLES=scott.dept REMAP_SCHEMA=scott:system;
    
    3)导入表空间
    
    impdp system/manager DIRECTORY=dpdata1 DUMPFILE=tablespace.dmp TABLESPACES=example;
    
    4)导入数据库
    
    impdb system/manager DIRECTORY=dump_dir DUMPFILE=full.dmp FULL=y;
    
    5)追加数据
    
    impdp system/manager DIRECTORY=dpdata1 DUMPFILE=expdp.dmp SCHEMAS=system TABLE_EXISTS_ACTION

    4. 表空间及用户

    --创建数据表空间:test
      

    create tablespace test
      datafile 'D:	est	est.dbf' size 30G
      autoextend on
      next 512M; 

    --创建索引表空间:test_index 

     create tablespace test_index
      datafile 'D:	est	est_index.dbf' size 5G
      autoextend on
      next 100M;

    --创建用户  

    create user user1 identified by user1 default tablespace test temporary tablespace temp;

    --用户授权  

    Grant create any synonym,select any table, update any table, insert any table, delete any table,create any view,unlimited tablespace,connect,resource,dba to user1;
  • 相关阅读:
    Serveral effective linux commands
    Amber learning note A8: Loop Dynamics of the HIV-1 Integrase Core Domain
    amber初学……
    anaconda使用
    python中的一些语法
    python中的OOP
    python中的模块
    将python程序打包成exe
    python-执行过程
    python基础
  • 原文地址:https://www.cnblogs.com/jmax/p/3518422.html
Copyright © 2011-2022 走看看