Linux新建Oracle用户和数据库及用PL/SQL连接该数据库

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013456370/article/details/87918870

CREATE TABLESPACE zs2019 LOGGING DATAFILE '/software/oracle/app/oradata/orcl/zs2019.dbf' 
SIZE 100M AUTOEXTEND ON NEXT 32M MAXSIZE 500M EXTENT MANAGEMENT LOCAL;


create temporary tablespace zs2019_temp tempfile '/software/oracle/app/oradata/orcl/zs2019_temp.dbf'
size 100m autoextend on next 32m maxsize 500m extent management local;

create user zs identified by 123456 default tablespace zs2019 temporary tablespace zs2019_temp;


grant connect,resource to zs;

alter user zs account unlock;

创建完成,可以通过PL/SQL连接数据库;

报错请参考:https://blog.csdn.net/u013456370/article/details/87918253  PL/SQL连接虚拟机中的oracle数据库

参考链接内容:

1、切换到Oracle用户

su – oracle

2、登录sys用户

sqlplus / as sysdba

3、创建表空间

查询用户表空间文件的路径

select name from v$datafile;

CREATE TABLESPACE customerchat LOGGING DATAFILE '/database/app/oracle/oradata/ccorcl/customerchat.dbf' 
SIZE 100M AUTOEXTEND ON NEXT 32M MAXSIZE 500M EXTENT MANAGEMENT LOCAL;
 

4、创建临时表空间

select name from v$tempfile;

create temporary tablespace customerchat_temp tempfile '/database/app/oracle/oradata/ccorcl/customerchat_temp.dbf'
size 100m autoextend on next 32m maxsize 500m extent management local;

5、创建用户密码与上面创建的文件形成映射关系

create user customerchat identified by customerchat default tablespace customerchat temporary tablespace customerchat_temp;

6、为用户添加权限

初始建立的用户没有任何权限,不能执行任何数据库操作,因此必须为用户设置权限或者角色。被赋予了某个角色的用户将拥有该角色所具备的权限,常被用到的系统预定义角色:CONNECT、RESOURCE、DBA、EXP_FULL_DATABASE、IMP_FULL_DATABASE。其中,CONNECT、RESOURCE、DBA主要用于数据库管理,数据库管理员需要被授予这三个角色。一般的数据库开发人员,需要被授予CONNECT、RESOURCE角色即可。EXP_FULL_DATABASE、IMP_FULL_DATABASE角色分别用于操作数据库导出、导入相关的操作。为用户授予角色:
grant connect,resource to customerchat;

7、查询已创建的用户

select username from dba_users;
8、修改用户密码:

--将用户的密码设置为123456。
alter user customerchat identified by 123456;
有时用户会处于锁定状态,解锁用户:

alter user customerchat account unlock;

9、删除用户语句:

drop user 用户名 cascade;
--删除空的表空间,但是不包含物理文件
drop tablespace tablespace_name;
--删除非空表空间,但是不包含物理文件
drop tablespace tablespace_name including contents;
--删除空表空间,包含物理文件
drop tablespace tablespace_name including datafiles; 
--删除非空表空间,包含物理文件
drop tablespace tablespace_name including contents and datafiles;
--如果其他表空间中的表有外键等约束关联到了本表空间中的表的字段,就要加上CASCADE CONSTRAINTS
drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;
 

10、登录

sqlplus usernmae/password
报错:

ERROR:
ORA-01045: user CUSTOMERCHAT lacks CREATE SESSION privilege; logon denied

这是因为没有创建会话的权限,可以重新赋创建会话的权限

grant create session to customerchat;

11、查询用户下所有表

SELECT * FROM ALL_TABLES WHERE OWNER= 'CUSTOMERCHAT';
其中用户名必须大写

select * from all_tab_comments 
-- 查询所有用户的表,视图等
select * from user_tab_comments   
-- 查询本用户的表,视图等
select * from all_col_comments 
--查询所有用户的表的列名和注释.
select * from user_col_comments 
-- 查询本用户的表的列名和注释
select * from all_tab_columns 
--查询所有用户的表的列名等信息(详细但是没有备注).
select * from user_tab_columns 
--查询本用户的表的列名等信息(详细但是没有备注).
 

12、Linux使用sqlplus退格

使用Ctrl+Backspace

13、登录新建的customerchat用户导入sql文件

--sqlplus登录:
sqlplus customerchat/customerchat

导入sql文件:@路径名/文件名

报如下错误:

ORA-01031: insufficient privileges

这是因为没有建表的权限

登录dba用户导入

sqlplus / as sysdba

导入sql文件报如下错误:

ORA-01950: no privileges on tablespace 'CUSTOMERCHAT'

这是由于创建表空间时设置了有限的大小,两种方法:

方法1: 授予用户对该表空间的UNLIMITED配额

ALTER USER CUSTOMERCHAT  QUOTA UNLIMITED ON customerchat;
方法2: 重新授权resource角色给用户之后,便可以创建表

GRANT RESOURCE TO CUSTOMERCHAT;
 

猜你喜欢

转载自blog.csdn.net/u013456370/article/details/87918870