Oracle database create user, tablespace, authorization

Oracle database create user, tablespace, authorization

1. First, log in to oracle as sysdba with user scott

conn scott/tiger as sysdba;

2. Create user eg: cyz

create user cyz identified by "123456";

3. If you want to modify the user password:

alter user cyz identified by cyz21;

4. User unlock

alter user cyz account unlock;

5. Query or delete the tablespace of the current user/system

select username,default_tablespace from user_users;//查询当前表空间
drop tablespace USERS including contents and datafiles cascade constraint;/删除表空间
select username,default_tablespace from dba_users;//查询系统表空间

6. Create a tablespace

create tablespace db_space datafile 'E:\db_space\db_data.dbf' size 200M;

7. Allocate tablespaces to users

alter user cyz default tablespace db_space ;

8. Determine whether the user exists

select username from all_users where username='cyz';

9. Authorization (Single Authorization)

grant create session to cyz;登录权限
grant create table to cyz;建表权限
grant create view to cyz;创建视图权限
grant create connect to cyz
grant resource to cyz
grant all to public;所有权限给所有用户

10. Authorize users as a whole

grant connect ,resource,dba,exp_full_database,imp_full_database to cyz;

Detailed introduction:

The permissions of the connect role are: alter session, create cluster, create database
link, create sequence, create session, create stnonym, create table, create
view; the permissions of the resource role are: create cluster, create indextype, create
operator, create procedure , create sequence, create table, create
trigger, create type; all management rights owned by dba exp_full_database is mainly for exporting user oracle data
imp_full_database is mainly used for importing oracle data

11. Revoke permissions

revoke connect   from cyz;

12. Query the permissions the user has

select * from session_privs;

13. Delete users and related objects

drop user cyz cascade;

14. Relevant operations on tables, fields and types.

create table test
(
id  number not null,
name varchar2(20)
)
alter table test rename to test1;修改表名
alter table test rename column name to name1;修改表列名
alter table test modify (name1 number(20));修改字段类型
alter table test add  status varchar2(50);添加字段status
alter table test drop column status;删除字段status

15. Delete all tables under the user

selectdrop table||table_name||;from cat where table_type='TABLE' order by TABLE_NAME;

16. Data export and import
exp username/password@database instance owner=username file=file storage path

exp cyz/123456@127.0.0.1:1521/orcl owner=cyz file=F:\cyzdb.dmp

import
imp username/password@database fromuser=username touser=username file=d:\cu.dmp ignore=y

imp cyz/123456@127.0.0.1:1521/orcl fromuser=cyz touser=data file=F:\test.dmp ignore=y

Basic syntax and examples:

1. exp: There are three main ways (full, user, table) 1. Full: EXP SYSTEM/MANAGER BUFFER=64000
FILE=C:\FULL.DMP FULL=Y If you want to perform a full export, you must have special permissions 2 , User mode: EXP SONIC/SONIC
BUFFER=64000 FILE=C:\SONIC.DMP OWNER=SONIC All objects of user SONIC are output to the file.
3. Table mode: EXP SONIC/SONIC BUFFER=64000 FILE=C:\SONIC.DMP OWNER=SONIC
TABLES=(SONIC) In this way, the table SONIC of user SONIC will be exported

17. Determine whether the user's table below exists, delete it if it exists, and create it if it does not exist

declare
	num number;
	Begin
		select count(1) into num from all_tables where table_name='DS_TABLE' and owner='data';
	if num=1
	then 
		execute immediate 'drop table DS_TABLE';
	else
		execute immediate 'create table XXXX(id number not null,name varchar(100))';
	end if;
end;

18. Extended content:
18.1 Query oracle version

select version from product_component_version where substr(product, 1, 6) = 'Oracle';

18.2 Query table space size

select sum(bytes) / (1024 * 1024) as free_space, tablespace_name from dba_free_space group by tablespace_name;

18.3 Query table space size, free size, and use size.

select a.tablespace_name tablespace,//查询表空间
        total/(1024*1024) allsize,//查询总大小,单位为Mb
        free/(1024*1024) freesize,//空闲空间大小
        (total-free)/(1024*1024) usedsize,//已使用大小
        total/(1024*1024*1024) Gsize,//查询总大小, 单位为G
        round((total-free)/total,4)*100 usedlv //使用率
        from (select tablespace_name,sum(bytes)free
        from dba_free_space group by tablespace_name) a,
        (select tablespace_name,sum(bytes) total 
        from dba_data_files group by tablespace_name)b
        where a.tablespace_name=b.tablespace_name;

18.4 Modify the connection pool
//Query the number of connections in the connection pool

show parameter processes;

//modify the connection pool

alter system set processes=1000 scope=spfile;

//Query the connection session

show parameter sessions;

//Modify the connection session size

alter system set sessions=1000 scope=spfile;

19. Open and close the database
19.1 Close the database (SHUTDOWN IMMEDIATE)

1)打开cmd,输入sqlplus/nolog,按回车键;2)输入conn/ as sysdba(最高权限)3)shutdown immediate;

19.2, start the database

1)打开cmd,输入sqlplus/nolog,按回车键;2)输入conn/ as sysdba3)startup

20. Query whether the oracle user is connected

select sid,serial#,username from v$session where username=upper('用户名');
  /*
     删除当前连接用户
    */
-- 1、首先切换到 SYSTEM 用户
-- 2、查询用户各进程相对应的 sid、serial#。
      SELECT sid,serial#,username FROM v$session WHERE username = UPPER('TEST1');
-- 3、根据上面的查询结果,将用户占用的所有进程杀掉。
      --注意: sid 与 serial# 是一一对应的
      ALTER SYSTEM KILL SESSION 'xxx, xxx';
-- 4、删除用户
      DROP USER test1 CASCADE;

21. Query the job process, kill the process and query the job serial number

select * from user_jobs;

kill process

exec DBMS_JOB.BROKEN(JOB,true);

start process

exec DBMS_JOB.RUN(JOB)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324353637&siteId=291194637