简体   繁体   English

从Oracle迁移到MySQL

[英]Migrate from Oracle to MySQL

We ran into serious performance problems with our Oracle database and we would like to try to migrate it to a MySQL-based database (either MySQL directly or, more preferably, Infobright). 我们的Oracle数据库遇到了严重的性能问题,我们想尝试将其迁移到基于MySQL的数据库(直接使用MySQL,或者最好使用Infobright)。

The thing is, we need to let the old and the new system overlap for at least some weeks if not months, before we actually know, if all the features of the new database match our needs. 问题是,在我们实际上不知道新数据库的所有功能是否符合我们的需求之前,我们需要让旧系统和新系统至少重叠数周(如果不是几个月)。

So, here is our situation: 因此,这是我们的情况:

The Oracle database consists of multiple tables with each millions of rows. Oracle数据库由多个表组成,每百万行。 During the day, there are literally thousands of statements, which we cannot stop for migration. 白天,实际上有成千上万的语句,我们无法停止迁移。

Every morning, new data is imported into the Oracle database, replacing some thousands of rows. 每天早晨,新数据都会导入到Oracle数据库中,从而替换了数千行。 Copying this process is not a problem, so we could, in theory, import in both databases in parallel. 复制此过程不是问题,因此从理论上讲,我们可以并行导入两个数据库。

But, and here the challenge lies, for this to work we need to have an export from the Oracle database with a consistent state from one day. 但是,挑战就在这里,要使此工作正常进行,我们需要从一天开始以一致的状态从Oracle数据库进行导出。 (We cannot export some tables on Monday and some others on Tuesday, etc.) This means, that at least the export should be finished in less than one day. (我们不能在星期一导出某些表,而在星期二不能导出其他表,等等。)这意味着,至少导出应在不到一天的时间内完成。

Our first thought was to dump the schema, but I wasn't able to find a tool to import an Oracle dump file into MySQL. 我们最初的想法是转储架构,但是我找不到能够将Oracle转储文件导入MySQL的工具。 Exporting tables in CSV files might work, but I'm afraid it could take too long. 将表格导出为CSV文件可能会起作用,但恐怕可能会花费太长时间。

So my question now is: 所以我的问题是:

What should I do? 我该怎么办? Is there any tool to import Oracle dump files into MySQL? 有没有什么工具可以将Oracle转储文件导入MySQL? Does anybody have any experience with such a large-scale migration? 有人有过大规模迁移的经验吗?

PS: Please, don't suggest performance optimization techniques for Oracle, we already tried a lot :-) PS:请不要建议Oracle性能优化技术,我们已经尝试了很多:-)

Edit: We already tried some ETL tools before, only to find out, that they were not fast enough: Exporting only one table already took more than 4 hours ... 编辑:我们已经尝试过一些ETL工具,才发现它们不够快:仅导出一张表已经花费了4多个小时...

2nd Edit: Come on folks ... did nobody ever try to export a whole database as fast as possible and convert the data so that it can be imported into another database system? 第二编辑:来吧……没有人尝试过尽快导出整个数据库并转换数据以便可以将其导入另一个数据库系统吗?

Oracle does not supply an out-of-the-box unload utility. Oracle不提供开箱即用的卸载实用程序。

Keep in mind without comprehensive info about your environment (oracle version? server platform? how much data? what datatypes?) everything here is YMMV and you would want to give it a go on your system for performance and timing. 请记住,如果没有有关您的环境的全面信息(Oracle版本?服务器平台?多少数据?什么数据类型?),这里的所有内容都是YMMV,您可能希望在系统上使用它来提高性能和计时。

My points 1-3 are just generic data movement ideas. 我的观点1-3只是通用的数据移动思想。 Point 4 is a method that will reduce downtime or interruption to minutes or seconds. 第4点是一种将停机时间或中断时间减少到几分钟或几秒钟的方法。

1) There are 3rd party utilities available. 1)有第三方实用程序。 I have used a few of these but best for you to check them out yourself for your intended purpose. 我已经使用了其中一些,但最适合您根据自己的意图检查一下。 A few 3rd party products are listed here: OraFaq . 这里列出了一些第三方产品: OraFaq Unfortunately a lot of them run on Windows which would slow down the data unload process unless your DB server was on windows and you could run the load utility directly on the server. 不幸的是,除非其中的DB服务器在Windows上并且您可以直接在服务器上运行load实用程序,否则它们中的许多都将在Windows上运行,这会减慢数据卸载过程。

2) If you don't have any complex datatypes like LOBs then you can roll your own with SQLPLUS. 2)如果您没有像LOB这样的复杂数据类型,则可以使用SQLPLUS进行滚动。 If you did a table at a time then you can easily parallelize it. 如果您一次创建一个表,则可以轻松地对其进行并行化。 Topic has been visited on this site probably more than once, here is an example: Linky 可能已经多次访问了此主题,这里有一个示例: Linky

