# 切换至oracle用户
[root@localhost ~]# su - oracle
# 连接,以 DBA 用户身份登录 SQL*Plus
[oracle@db ~]$ sqlplus / as sysdba
# 查看现有表空间名称及存放路径
SQL> SELECT file_name,tablespace_name FROM dba_data_files;
-- 创建表空间 zf
CREATE TABLESPACE zf
DATAFILE '/u01/oracle/oradata/zf.dbf'
SIZE 100M
AUTOEXTEND ON
NEXT 10M
MAXSIZE 2048M
EXTENT MANAGEMENT LOCAL;
-- 创建用户 zf
CREATE USER zf
IDENTIFIED BY zf123
DEFAULT TABLESPACE zf
TEMPORARY TABLESPACE temp
PROFILE DEFAULT;
-- 授予用户 zf DBA 权限
GRANT DBA TO zf;
-- 授予用户 zf 无限表空间权限
GRANT UNLIMITED TABLESPACE TO zf;
-- 验证表空间和用户创建成功
SELECT tablespace_name, file_name, file_id, bytes / (1024 * 1024) AS "Size (MB)"
FROM dba_data_files
WHERE tablespace_name = 'ZF';
SELECT username, default_tablespace, temporary_tablespace
FROM dba_users
WHERE username = 'ZF';
其他常见操作
select * from dba_data_files;
DROP TABLESPACE V3XUSER INCLUDING CONTENTS AND DATAFILES;
SELECT * FROM dba_users;
DROP USER u1 CASCADE;
创建目录对象
-- 创建目录对象
CREATE DIRECTORY dump_dir AS '/u01/tomcat/webapps/';
-- 授予用户 zf 对目录对象的读写权限
GRANT READ, WRITE ON DIRECTORY dump_dir TO zf;
配置数据源
编辑/u01/tomcat/webapps/zftal-hrm/WEB-INF/classes/subsystem.properties
datasource.url=jdbc:oracle:thin:@192.168.228.129:1521/orcl
datasource.username=zf
datasource.password=zf123
使用 impdp
导入数据
# 打开终端,切换到具有 DBA 权限的用户
sudo su - oracle
# 使用旧版本的导入工具 imp 导入 dmp 文件
imp zf/zf123 file=/u01/tomcat/webapps/hrm_v85.dmp full=y
# expdp 重新导出数据用impdp
impdp 'zf/zf123' directory=DUMP_DIR dumpfile=hrm_v85.dmp table_exists_action=replace