在网上看了挺多篇使用exp命令和imp命令导入用户的例子,发现都不是很满意。所以我自己通过多次实验,终于得到一个令人满意的方法。
exp导出用户
我们以scott用户为例。
1、打开cmd
2、运行以下命令,生成dmp文件。
exp scott/tiger@Q owner=scott file=C:\Users\win10\Desktop\scott_dmp\scott.dmp
exp username/password@db_name owner=db_name file=存放路径
可以看到在指定路径已经生成了一个dmp文件。该文件不用事先创建,但是要创建该文件的存放路径。
imp导入用户
1、登录system用户,删除scott用户。若scott用户处于连接状态,是不能删除的,应退出连接。由于scott包含索引等信息,应使用cascade参数。命令如下:
drop user scott cascade;
2、在使用imp命令导入scott用户之前,需要先在目标数据库创建该用户,并赋予相应的权限。首先登录sys或者system用户。运行以下语句:
create user scott identified by tiger;
grant create session,create table,unlimited tablespace to scott;
可以看到scott用户已经创建成功,但是没有相关的数据。
3、打开cmd,运行以下语句,导入数据。
imp scott/tiger@Q file=C:\Users\win10\Desktop\scott_dmp\scott.dmp full=y
imp username/password@db_name file=dmp文件存放路径 full=y
可以看到scott用户导入成功了。