3) If you are 10g+ then External Tables might be a performant way to accomplish this task. 3)如果您的年龄在10克以上,则外部表可能是完成此任务的一种有效方法。 If you create some blank external tables with the same structure as your current tables and copy the data to them, the data will be converted to the external table format (a text file). 如果创建具有与当前表相同结构的空白外部表并将数据复制到它们中,则数据将转换为外部表格式(文本文件)。 Once again, OraFAQ to the rescue . 再次,OraFAQ进行救援

4) If you must keep systems in parallel for days/weeks/months then use a change data capture/apply tool for near-zero downtime. 4)如果必须将系统并行运行几天/几周/几月,请使用变更数据捕获/应用工具将停机时间几乎设为零。 Be prepared to pay $$$. 准备支付$$$。 I have used Golden Gate Software's tool that can mine the Oracle redo logs and supply insert/update statements to a MySQL Database. 我使用了Golden Gate Software的工具,该工具可以挖掘Oracle重做日志并向MySQL数据库提供插入/更新语句。 You can migrate the bulk of the data with no downtime the week before go-live. 在上线前一周,您可以在不停机的情况下迁移大量数据。 Then during your go-live period, shut down the source database, have Golden Gate catch up the last remaining transactions, then open up access to your new target database. 然后在上线期间,关闭源数据库,让Golden Gate赶上最后剩下的事务,然后打开对新目标数据库的访问。 I have used this for upgrades and the catch up period was only a few minutes. 我已经使用它进行升级了,追赶期只有几分钟。 We already had a site licenses for Golden Gate so it wasn't anything out of pocket for us. 我们已经有了Golden Gate的站点许可证,因此对于我们而言,这并不是什么便宜的事情。

And I'll play the role of Cranky DBA here and say if you can't get Oracle performing well I would love to see a write up of how MySQL fixed your particular issues. 我将在这里扮演Cranky DBA的角色,并说如果您不能使Oracle表现良好,我很乐意看到有关MySQL如何解决您的特定问题的文章。 If you have an application where you can't touch the SQL, there are still lots of possible ways to tune Oracle. 如果您有一个无法使用SQL的应用程序,那么仍有许多可能的方法来调整Oracle。 /soapbox /肥皂盒

I have built a C# application that can read an Oracle dump (.dmp) file and pump it's tables of data into a SQL Server database. 我建立了一个C#应用程序,可以读取Oracle转储(.dmp)文件并将其数据表泵送到SQL Server数据库中。

This application is used nightly on a production basis to migrate a PeopleSoft database to SQL Server. 该应用程序每天在生产环境中使用,以将PeopleSoft数据库迁移到SQL Server。 The PeopleSoft database has 1100+ database tables and the Oracle dump file is greater than 4.5GB in size. PeopleSoft数据库具有1100多个数据库表,Oracle转储文件的大小大于4.5GB。

This application creates the SQL Server database and tables and then loads all 4.5GB of data in less than 55 minutes running on a dual-core Intel server. 该应用程序创建SQL Server数据库和表,然后在不到55分钟的时间内在双核Intel服务器上运行,加载所有4.5GB的数据。

I don't believe it would be too difficult to modify this application to work with other databases provided they have an ADO.NET provider. 我认为修改此应用程序以使其与具有ADO.NET提供程序的其他数据库一起工作不会太困难。

yeah, Oracle is pretty slow. 是的,Oracle非常慢。 :) :)

You can use any number of ETL tools to move data from Oracle into MySQL. 您可以使用任意数量的ETL工具将数据从Oracle移到MySQL。 My favourite is SQL Server Integration Services. 我最喜欢的是SQL Server集成服务。

If you have Oracle9i or higher, you can implement Change Data Capture. 如果您具有Oracle9i或更高版本,则可以实施Change Data Capture。 Read more here http://download-east.oracle.com/docs/cd/B14117_01/server.101/b10736/cdc.htm 在此处阅读更多信息http://download-east.oracle.com/docs/cd/B14117_01/server.101/b10736/cdc.htm

Then you can take a delta of changes from Oracle to your MySQL or Infobright using any ETL technologies. 然后,您可以使用任何ETL技术从Oracle到您的MySQL或Infobright进行大量更改。

I've used Pentaho Data Integration to migrate from Oracle to MySql (I also migrated the same data to Postresql, which was about 50% quicker, which I guess was largely due to the different JDBC drivers being used). 我已经使用Pentaho Data Integration从Oracle迁移到MySql(我也将相同的数据迁移到Postresql,速度大约快50%,我猜这很大程度上是由于使用了不同的JDBC驱动程序)。 I followed Roland Bouman's instructions here, almost to the letter, and was very pleasantly suprised at how easy it was: 我几乎遵循这封信,遵循罗兰·鲍曼(Roland Bouman)的指示,对它的简单程度感到非常惊喜:

Copy Table data from one DB to another 将表数据从一个数据库复制到另一个数据库

