zoukankan      html  css  js  c++  java
  • oracle 新建表空间和导入数据

    今天需要布置一个项目使用的是oracle10g数据库,数据库已经建好,但是找不到相关权限的密码,就学习了一下使用putty连接Linux服务器,使用命令行创建表空间,

    记录一下:

    使用root用户登录Linux,首先需要切换到oracle用户

    su - oracle 
    

    之后查看一下oracle的安装目录

    echo $ORACLE_HOME
    

    之后cd进去,在oracle目录下的oradata文件夹新建一个milude文件夹

    mkdir milude

    之后使用无密码dba登录oracle

    sqlplus / as sysdba
    

    先创建临时表空间 milude_temp 

    create temporary tablespace milude_temp tempfile '/opt/oracle/oradata/milude/test_temp01.dbf' size 100m autoextend on next 40m maxsize 2048m extent management local; 

    创建表空间 milude

    create tablespace milude logging datafile '/opt/oracle/oradata/milude/test_data01.dbf' size 100m autoextend on next 40m maxsize 2048m extent management local; 
    

    创建用户名 milude 和密码 miludepwd 

    create user milude identified by miludepwd default tablespace milude temporary tablespace milude_temp; 
    

    对用户 milude 进行授权

    grant dba to milude;
    grant connect,resource to milude;
    grant select any table to milude;
    grant delete any table to milude;
    grant update any table to milude;
    grant insert any table to milude;
    

    之后退出登录就可以导入表结构和表数据

    因为我在服务器上使用plsql导出的dmp文件,而我本地使用的是dbeaver,不支持这个文件格式的导入,只能使用命令行导入
    使用root权限上传到oracle用户目录下
    之后切换到oracle用户并输入

    imp milude/miludepwd file=/home/oracle/expsqlanddata.dmp ignore=y full=y
    

     ps:以下操作没有进行,在网上查到的内容(https://www.cnblogs.com/gzggyy/p/3319315.html

    1查看用户权限

    --查看用户要具备drop tablespace的权限,如果没有,先用更高级的用户(如sys)给予授权
    select a2.username,a1.privilege from dba_sys_privs a1 , user_role_privs a2
    where a1.privilege = 'DROP TABLESPACE'
    and a1.grantee =a2.granted_role
    

    2删除临时表空间

    --查看临时表空间文件
    select name from v$tempfile;
    --查看用户和表空间的关系
    select USERNAME,TEMPORARY_TABLESPACE from DBA_USERS;
    --如果有用户的默认临时表空间是NOTIFYDB_TEMP的话,建议进行更改
    alter user xxx temporary tablespace tempdefault;
    ---设置tempdefault为默认临时表空间
    alter database default temporary tablespace tempdefault;
    --删除表空间NOTIFYDB_TEMP及其包含数据对象以及数据文件
    drop tablespace NOTIFYDB_TEMP including contents and datafiles; 
    

    3删除用户表空

    --查看表空间文件
    select name from v$datafile;
    --停止表空间的在线使用
    alter tablespace 表空间名称 offline;
    --删除表空间NOTIFYDB_TEMP及其包含数据对象以及数据文件
    drop tablespace NOTIFYDB_TEMP including contents and datafiles; 
    

    4其他操作

    --查看所有的用户
    select * from all_users;
    --查看当前用户信息
    select * from user_users;
    --查看当前用户的角色
    select * from user_role_privs;
    --查看当前用户的权限
    select * from user_sys_privs;
    --查看当前用户的表可操作权限
    select * from user_tab_privs;
    
    --查看某一个表的约束,注意表名要 大写
    select * from user_constraints where table_name='TBL_XXX';
    --查看某一个表的所有索引,注意表名要 大写
    select index_name,index_type,status,blevel from user_indexes where table_name = 'TBL_XXX';
    --查看索引的构成,注意表名要 大写
    select table_name,index_name,column_name, column_position FROM user_ind_columns WHERE table_name='TBL_XXX';
    
    --系统数据字典 DBA_TABLESPACES 中记录了关于表空间的详细信息
    select * from sys.dba_tablespaces;
    
    --查看用户序列
    select * from user_sequences;
    --查看数据库序列
    select * from dba_sequences;
    
  • 相关阅读:
    子类构造函数中调用虚函数问题验证
    socks5代理浅识
    关于C++标准库(第2版)std::remove_if的"特性"概述
    动态获取结构体中指定的属性值
    构造和析构函数定义为私有场景
    remove_pointer使用测验
    广播自定义消息实现进程间的通信问题
    遍历窗口权限问题
    嵌入窗口到桌面的问题
    实验一 熟悉实验环境
  • 原文地址:https://www.cnblogs.com/milude0161/p/7890677.html
Copyright © 2011-2022 走看看