背景
由于一套系统用于多个省份,而不同省份都有自己的需求,会存在这种情况:
A省的service表比B省的service表多了几个字段。
而开发的时候,都是多个省份共用一套数据库的。为了解决上面的问题需要测试人员对各个省对应的数据库进行管控,以防止系统发布补丁是出现表的不兼容的情况。但是为了便于开发测试,这里再新建数据库用于A省份的开发,即需要将原有的数据库迁移到新数据库上面。下面一次记录操作步骤。
新建用户并授权
--创建用户
create user CC identified by CC default tablespace CC temporary tablespace temp;
create user ZZ identified by ZZ default tablespace ZZ temporary tablespace temp;
create user PP identified by PP default tablespace PP temporary tablespace temp;
create user JJ identified by JJ default tablespace JJ temporary tablespace temp;
create user GG identified by GG default tablespace GG temporary tablespace temp;
--授权
grant select any sequence, connect, resource, select any table,create table,create any index, update any table,execute any procedure, insert any table to CC;
grant select any sequence, connect, resource, select any table,create table,create any index, update any table,execute any procedure, insert any table to ZZ;
grant select any sequence, connect, resource, select any table,create table,create any index, update any table,execute any procedure, insert any table to GG;
grant select any sequence, connect, resource, select any table,create table,create any index, update any table,execute any procedure, insert any table to JJ;
grant select any sequence, connect, resource, select any table,create table,create any index, update any table,execute any procedure, insert any table to PP;
根据用户创建对应的数据文件
--创建用户数据文件
create tablespace ZZ datafile
'/data/boss/ZZ_data.dbf' SIZE 10G autoextend on next 128M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
ALTER TABLESPACE ZZ
ADD DATAFILE '/data/boss/ZZ_data2.dbf' size 5G autoextend on next 128m maxsize unlimited
create tablespace ZZ_IDX datafile
'/data/boss/ZZ_idx.dbf' SIZE 3G autoextend on next 128M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
create tablespace CC datafile
'/data/boss/CC_data.dbf' SIZE 10G autoextend on next 128M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
create tablespace CC_IDX datafile
'/data/boss/CC_idx.dbf' SIZE 512M autoextend on next 128M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
create tablespace PP datafile
'/data/boss/PP_data.dbf' SIZE 512M autoextend on next 128M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
create tablespace JJ datafile
'/data/boss/JJ_data.dbf' SIZE 1024M autoextend on next 128M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
create tablespace JJ_IDX datafile
'/data/boss/JJ_idx.dbf' SIZE 512M autoextend on next 128M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
create tablespace GG datafile
'/data/boss/GG_data.dbf' SIZE 50M autoextend on next 128M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
将对应用户的数据导出
--从121数据库中导出数据
nuhup exp GG/GG@121 file=GG.dmp log=GG.log
nuhup exp PP/PP@121 file=PP.dmp log=PP.log
nuhup exp ZZ/ZZ@121 file=ZZ.dmp log=ZZ.log
nuhup exp CC/CC@121 file=CC.dmp log=CC.log
nuhup exp JJ/JJ@121 file=JJ.dmp log=JJ.log
将导出文件导入到新的数据库中
--导入到test库,其他用户以此类推
imp JJ/JJ@TEST file=d:\JJ.dmp
说明
1、这里需要注意oracle对应的exp和imp的版本是向上兼容的,即可以使用高版本的exp和imp从低版本数据库中导出数据然后导入到高版本的数据库中。反之可能会出现问题,
sqlplus远程连接数据库
--连接远程数据库:用户名/密码@ip:port/service_name
--TSTDB2 is service_name
sqlplus tst/234@10.128.11.98:8899/TSTDB2