Oracle数据迁移备份、授权和创建表空间、用户
1.Oracle数据迁移备份(cmd方式)
-
从Oracle导出数据到本地电脑
C:\Users\bobo>exp scott/[email protected] tables=emp,dept rows=y file=d:\emp_dept.dmp log=d:\emp_dept.log
—rows是行,y代表yes
—数据要dmp格式 -
从本地电脑导入数据到Oracle
emp_dept.dmp源数据文件导入到scott用户
C:\Users\bobo>imp scott/[email protected] fromuser=scott touser=scott file=d:\emp_dept.dmp rows=y log=d:\imp_emp_dept.log
—fromuser是从哪个用户导出
—touser是导入到哪个用户下
在Oracle客户端的tables文件夹下就能看到导入的数据表
2.Oracle用户授权
前期准备:
打开cmd窗口,输入sqlplus scott/[email protected]连接Oracle数据库
或者
在PLSQL Developer客户端,打开sql编写窗口,输入以下命令也可授权。
-
授权/撤销授权用户DBA角色
授权:grant dba to scott;
撤销:revoke dba from scott; -
表空间授权
创建表空间:grant create tablespace to scott;
修改表空间:grant alter tablespace to scott;
删除表空间:grant drop tablespace to scott;授权完成后,可以在客户端查看授权信息,也可以直接在客户端编辑添加权限。
-
用户授权
创建用户:grant create user to scott;
修改用户:grant alter user to scott;
删除用户:grant drop user to scott;
3.创建表空间和用户
一般是先有数据库,然后创建N个表空间,再创建用户,用户可以指定该表空间,该表空间下可以存储N张表。
-
创建表空间
create tablespace test
datafile ‘D:\oracle\product\10.2.0\oradata\orcl\test.dbf’
size 10m [autoextend on] [next 1M] [maxsize 2G];—datafile数据库的路径要真实存在
—.dbf(database file) 数据库文件
—size 为初始表空间大小,单位为K或者M
—autoextend 是否自动扩展,值为on或off
—next为文件满了后扩展大小
—maxsize为文件最大大小,值为数值或unlimited(表示不限大小) -
删除表空间
drop tablespace 表空间名称;删除空表空间,包括创建的数据库文件
drop tablespace test including contents and datafiles; -
创建用户
create user test01 identified by test01
default tablespace test
temporary tablespace temp;—identified by:创建用户名的口令密码
—默认表空间用test
—临时空间用temp -
给test01用户授权连接数据库
创建完用户之后,在Users文件夹下能看见test01用户,但是想登录test01用户显示没有权限去连接数据库。
所以需要在system用户下授权test01用户连接数据库。
再次按会话登录,就能成功登录上test01用户。
test01用户指定了test表空间,创建的表存放在test表空间下。