原文地址在(http://www.yougemysqldba.com/dis ... &extra=page%3D1)
企业去IOE、或者转型MySQL,不是一蹴而就的,而是需要长期的积累。只有当企业能够真正驾驭MySQL时,才会将其作为核心数据库。在未来很长一段时间,MySQL的比重会不断的增加、Oracle的比重将会逐渐降低。而在这个时间内,企业经常需要将Oracle中的数据迁移到MySQL中。
目前较出名的有kettle(http://community.pentaho.com/projects/data-integration/),这款工具的核心特点是可视化、支持的数据库种类多。但是
其缺点也很明显,安装包大(接近一个G)、抽取和插入效率不敢恭维。
为了给大家一个额外的选择,我们提供了一个命令行下的数据迁移工具,专门针对从Oracle到MySQL,效率上要完爆kettle,而且配合一两行shell脚本,可以轻松
实现多线程。
安装
操作系统 Centos5、centos6 X64
软件环境 Oracle instant client软件包
上传上述rpm包与二进制包至/usr/local/ora2mysql/,并安装
oracle-instantclient-basic-10.2.0.4-1.x86_64.rpm(该文件太大,自己去网上下载)
oracle-instantclient-devel-10.2.0.4-1.x86_64.rpm
oracle-instantclient-sqlplus-10.2.0.4-1.x86_64.rpm
libmysqlclient.so.18(该文件太大,自己去网上下载)
oracle-instantclient-devel-10.2.0.4-1.x86_64.rpm (283.04 KB)
oracle-instantclient-sqlplus-10.2.0.4-1.x86_64.rpm (766.96 KB)
ora2mysql (143.22 KB)
rpm -ivh *.rpm
数据拷贝工具 ora2mysql
上传到/usr/local/ora2mysql/下
环境变量 修改/etc/profile,在末尾增加如下
export ORACLE_HOME=/usr/lib/oracle/10.2.0.4/client64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle/10.2.0.4/client64/lib:/usr/local/ora2mysql/
export TNS_ADMIN=/usr/lib/oracle/10.2.0.4/client64
运行 source /ect/profile
运行
1. 进入ora2mysql目录/usr/local/ora2mysql/下
运行
./ora2mysql
显示如下
DataCopy: Fast Oracle Data Copy Utility, Release 3.0.1
(c) Copyright Lou Fangxin (AnySQL.net) 2010, all rights reserved.
Support by Wang Guang You(www.yougemysqldba.com) or WeChat(onesoft007)
Usage: ora2mysql keyword=value [,keyword=value,...]
Valid Keywords:
user1 = username/password@hostort:sid for source database.
user2 = username/password@hostort:database for target database.
table = table name for both source and target.
tables = table name list for both source and target.
table1 = source table name to query data from.
table2 = target table name to insert data into.
query1 = select SQL for source database.
query2 = insert SQL for target database.
read = set DB_FILE_MULTIBLOCK_READ_COUNT at session level
sort = set SORT_AREA_SIZE at session level (UNIT:MB)
hash = set HASH_AREA_SIZE at session level (UNIT:MB)
serial = set _serial_direct_read to TRUE at session level
array = array fetch size
rows = print log information for every given rows.
long = maximum size for long, long raw, CLOB, BLOB columns.
crypt = encrypt the connection info only, no data copy (YES/NO).
parfile = read command option from parameter file
* wait = wait time in microsecond after each array.
* sync = sync mode (INSERT,UPDATE,DELETE,INSUPD,ARRINS,ARRUPD).
* unique = primary key or unique key columns of target table.
* conflict= conflict columns for update on target table.
* filler = filler columns (exclude columns) for target table.
* safe = double column buffer for character set conversion.
* degree = parallelize data copy degree (2-128).
log = log file name for screen messages.
Notes:
ora2mysql user1=scott/tiger user2=scott/tiger table=emp
ora2mysql user1=scott/tiger user2=scott/tiger table1=emp table2=emp_his
2. 根据Oracle表结构生成对应的MySQL表结构。由Oracle DBA和MySQL DBA配合完成。
3. 若两个表字段数和含义相同,运行如下命令
./ora2mysql user1=<username>/<password>@<host>:<port>:<sid> user2=<username/<password>@<host>:<port>:<database> table=<tablename>
4. 若两个表字段数或者含义不同,运行如下命令
./ora2mysql user1=<username>/<password>@<host>:<port>:<sid> user2=<username/<password>@<host>:<port>:<database> query1=”select <column> from <table>” query2=”insert into <table>( <column> )”