1 概述
学习使用Oracle数据库或者作为一个Oracle数据库dba,主要也就是做以下几件事:
1) 安装和升级Oracle数据库。
2) 建库、表空间、表、视图、索引……
3) 指定并实施备份与恢复计划。
4) 数据库权限管理,调优,故障排除。
5) 对于高级数据库管理员,要求能参与项目开发,会编写Sql语句,存储过程,触发器,规则,约束,包。
2 安装
至于Oracle数据库的安装,这里不详细描述,推荐的做法是:先安装Oracle数据库管理软件(不自动创建全局数据库以及SID,后面手动创建)->创建数据库->本地服务名配置 ->监听程序配置->TNSPING测试本地服务以及监听->重启计算机。
3 常用命令
1)用户管理
明白角色和权限,对用户进行管理。角色包含权限,是一组用户角色的组合,打个简单的比方,赋予某个用户一个角色,则该用户具有该角色相关权限。权限指用户操作访问
数据库的权限。
预定义角色:CONNECT, RESOURCE, DBA(用于数据库管理);DELETE_CATALOG_ROLE, EXECUTE_CATALOG_ROLE, SELECT_CATALOG_ROLE(访问数据字典视图和包);
EXP_FULL_DATABASE, IMP_FULL_DATABASE(用于数据导入导出工具的使用);AQ_USER_ROLE, AQ_ADMINISTRATOR_ROLE(高级查询功能)......
常用命令:sql>select * from role_sys_privs where role='角色名'; --查看角色包含的权限
sql>create role role1; --建一个角色
sql>grant create any table,create procedure to role1; --授权给角色
sql>grant role1 to user1; --授予角色给用户
sql>select * from role_sys_privs; --查看角色所包含的权限
sql>create role role1 identified by password1; --创建带有口令以角色(在生效带有口令的角色时必须提供口令)
sql>alter role role1 not identified; --修改角色:是否需要口令
sql>alter role role1 identified by password1;
sql>drop role role1; --删除角色
权限:dba,resource,connect(系统权限,对于普通用户授予resourc,connect则可,管理员则全部);select, update, insert, alter, index, delete, all //all包括所
有权限execute //执行存储过程权限(实体权限)
常用命令:SQL> grant connect, resource, dba to 用户名1 [,用户名2]...
SQL> grant connect, resorce to user50 with admin option; --可以传递所获系统权限。
SQL> Revoke connect, resource from user50; --系统权限回收
SQL> grant select, update, insert on product to user02; --授予实体权限
SQL> grant select, update on product to user02 with grant option; --user02得到权限,并可以传递。
SQL>Revoke select, update on product from user02; --传递的权限将全部丢失。
用户:
常用命令:--创建用户的Profile文件
SQL> create profile student limit // student为资源文件名
FAILED_LOGIN_ATTEMPTS 3 //指定锁定用户的登录失败次数
PASSWORD_LOCK_TIME 5 //指定用户被锁定天数
PASSWORD_LIFE_TIME 30 //指定口令可用天数
--创建用户
SQL> Create User username
Identified by password
Default Tablespace tablespace
Temporary Tablespace tablespace
Profile profile
Quota integer/unlimited on tablespace;
--修改用户
SQL> Alter User 用户名
Identified by 口令
Default Tablespace tablespace
Temporary Tablespace tablespace
Profile profile
Quota integer/unlimited on tablespace;
例:SQL> Create user acc01
identified by acc01 // 如果密码是数字,请用双引号括起来
default tablespace account
temporary tablespace temp
profile default
quota 50m on account;
SQL> grant connect, resource to acc01;
--查询用户缺省表空间、临时表空间
SQL> select username, default_tablespace, temporary_tablespace from dba_users;
--查询系统资源文件名:
SQL> select * from dba_profiles;
--资源文件类似表,一旦创建就会保存在数据库中。
SQL> select username, profile, default_tablespace, temporary_tablespace from dba_users;
SQL> create profile common limit
failed_login_attempts 5
idle_time 5;
SQL> Alter user acc01 profile common;
2)进程与会话
常用命令:--查看最大会话上限
sql>show parameter v$session;
--查看创建的会话
sql>select * from v$session;
--查看最大进程上限
sql>show parameter v$processes;
--查看链接的进程
sql>select * from v$process;
--查看当前数据库DBLINK最多可打开的连接数量
sql>show parameters open_links;
当连接池达到上限时,则需要修改进程上限和会话上限。
常用命令:--修改数据库最大会话数量
sql>alter system set processes=500 scope=spfile (在命令模式下执行)
3)sql操作
这里指的就是我们通常所说的增删改查,也就是对表、视图的操作。
命令:sql>create table tablename{
id int,
...
);
sql>alter table tablename add constraint pkname primary key (ziduan);
sql>insert into table(id,name) values(value,vale);
sql>select * from tablename;
sql>update tablenam id=vlue;
学习使用Oracle数据库或者作为一个Oracle数据库dba,主要也就是做以下几件事:
1) 安装和升级Oracle数据库。
2) 建库、表空间、表、视图、索引……
3) 指定并实施备份与恢复计划。
4) 数据库权限管理,调优,故障排除。
5) 对于高级数据库管理员,要求能参与项目开发,会编写Sql语句,存储过程,触发器,规则,约束,包。
2 安装
至于Oracle数据库的安装,这里不详细描述,推荐的做法是:先安装Oracle数据库管理软件(不自动创建全局数据库以及SID,后面手动创建)->创建数据库->本地服务名配置 ->监听程序配置->TNSPING测试本地服务以及监听->重启计算机。
3 常用命令
1)用户管理
明白角色和权限,对用户进行管理。角色包含权限,是一组用户角色的组合,打个简单的比方,赋予某个用户一个角色,则该用户具有该角色相关权限。权限指用户操作访问
数据库的权限。
预定义角色:CONNECT, RESOURCE, DBA(用于数据库管理);DELETE_CATALOG_ROLE, EXECUTE_CATALOG_ROLE, SELECT_CATALOG_ROLE(访问数据字典视图和包);
EXP_FULL_DATABASE, IMP_FULL_DATABASE(用于数据导入导出工具的使用);AQ_USER_ROLE, AQ_ADMINISTRATOR_ROLE(高级查询功能)......
常用命令:sql>select * from role_sys_privs where role='角色名'; --查看角色包含的权限
sql>create role role1; --建一个角色
sql>grant create any table,create procedure to role1; --授权给角色
sql>grant role1 to user1; --授予角色给用户
sql>select * from role_sys_privs; --查看角色所包含的权限
sql>create role role1 identified by password1; --创建带有口令以角色(在生效带有口令的角色时必须提供口令)
sql>alter role role1 not identified; --修改角色:是否需要口令
sql>alter role role1 identified by password1;
sql>drop role role1; --删除角色
权限:dba,resource,connect(系统权限,对于普通用户授予resourc,connect则可,管理员则全部);select, update, insert, alter, index, delete, all //all包括所
有权限execute //执行存储过程权限(实体权限)
常用命令:SQL> grant connect, resource, dba to 用户名1 [,用户名2]...
SQL> grant connect, resorce to user50 with admin option; --可以传递所获系统权限。
SQL> Revoke connect, resource from user50; --系统权限回收
SQL> grant select, update, insert on product to user02; --授予实体权限
SQL> grant select, update on product to user02 with grant option; --user02得到权限,并可以传递。
SQL>Revoke select, update on product from user02; --传递的权限将全部丢失。
用户:
常用命令:--创建用户的Profile文件
SQL> create profile student limit // student为资源文件名
FAILED_LOGIN_ATTEMPTS 3 //指定锁定用户的登录失败次数
PASSWORD_LOCK_TIME 5 //指定用户被锁定天数
PASSWORD_LIFE_TIME 30 //指定口令可用天数
--创建用户
SQL> Create User username
Identified by password
Default Tablespace tablespace
Temporary Tablespace tablespace
Profile profile
Quota integer/unlimited on tablespace;
--修改用户
SQL> Alter User 用户名
Identified by 口令
Default Tablespace tablespace
Temporary Tablespace tablespace
Profile profile
Quota integer/unlimited on tablespace;
例:SQL> Create user acc01
identified by acc01 // 如果密码是数字,请用双引号括起来
default tablespace account
temporary tablespace temp
profile default
quota 50m on account;
SQL> grant connect, resource to acc01;
--查询用户缺省表空间、临时表空间
SQL> select username, default_tablespace, temporary_tablespace from dba_users;
--查询系统资源文件名:
SQL> select * from dba_profiles;
--资源文件类似表,一旦创建就会保存在数据库中。
SQL> select username, profile, default_tablespace, temporary_tablespace from dba_users;
SQL> create profile common limit
failed_login_attempts 5
idle_time 5;
SQL> Alter user acc01 profile common;
2)进程与会话
常用命令:--查看最大会话上限
sql>show parameter v$session;
--查看创建的会话
sql>select * from v$session;
--查看最大进程上限
sql>show parameter v$processes;
--查看链接的进程
sql>select * from v$process;
--查看当前数据库DBLINK最多可打开的连接数量
sql>show parameters open_links;
当连接池达到上限时,则需要修改进程上限和会话上限。
常用命令:--修改数据库最大会话数量
sql>alter system set processes=500 scope=spfile (在命令模式下执行)
3)sql操作
这里指的就是我们通常所说的增删改查,也就是对表、视图的操作。
命令:sql>create table tablename{
id int,
...
);
sql>alter table tablename add constraint pkname primary key (ziduan);
sql>insert into table(id,name) values(value,vale);
sql>select * from tablename;
sql>update tablenam id=vlue;