I don't know whether it will be appropriate for your data load, but it's worth a shot. 我不知道它是否适合您的数据加载,但是值得一试。

I recently released etlalchemy to accomplish this task. 我最近发布了etlalchemy以完成此任务。 It is an open-sourced solution which allows migration between any 2 SQL databases with 4 lines of Python , and was initially designed to migrate from Oracle to MySQL. 它是一个开放源代码的解决方案,允许使用4行Python在任意2个SQL数据库之间进行迁移,并且最初设计为从Oracle迁移到MySQL。 Support has been added for MySQL, PostgreSQL, Oracle, SQLite and SQL Server. 添加了对MySQL,PostgreSQL,Oracle,SQLite和SQL Server的支持。

This will take care of migrating schema (arguably the most challenging), data, indexes and constraints, with many more options available. 这将照顾到迁移模式(可以说是最具挑战性的),数据,索引和约束,还有更多可用选项。

To install: 安装:

$ pip install etlalchemy

On El Capitan : pip install --ignore-installed etlalchemy 在El Capitan上pip install --ignore-installed etlalchemy

To run: 跑步:

from etlalchemy import ETLAlchemySource, ETLAlchemyTarget

orcl_db_source = ETLAlchemySource("oracle+cx_oracle://username:password@hostname/ORACLE_SID")

mysql_db_target = ETLAlchemyTarget("mysql://username:password@hostname/db_name", drop_database=True)
mysql_db_target.addSource(orcl_db_source)
mysql_db_target.migrate()

Concerning performance , this tool utilizes BULK import tools across various RDBMS such as mysqlimport and COPY FROM ( postgresql ) to carry out migrations efficiently. 关于性能 ,此工具在各种RDBMS中使用BULK导入工具,例如mysqlimportCOPY FROMpostgresql ),以高效地进行迁移。 I was able to migrate a 5GB SQL Server database with 33,105,951 rows into MySQL in 40 minutes, and a 3GB 7,000,000 row Oracle database to MySQL in 13 minutes. 我能够在40分钟内将具有33105951行的5GB SQL Server数据库迁移到MySQL,并在13分钟内将3GB 7000000行的Oracle数据库迁移到MySQL。

To get more background on the origins of the project, check out this post. 要获得有关项目起源的更多背景信息, 请查看这篇文章。 If you get any errors running the tool, open an issue on the github repo and I'll patch it up in less than a week! 如果在运行该工具时遇到任何错误,请在github存储库上打开一个问题,我将在不到一周的时间内对其进行修补!

(To install the "cx_Oracle" Python driver, follow these instructions ) (要安装“ cx_Oracle” Python驱动程序,请按照以下说明进行操作

We had the same issue. 我们有同样的问题。 Needed to get tables and data from oracle dbms to mysql dbms. 需要从oracle dbms到mysql dbms获取表和数据。

We used this tool we found online... It worked well. 我们使用了我们在网上找到的工具...效果很好。

http://www.sqlines.com/download http://www.sqlines.com/download

This tool will basically help you: 该工具基本上可以帮助您:

  1. Connect to your source DBMS(ORACLE) 连接到您的源DBMS(ORACLE)
  2. Connect to destination DBMS(MySQL) 连接到目标DBMS(MySQL)
  3. Specify schema and tables in the ORACLE DBMS you want to migrate 在要迁移的ORACLE DBMS中指定架构和表
  4. Press a "Transfer" button to Run the migration process(running inbuilt migration queries) 按下“传输”按钮以运行迁移过程(运行内置的迁移查询)
  5. Get a transfer log, which will tell how many records were READ from SOURCE and WRITTEN on the destination database, what queries failed. 获取传输日志,该日志将告诉您从目标数据库中的SOURCE和WRITTEN中读取了多少条记录,哪些查询失败。

Hope this will help others that will land on this question. 希望这会帮助其他将解决此问题的人。

You can use Python, SQL*Plus and mysql.exe (MySQL client) script to copy whole table of just query results. 您可以使用Python,SQL * Plus和mysql.exe (MySQL客户端)脚本复制仅查询结果的整个表。 It will be portable because all those tools exist on Windows and Linux. 由于所有这些工具都存在于Windows和Linux中,因此它将是可移植的。

When I had to do it I implemented following steps using Python: 当必须这样做时,我使用Python实现了以下步骤:

  1. Extract data into CSV file using SQL*Plus. 使用SQL * Plus将数据提取到CSV文件中。
  2. Load dump file into MySQL using mysql.exe. 使用mysql.exe将转储文件加载到MySQL中。

You can improve performance by performing parallel load using Tables/Partitions/Sub-partitions. 您可以通过使用表/分区/子分区执行并行加载来提高性能。

Disclosure: Oracle-to-MySQL-Data-Migrator is the script I wrote for data integration between Oracle and MySQL on Windows OS. 披露: Oracle到MySQL的数据迁移器是我为Windows OS上的Oracle and MySQL之间的数据集成编写的脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM