Oracle数据库创建表空间用户21-11-25

Posted mingyuewu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle数据库创建表空间用户21-11-25相关的知识,希望对你有一定的参考价值。

Oracle数据库创建表空间、用户

文章目录

1 登录oralce数据库

# sysdba
sqlplus '/ as sysdba'
# 普通用户
conn  xiaoming/"123456"
conn   upp/upp@ip:1521/orcl

2 创建表空间


create  tablespace  ONEPAY   datafile'/data/oracle/oradata/orcl12c/ONEPAY_CORE.dbf'  size 512M
autoextend on next 512M maxsize unlimited extent management local;


create  tablespace  ONEPAY_INDEX   datafile'/data/oracle/oradata/orcl12c/ONEPAY_INDEX.dbf'  size 512M
autoextend on next 512M maxsize unlimited extent management local;

3 创建用户

# 指定用户的默认表空间及第二表空间
create user ONEPAY identified by "123456" default tablespace ONEPAY_CORE profile DEFAULT;
ALTER USER  ONEPAY  QUOTA UNLIMITED ON ONEPAY_INDEX;


#######授权
-- Grant/Revoke role privileges 
grant connect to onepay;
grant dba to onepay;
grant resource to onepay;
-- Grant/Revoke system privileges 
grant create any synonym to onepay;
grant create session to onepay;
grant unlimited tablespace to onepay;

4 授权

grant connect,resource , dba to ONEPAY;
grant create view to ONEPAY;
grant create public synonym to ONEPAY;
grant drop public synonym to ONEPAY;
grant unlimited tablespace to ONEPAY;
grant read,write on directory dir_dump to ONEPAY;

5 查询验证

/* 查用户及其默认表空间*/
select  * from  dba_users;   //DBA用户
select  *  from  dba_tablespaces;
select  *  from  user_users;  //普通用户
select  username,default_tablespace from user_users;   //普通用户
/* 查看.dbf文件 */
select name from v$datafile;  //DBA用户
select * from dba_data_files;  //DBA用户
/* 查看表 */
SELECT * FROM  ALL_TABLES  WHERE  OWNER='ONEPAY';
SELECT table_name FROM user_tables ORDER BY Table_name;
/*查看oralce服务名和SID*/
 select global_name from global_name;  //DBA身份
  select instance_name from v$instance;

6 删除用户和表空间

DROP USER username CASCADE; 

DROP TABLESPACE tablespace-name INCLUDING CONTENTS AND DATAFILES;

7 执行SQL文件

登录到对应用户
@ 路径
@/data/onepay.sql

8 创建表

create table WMY.student_info (
  sno         number(10) constraint pk_si_sno primary key,
  sname       varchar2(10),
  sex         varchar2(4),
  create_date date
);
-- 添加注释
comment on table WMY.student_info is '学生信息表';
comment on column WMY.student_info.sno is '学号';
comment on column WMY.student_info.sname is '姓名';
comment on column WMY.student_info.sex is '性别';
comment on column WMY.student_info.create_date is '创建日期';


insert into WMY.student_info (sno, sname, sex, create_date)
values (1, '张三', '男', sysdate);
insert into WMY.student_info (sno, sname, sex, create_date)
values (2, '李四', '女', sysdate);
insert into WMY.student_info (sno, sname, sex, create_date)
values (3, '王五', '男', sysdate);

9数据泵迁移

//create  select grant 语句在oralce里执行,expdp  impdp在oracle数据库外执行 ,即su - oracle 下执行
/*创建数据导出时存放的目录*/
create directory DIR_DUMP as '/backup/dumpdir';	
/*查看该路径变量是否创建成功*/
select * from dba_directories where DIRECTORY_NAME='DIR_DUMP';   
/*授权*/
grant read, write on directory DIR_DUMP  to upp;
grant exp_full_database,imp_full_database to upp;
// 
/*导出数据*/
expdp username/password@内网IP:1521/orcl   directory=dir_dump  dumpfile=upp-20211201.dmp schemas=upp logfile=exportupp.log compression=ALL
/*在新的机器上导入数据*/
查询是否有dump_dir:
select * from dba_directories;
若没有创建个dump目录,目录名先建:
create directory dump_dir as '/data/oracle/backup';
dmp文件复制到/data/oracle/backup目录。
impdp  username/password  directory=dump_dir  dumpfile=upp20211201.dmp    logfile=upp-20211201.log 

以上是关于Oracle数据库创建表空间用户21-11-25的主要内容,如果未能解决你的问题,请参考以下文章

Oracle数据库创建表空间用户21-11-25

Oracle进阶学习之创建数据库

Oracle进阶学习之创建数据库

oracle以啥用户创建表空间

oracle 创建表空间、创建用户

oracle怎样创建表空间和用户