create tablespace sharedb
select * from dba_data_files; -- 查看表空间适合的物理位置,这里是'E:\app\oradata\'。
datafile 'E:\app\oradata\sharedb.def' size 5000M;
create user sharedb identified by mima;
grant connect,resource,DBA to sharedb;
datafile 'E:\app\oradata\sharedb.def' size 5000M;
create user sharedb identified by mima;
grant connect,resource,DBA to sharedb;
imp sharedb/
mima@orcl file=C:\Users\LIUWEN\Desktop\sharedb.dmp full=y
执行到这里提示出错,首先sharedb.def,应该是sharedb.dbf。不过扩展名应该不影响。只要是创建的用户不在指定的表空间。
重新再来:
直接删除sharedb.def文件。这里将导致数据库未打开的错误,此时tables打不开。可能是这样操作会导致数据库挂起了,禁止你进行任何操作了。
解决方式:
用sys/***作为SYSDBA登录orcl,
执行alter database datafile 'E:\app\oradata\sharedb.def' offline drop;
执行alter database open;
退出重新用sys/***作为SYSDBA登录orcl。此时就能打开tables。
删除sharedb用户,删除sharedb表空间。
执行select username,default_tablespace from user_users;
执行drop user sharedb cascade;
执行DROP TABLESPACE sharedb INCLUDING CONTENTS AND DATAFILES;
如果出错就别直接删除,直接删除用户、表空间就行。即执行上边两句就OK。
select * from all_users ;
select * from dba_data_files;这两句可查看用户与表空间是否已删除
真正的重新开始:
执行
create tablespace sharedb
logging
datafile 'E:\app\oradata\sharedb.dbf' size 5000M
autoextend on
next 200m maxsize 20480m
extent management local;
create user sharedb identified by mima default tablespace sharedb;
grant connect,resource,DBA to sharedb;
一般到这就可以了。不过同样可能出现一些问题:
IMP-00038:无法转换为环境字符集句柄
这里可能的原因可能是导入导出字符集不匹配。我这里就遇到了这个问题,但却不是这个原因。而是导出时用的expdp命令导出的,导入时需要用impdp命令。详情看笔记“expdp / impdp 用法”或
http://www.cnblogs.com/huacw/p/3888807.html。
下面是我执行的过程:
一、创建逻辑目录,该命令不会在操作系统创建真正的目录,最好以system等管理员创建。
create directory dpdata1 as 'C:\Users\LIUWEN\Desktop';
二、查看管理理员目录(同时查看操作系统是否存在,因为Oracle并不关心该目录是否存在,如果不存在,则出错)
select * from dba_directories;
三、给scott用户赋予在指定目录的操作权限,最好以system等管理员赋予。
grant read,write on directory dpdata1 to sharedb;
impdp sharedb/mima DIRECTORY=dpdata1 DUMPFILE=sharedb.dmp SCHEMAS=sharedb;
执行这条语句又给我出幺蛾子了:
ORA-39165: 未找到方案 sys;。
所以我尝试着执行了impdp sharedb/mima DIRECTORY=dpdata1 DUMPFILE=sharedb.dmp;成功导入了。
用户权限:
grant connect to sharedb;
grant resource to sharedb;
grant exp_full_database to sharedb;
grant imp_full_database to sharedb;
grant debug connect session to sharedb;
grant create any view to sharedb;
grant select any table to sharedb;
grant create any table to sharedb;
grant create any index to sharedb;
grant create any sequence to sharedb;
grant execute any procedure to sharedb;
grant unlimited tablespace to sharedb;
下面是完整版第二次
第一次只是经理让我在自己本机上做的练习,第二次是要导入到服务器上。
1、PLSQL远程登录远程数据库:sys/*** as sysdba。
2、删除原来的用户、表空间,当然最好还是实现查看一下。可在Objects的tablespaces与users中查看,也可通过sql。
select username from all_users;
select * from dba_data_files; -- 可查看表空间物理地址与对应的用户。这里可知道表空间物理地址一般放哪,不能乱放啊
drop user sharedb cascade;
drop
TABLESPACE sharedb INCLUDING CONTENTS AND DATAFILES;
3、创建表空间、用户。
由于impdp导入时需要逻辑目录,所以导入操作只能在服务器上了。远程登录服务器,发现没有PLSQL这些,所以只能通过命令行。
cmd进入命令行,sqlplus sys/*** as sysdba。
create tablespace sharedb datafile 'D:\ORACLE11G64\ORADATA\ORCL\SHAREDB.DBF' size 100m autoextend on next 50m;
create user sharedb identified by mima default tablespace sharedb temporary tablespace temp;
grant connect to sharedb;
grant resource to sharedb;
grant exp_full_database to sharedb;
grant imp_full_database to sharedb;
grant debug connect session to sharedb;
grant create any view to sharedb;
grant select any table to sharedb;
grant create any table to sharedb;
grant create any index to sharedb;
grant create any sequence to sharedb;
grant execute any procedure to sharedb;
grant unlimited tablespace to sharedb;
4、导入
cmd进入命令行,impdp sharedb/mima DIRECTORY=dpdata1 DUMPFILE=sharedb.dmp
第三次
create tablespace hbjk datafile 'E:\app\oradata\hbjk.dbf' size 100m autoextend on next 50m;
create user hbjk identified by hbjk default tablespace hbjk;
grant connect,resource,DBA to hbjk;
select * from dba_directories;
grant read,write on directory dpdata1 to hbjk;
imp hbjk/ hbjk@orcl file=C:\Users\LIUWEN\Desktop\hbjk.dmp full=y
create user hbjk identified by hbjk default tablespace hbjk;
grant connect,resource,DBA to hbjk;
select * from dba_directories;
grant read,write on directory dpdata1 to hbjk;
imp hbjk/ hbjk@orcl file=C:\Users\LIUWEN\Desktop\hbjk.dmp full=y