sqlplus system/orcl_123456@orcl //sqlplus连接
select name from v$database; //查询当前数据库名
select instance_name from v$instance; // 查询当前数据库实例名
//创建临时表空间
CREATE TEMPORARY TABLESPACE OX_TEMP TEMPFILE '/opt/oracle/oradata/orcl/OX_TEMP.DBF'
SIZE 64M
AUTOEXTEND ON
NEXT 64M MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL;
//创建数据表空间
CREATE TABLESPACE OX_DATA
LOGGING
DATAFILE '/opt/oracle/oradata/orcl/OX_DATA.DBF'
SIZE 64M
AUTOEXTEND ON
NEXT 64M MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL;
//创建用户(方案) 并指定表空间
CREATE USER OX IDENTIFIED BY ox_123456
ACCOUNT UNLOCK
DEFAULT TABLESPACE OX_DATA
TEMPORARY TABLESPACE OX_TEMP;
//给用户授权
GRANT CONNECT,RESOURCE TO OX;// 把connect,resource权限授予用户
GRANT DBA TO OX; //把 dba权限授予给用户
---一般用户登录---
sqlplus C##DBADMIN/orcl_admin@orcl;
sqlplus ox/ox_123456@ORCLPDB;
conn ox/ox_123456@orclpdb;
conn C##DBADMIN/orcl_admin@orcl;
--打开PDB数据库--
sqlplus / as sysdba
#查看PDB数据状态
select con_id,name,open_mode from v$pdbs;
alter pluggable database ORCLPDB open;
alter session set container=ORCLPDB;
commit;
--sys dba登陆 开启服务---
# su - oracle
$ lsnrctl status 检查oracle监听器运行状态
$ lsnrctl start / lsnrctl stop
sqlplus / as sysdba
>startup //开启服务 >shutdown immediate; //关闭服务
--oracle 12c 开启pdb数据库--
select CDB from v$database;
show con_name;
select con_id, dbid, guid, name , open_mode from v$pdbs;
alter pluggable database ORCLPDB open;
alter pluggable database all open;
#alter pluggable database PDBORCL close;
alter session set container=ORCLPDB;
#alter session set container=CDB$ROOT;
CREATE TABLESPACE OX
LOGGING
DATAFILE '/u01/app/oracle/oradata/orcl/orclpdb/OX.DBF'
SIZE 64M
AUTOEXTEND ON
NEXT 64M MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL;
CREATE TEMPORARY TABLESPACE OX_TEMP TEMPFILE '/u01/app/oracle/oradata/orcl/orclpdb/OX_TEMP.DBF'
SIZE 64M
AUTOEXTEND ON
NEXT 64M MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL;
CREATE USER OX IDENTIFIED BY ox_123456
ACCOUNT UNLOCK
DEFAULT TABLESPACE OX
TEMPORARY TABLESPACE OX_TEMP;
GRANT CONNECT,RESOURCE TO OX;// 把connect,resource权限授予用户
GRANT DBA TO OX; //把 dba权限授予给用户
jdbc连接oracle12的数据库需要具备的条件:
1、监听成功启用,且tnsping通过(OK (30 毫秒);
2、tnsnames.ora配置正确(连接pdb数据库,注意添加pdb服务项,具体如何配置查看[准备阶段]);
3、 监听连带的相应数据库成功开启;
4、Jdbc连接字符串迭代更新为”jdbc:oracle:thin:@192.168.75.131:1521/pdborcl”而非" jdbc:oracle:thin:@192.168.75.131:1521:pdborcl"
--一个触发器--
conn / as sysdba
CREATE TRIGGER open_all_pdbs
AFTER STARTUP
ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'alter pluggable database all open';
END
open_all_pdbs;
/
--Oracle数据库导出--
exp ox/ox_pwd@ox file=/home/oracle/ox_db.dmp owner=ox rows=n
exp ox/ox_123456@orclpdb file=/home/oracle/db_bak/ox_db.dmp owner=ox rows=n //仅owner=ox导出结构
---重点-----导出owner=ox所有数据对象
exp ox/ox_pwd@ox buffer=10240 file=/home/oracle/ox_db_20190417.dmp log=/home/oracle/ox_db_20190417.log owner=ox //导出owner=ox所有数据对象
--Oracle数据库导入--
sqlplus / as sysdba
select owner, table_name from dba_tables where owner='OX';
alter session set container=orclpdb;
imp ox/ox_123456@orclpdb buffer=10240 file=ox_db.dmp full=y ignore=y;
imp ox/ox_123456@orclpdb buffer=10240 file=ox_db_20190417.dmp full=y ignore=y;
----重点----将fromuser=OX用户的所有数据对象导入到touser=OX---
imp SYSTEM/oracle@orclpdb buffer=102400 file=ox_db_20190417.dmp fromuser=OX touser=OX ignore=y; (不能使用full=y) //将fromuser=OX用户的所有数据对象导入到touser=OX
--删除方案(删除OX2用户及OX2的所有数据)---
drop user OX2 cascade;
来源:oschina
链接:https://my.oschina.net/u/4262067/blog/3216307