oracle用户管理以及网络连接配置

创建普通用户(需要具有dba权限的用户才能操作,比如system,sys)
create user xiaoming identified by m123;
grant create session to xiaoming;
oracle刚刚创建的用户是没有任何权限,需要管理员给用户分配相应的权限,才能登录,比如我们给 shunping create session


password 用户名

alter user 用户名 identified by 新密码;

创建用户(细节)
例子:sql>create user shunping identified by m123
               default tablespace users
               temporary tablespace temp
               quota 3m on users;


where 子句的作用是在对查询结果进行分组前,将不符合where条件的行去掉,即在分组之前过滤数据,条件中不能包含聚组函数,使用where条件显示特定的行。

having 子句的作用是筛选满足条件的组,即在分组之后过滤数据,条件中经常包含聚组函数,使用having 条件显示特定的组,也可以使用多个分组标准进行分组。

oracle创建用户,赋予权限/角色,撤销权限,权限转移,删除用户等操作(sqlplus)
conn system/abc;
create user xiaohong identified by m123
grant connect to xiaohong;
grant resource to xiaohong; //
grant dba to xiaoming;      //数据库管理员角色,一般不给
connect xiaohong/m123;
password xiaohong;

create table users(id number);
insert into users values(1);
select * from users;

conn system/abc;
revoke connect from xiaohong;
revoke resource from xiaohong;
drop user xiaohong cascade;


题目:让xiaohong用户可以去查scott的emp表
步骤:1.先用scott登录 conn scott/tiger
      2.赋权限 grant select[update|delete|insert|all] on emp to xiaohong;


权限转移 scott->xiaohong->stu
conn scott/tiger;
grant select on emp to xiaohong with grant option;
conn xiaohong/xiaohong;
grant select on scott.emp to stu;
系统权限:with admin option
对象权限:with grant option
revoke select on scott.emp from stu;
conn system/abc;
drop user stu;
drop user xiaohong cascade;

口令管理

create profile 文件名1 limit failed_login_attempts 3 password_lock_time 2;//密码输错3次,将会锁定2天
alter user 用户名 profile 文件名1

给用户解锁:alter user 用户名 account unlock;

终止口令
需求:说一个帐号,最多10,宽限为2天,到时必须设置新的密码
create profile 文件名2 limit password_life_time 10 password_grace_time 2;
alter user 用户名 profile 文件名2;


删除profile:drop profile 文件名 //删除profile文件后,对用户的限制也将失效

 

oracle数据库的启动流程(cmd)
lsnrctl start //启动监听
oradim -startup-sid orcl
TNSLSNR start
tnslsnr start
systeminfo //查看windows系统信息

--oracle创建表空间

/*分为四步 */
 
/*第1步:创建临时表空间  */
 
create temporary tablespace user_temp 
 
tempfile 'D:\oracle\oradata\Oracle9i\user_temp.dbf'
 
size 50m 
 
autoextend on 
 
next 50m maxsize 20480m 
 
extent management local; 
 
 
 
/*第2步:创建数据表空间  */
 
create tablespace user_data 
 
logging 
 
datafile 'D:\oracle\oradata\Oracle9i\user_data.dbf'
 
size 50m 
 
autoextend on 
 
next 50m maxsize 20480m 
 
extent management local; 
 
 
 
/*第3步:创建用户并指定表空间  */
 
create user username identified by password 
 
default tablespace user_data 
 
temporary tablespace user_temp; 
 
 
 
/*第4步:给用户授予权限  */
grant connect,resource,dba to username; 

--结束---

将scott用户下的所有表导入到指定的用户目录下(cmd命令输入)
exp scott/tiger@orcl file=E:\dataImpExp\scott01.dmp log=E:\dataImpExp\scott01.log

导入和导出oracle数据库表所使用到的命令分别是EXP和IMP。要想更加清晰地明白EXP和IMP的使用方法,可以在cmd命令行下敲入“EXP -HELP”和“IMP -HELP”进行查询,查询结果如下图所示:

接下来,进行的操作是将scott用户下的所有表导入到指定的用户目录下:
数据库表导出:EXP SCOTT/TIGGER(scott用户的密码)@INSTANCE NAME(数据库名称/实例名) FILE=D:\SCOTT01.DMP(导出文件存储的路径和名称) LOG=D:\SCOTT01.LOG(导出时的日志文件存储的路径和名称)
PS:如果在上面的操作中出现scott用户被锁定的情况,首先需要对scott用户进行解锁操作。这需要用管理员用户登录,然后执行ALTER USER SCOTT ACCOUNT UNLOCK命令即可。有些时候,可能会遇到用户密码过期的现象,这个时候就需要重新修改一下用户密码。

