oracle数据库,实例名和数据库是一一对应的,oracle服务端可以启动多个实例,对应于多个数据库。
数据库可以通过sqlplus / as sysdba 进入默认SID的实例,
查看当前的实例名:select * from v$instance;
切换进入其他实例,只需要export ORACLE_SID= sidname(实例名),再sqlplus / as sysdba 进入即可。
数据库已经存在的情况下,才存在用户和用户可以访问的表空间,即数据存储的表结构文件。
一,oracle TNS listener相关:
查看监听器状态:
lsnrctl status
启动:
lsnrctl start
关闭:
lsnrctl stop
修改监听文件的端口,用于网络客户端链接:
vi /u01/app/oracle/product/11.2.0/network/admin/listener.ora
修改内容(HOST = 10.116.4.63)(PORT = 1521)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.116.4.63)(PORT = 1521))
# (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
修改listener的SID映射文件:
vi /u01/app/oracle/product/11.2.0/network/admin/tnsnames.ora
添加SID是jjccbdb的实例名:
jjccbdb =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.116.4.63)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = jjccbdb)
)
)
二,oracle 创建/删除实例库的步骤
1、使用dbca工具静默建库
dbca -silent -createdatabase -templatename testdb -sid $dbname -gdbname $dbname -datafileDestination $dest -syspassword oracle -systempassword oracle
-characterset $langu -redoLogFileSize 512 -storageType FS -emConfiguration NONE -memoryPercentage 30 -totalMemory $mem -automaticMemoryManagement true
2、使用dbca工具删库
现有实例名:SRPSDB
dbca -silent -deleteDatabase -sourcedb SRPSDB -sid SRPSDB -sysDBAUserName sys -sysDBAPassword oracle
3、创建实例之后,设置表空间和用户访问权限
Create temporary tablespace srpsdb_tmp tempfile '/u01/app/oracle/oradata/SRPSDB/srpsdb_tmp.dbf' size 10240m autoextend on next 1024m maxsize 10240m extent management local;
create tablespace srpsdb logging datafile '/u01/app/oracle/oradata/SRPSDB/srpsdb.dbf' size 10240m autoextend on next 1024m maxsize 10240m extent management local;
Create temporary tablespace srpsdb_tmp tempfile '/u01/app/oracle/oradata/jjccbdb/srpsdb_tmp.dbf' size 10240m autoextend on next 1024m maxsize 10240m extent management local;
create tablespace srpsdb logging datafile '/u01/app/oracle/oradata/jjccbdb/srpsdb.dbf' size 10240m autoextend on next 1024m maxsize 10240m extent management local;
4、赋权用户的访问表空间
create user C identified by 123456 default tablespace srpsdb temporary tablespace srpsdb_tmp;
create user P identified by 123456 default tablespace srpsdb temporary tablespace srpsdb_tmp;
create user M identified by 123456 default tablespace srpsdb temporary tablespace srpsdb_tmp;
5、给用户赋予角色
grant DBA to C;
grant DBA to P;
grant DBA to M;
--------------
三,常用的oracle 查看用户表及权限相关
oracle中用户权限分为系统权限和用户表权限:
查看当前用户表级权限权限:
select * from user_tab_privs;
查看当前用户拥有的系统权限:
select * from user_sys_privs;
查看当前用户下的表:
select * from user_tables;
查看某用户的权限:
select * from dba_sys_privs where grantee='M';
查看用户的角色,限定当前查询用户是dba的前提下:
select * from dba_role_privs where grantee='P';
查看当前用户的表空间:
select username,default_tablespace from user_users;
进dba角色查看:
1、sqlplus / as sysdba
2、 select owner,table_name from dba_tables where table_name='ABM_ACCOUNT';
四,oracle的jdbc链接地址:jdbc:oracle:thin:@10.116.4.125:1521:SRPSDB(实例名)