数据库表导入:IMP 导入用户的用户名/导入用户的密码@INSTANCE NAME(数据库名称/实例名) FILE=D:\SCOTT01.DMP(源数据表文件存储的路径和名称) LOG=D:\IMPSCOTT01.LOG(导入时的日志文件存储的路径和名称)FROMUSER=SCOTT TOUSER=导入的用户名

导入数据(在命令提示符窗口)
imp test/test@orcl
BUFFER=64000
file=D:\test.dmp(dmp文件所在位置)
FULL=y(FULL和TABLES是两种导入模式,TABLES可以只导入部分表,TABLES=(tab1,tab2,...))
COMMIT=y  IGNORE=y  LOG=test.log


三种标准角色
1. connect role(连接角色)
 
 
  临时用户,特别是那些不需要建表的用户,通常只赋予他们connectrole。connect是使用oracle的简单权限,这种权限只有在对其他用户的表有访问权时,包括select、insert、update和delete等,才会变得有意义。拥有connect role的用户还能够创建表、视图、序列(sequence)、簇(cluster)、同义词(synonym )、会话(session)和与其他数据库的链(link)。
 
 
 
  2. resource role(资源角色)
 
 
 
  更可靠和正式的数据库用户可以授予resource role。resource提供给用户另外的权限以创建他们自己的表、序列、过程(procedure)、触发器(trigger)、索引(index)和簇(cluster)。
 
 
 
  3. dba role(数据库管理员角色)
 
 
 
  dba role拥有所有的系统权限----包括无限制的空间限额和给其他用户授予各种权限的能力。system由dba用户拥有。


----------------表空间sql语句示例说明-------------
drop user first1 cascade;
drop tablespace firstspace including contents and datafiles --cascade onstraints;

create tablespace firstspace
logging
datafile 'D:\oracle\Mytablespace\firstspace.dbf'
size 32m
autoextend on
next 32m maxsize 32m
extent management local;

create user first1 identified by first1
default tablespace firstspace;


grant connect,resource,dba to first1;

--设置后,就可以用imp导入数据,数据将会进入指定的firstspace表空间
revoke unlimited tablespace from first1;--撤销此权限
alter user first1 quota 0 on system;--将用户在System表空间的配额置为0
alter user first1 quota unlimited on firstspace;--设置在用户在firstspace表空间配额不受限


select T.OWNER 用户名,T.TABLE_NAME 表名,t.TABLESPACE_NAME 表空间名 From dba_tables t Where t.OWNER = 'FIRST1';

--新账户下测试
create table tb_test1(
name varchar2(10)
)
select * from tb_test1;
----------------表空间sql语句示例说明结束-------------


---------------创建表空间、账户常用语句---------
create temporary tablespace my_temp
tempfile 'D:\oracle\Mytablespace\my_temp.dbf'
size 50M
autoextend on 
next 50M maxsize 1024M 
extent management local; 
--------------------------
create tablespace payment 
logging 
datafile 'D:\oracle\Mytablespace\payment.dbf'
size 50M 
autoextend on 
next 50M maxsize unlimited 
extent management local; 

create user payment identified by payment
default tablespace payment
temporary tablespace my_temp;

grant connect,resource,dba to payment;

revoke unlimited tablespace from payment;
alter user payment quota 0 on system;
alter user payment quota unlimited on payment;
---------------创建表空间、账户常用语句end---------

--查看用户下所有的表,及其表所在的表空间等信息(实用)
select * from user_tables;

--删除用户的所有对象,并删除表空间(通常是一个用户对应一个表空间)
drop user payment cascade;
drop tablespace payment including contents --and datafiles;

--查看用户的解锁状态
select username,account_status from dba_users;

--给scott用户解锁
alter user scott account unlock;

--给scott用户赋予新口令(当scott用户的状态是expired时可以输入这样的命令)
alter user scott identified by tiger;


--------PL/SQL Command Window的使用----------------
SQL> @f:\a.sql
---------------------------------------------------

PL/SQL登录
192.168.1.101/ORCL

--数据库配置文件路径
D:\oracle\product\10.2.0\db_1\NETWORK\ADMIN\tnsnames.ora

--oracle会话解锁(DBA权限)
select * from v$locked_object ;
select object_name, object_type from dba_objects where object_id=166929;
select sid, serial#, machine, program from v$session where sid in (628,632);
alter system kill session '632,611';

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值