Alex Kirpichny

Alexandr Kirpichny

Chief Product Officer, Ispirer Systems

In the world of databases, switching from Oracle to MySQL database is like moving from a well-established giant to a nimble contender. Oracle has been the go-to choice for big companies, but things are changing. This article is your guide to understand why and how this shift makes sense. We'll break down the reasons, walk you through the technical steps, and make sure you're ready to embrace Oracle to MySQL migration.

What is Oracle?

Oracle database is a powerful and widely-used relational database management system (RDBMS) developed by Oracle Corporation. It's designed to store, manage, and retrieve structured data efficiently. In simple terms, think of it as a sophisticated digital filing cabinet where organizations can store and organize their data in a structured manner.

Oracle database uses a structured query language called SQL to interact with the data it holds. This allows users to perform various operations like inserting, querying, updating, and deleting data within the database. What sets Oracle database apart is its ability to handle large amounts of data, ensure data integrity, and provide advanced security features to protect sensitive information.

It's widely utilized across industries for applications ranging from handling financial transactions, customer records, and inventory management to running complex analytical queries. Oracle database scalability and reliability make it a popular choice for businesses that require robust data management solutions to support their operations.

What is MySQL?

MySQL is a relational database management system (RDBMS) developed by Oracle that is based on structured query language (SQL).

Relational databases are digital stores that collect and organize data according to a relational model. The structure of tables in this model follows a strict logical structure, with rows and columns. A Relational Database Management System (RDBMS) consists of the tools used to create, manage, and query such a database.

In today's world, MySQL is an integral part of many popular software stacks, whether you are building customer-facing web applications or powerful, data-driven business-to-business applications. Due to its open-source nature, stability, and rich feature set, Facebook, Flickr, Twitter, Wikipedia, and YouTube have all chosen MySQL over other platforms due to its open-source nature, stability, and feature set.

Oracle to MySQL Migration: 2 easy methods

Our article examines two ways to migrate Oracle database to MySQL:

  • Manual migration. This migration is appropriate for small and simple databases
  • Automated migration using special tools. This type of migration is appropriate for databases with a large amount of sql code, including packages.

How to Set up Oracle to MySQL Migration Manually?

1. Begin by accessing your MySQL interface and initializing the ODBC Connector data source.

2. Connect the ODBC Data Source to MySQL.

3. Enter the necessary information to connect the database, user, and password for the Oracle Server. Give an appropriate ODBC connection name. To check the connection, click the Test button.

4. Input the requisite details, including database credentials, user identification, and Oracle Server password. Assign a fitting name to the ODBC connection. To check the connection, click the Test button.

  1.  
  2. SID_LIST_LISTENER =
  3. &lsaquo;<Space>&rsaquo;(SID_LIST=
  4. &lsaquo;<Space>&rsaquo;(SID_DESC=
  5. &lsaquo;<Space>&rsaquo;(SID_NAME=test)
  6. &lsaquo;<Space>&rsaquo;(ORACLE_HOME=C:oracleproduct11.2.0dbhome_1)
  7. &lsaquo;<Space>&rsaquo;(PROGRAM=dg4odbc)
  8. )
  9. )
  10.  

If the path specified isn’t your installation path, change the location of ORACLE HOME.

If you have any problems, type dg4odbc to see if the software is present or not. If you encounter a "Program not recognized" problem, make sure your path variable includes $ORACLE HOME/bin and restart the command line to verify.

5. The file of inittest.ora is generated automatically when a new SID is created. To change its name, use init + SID name. Set up the data source and SID for dg4odbc program. Add the commands to the inittest.ora file.

  1.  
  2. HS_FDS_CONNECT_INFO = test
  3.  

6. Configure tnsnames.ora file (in the $ORACLE_HOME/NETWORK/ADMIN/TNSNAMES.ora.) by adding the statements.

  1.  
  2. TSLINK =
  3. (DESCRIPTION=
  4. (ADDRESS=
  5. (PROTOCOL=TCP)
  6. (HOST=localhost)
  7. (PORT=)
  8. )
  9. (CONNECT_DATA=
  10. (SID=the one created on the listener.ora file)
  11. )
  12. (HS=OK)
  13. )
  14.  

7. Reboot the Oracle Service and TNS Listener Service.

8. Log in to the Oracle database with credentials and create the database link: create public database link link2mysqltest connect to "oracle" identified by "oracle" using 'TSTLINK';

9. Test the link and click Finish.

10. Log in to MySQL and run the command.

  1.  
  2. select * from "xx_table"@link2mysqltest
  3.  

Limitations of Manual Oracle to MySQL Migration

To migrate Oracle database to MySQL manually you should be aware of a set of limitations:

  • While the setup may seem straightforward, the intricacies of a successful migration demand profound Oracle administration skills. Lack of the expertise can result in numerous errors due to the multitude of configuration parameters that differ across various versions.
  • Even upon achieving a seemingly smooth Oracle database to MySQL migration, the real-world connection exposes numerous constraints and imperfections concerning executable SQL queries. Challenges emerge involving unsupported functions and data types in both source and target databases.

Oracle to MySQL migration using Ispirer Toolkit

SQLWays Wizard is an easy-to-use solution for heterogeneous database migrations. Its smart core helps to automate the migration of a database schema, including data, tables, stored procedures, functions, triggers, and views. It supports a vast amount of migration directions between legacy and modern RDBMS, including Oracle to MySQL migration.

One of the hallmarks of SQLWays Wizard is a flexible approach to customizing the tool with hundreds of options for any kind of migration projects.

1. Tables, indexes and data types

SQLWays Wizard automates the migration of Oracle data types to corresponding types in MySQL database. The tool contains settings that allow to specify the target types of data in MySQL.

OracleMySQL
  1.  
  2.  
  3. CREATE TABLE products
  4. ( product_id numeric(10) not null,
  5. supplier_id numeric(10) not null,
  6. CONSTRAINT fk_supplier
  7. FOREIGN KEY (supplier_id)
  8. REFERENCES supplier(supplier_id)
  9. );
  10.  
  11.  
  12.  
  13. create index "Table1_IDX" on "Table1"("AA")
  14.  
  1.  
  2. CREATE TABLE products
  3. (
  4. product_id INT not null,
  5. supplier_id INT not null,
  6. CONSTRAINT FK_SUPPLIER
  7. FOREIGN KEY(supplier_id)
  8. REFERENCES supplier(supplier_id)
  9. );
  10.  
  11.  
  12. create index Table1_IDX on Table1
  13. (AA);
  14.  

2. Variables

In order to declare variables inside the function, the tool uses a DECLARE keyword. The DEFAULT keyword serves for assigning values to variables.

After Oracle to MySQL migration, the trunc function converts to a corresponding TRANCATE function.

OracleMySQL
  1.  
  2. CREATE FUNCTION "DELAYREPORTMESSAGE" (fltseqno number,delcode varchar2) return varchar2 is
  3. var_drm varchar2(4000) :='';
  4. var_drm2 varchar2(4000) :='';
  5. var_drm3 varchar2(4000) :='';
  6. var_drm4 varchar2(4000) :='';
  7. begin
  8. SELECT trunc(a.delay_mts),
  9. trunc(a.delay_mts/60),
  10. trunc(a.delay_mts/60,5),
  11. trunc(a.delay_mts/60,fltseqno)
  12. INTO var_drm, var_drm2, var_drm3, var_drm4
  13. FROM ekmis_flt_delay_dtls a;
  14. return var_drm;
  15. end;
  16.  
  1.  
  2. CREATE FUNCTION DELAYREPORTMESSAGE(fltseqno INT,delcode VARCHAR(4000)) RETURNS VARCHAR(4000)
  3. begin
  4. DECLARE var_drm VARCHAR(4000) DEFAULT '';
  5. DECLARE var_drm2 VARCHAR(4000) DEFAULT '';
  6. DECLARE var_drm3 VARCHAR(4000) DEFAULT '';
  7. DECLARE var_drm4 VARCHAR(4000) DEFAULT '';
  8. SELECT TRUNCATE(A.DELAY_MTS,0),
  9. TRUNCATE(A.DELAY_MTS/60,0),
  10. TRUNCATE(A.DELAY_MTS/60,5),
  11. TRUNCATE(A.DELAY_MTS/60,fltseqno)
  12. INTO var_drm,var_drm2,var_drm3,var_drm4
  13. FROM EKMIS_FLT_DELAY_DTLS A;
  14. return var_drm;
  15. end;
  16.  

3. Packages

MySQL syntax doesn’t contain packages, so the tool converts them to objects.

OracleMySQL
  1.  
  2. CREATE OR REPLACE PACKAGE emp_mgmt AS
  3. PROCEDURE remove_emp(employee_id NUMBER);
  4. END emp_mgmt;
  5.  
  6. CREATE OR REPLACE PACKAGE BODY emp_mgmt AS
  7. PROCEDURE remove_emp (employee_id NUMBER) IS
  8. BEGIN
  9. DELETE FROM employees
  10. WHERE employees.employee_id = remove_emp.employee_id;
  11. END;
  12. END emp_mgmt;
  13.  
  1.  
  2. DROP PROCEDURE IF EXISTS EMP_MGMT_REMOVE_EMP;
  3. //
  4. CREATE PROCEDURE EMP_MGMT_REMOVE_EMP(employee_id INT)
  5. BEGIN
  6. DELETE FROM employees
  7. WHERE employees.employee_id = remove_emp.employee_id;
  8. END;
  9. //
  10.  

4. Cursors

Some changes SQLWays Wizard provides during Oracle to MySQL conversion:

  • For Oracle cursors the tool declares additional variables SWV_NO_DATA, SWV_CUR1_COL1, SWV_CUR1_TOTAL.
  • If a cursor doesn’t contain variables, then the tool uses a handler and SWV_NO_DATA variable.
  • Instead of FOR LOOP the tool uses FETCH. Values are written to variables SWV_CUR1_COL1 и SWV_CUR1_TOTAL.
OracleMySQL
  1.  
  2. CREATE PROCEDURE PROC_A_T2 AS
  3.  
  4.  
  5. v1 NUMBER;
  6. v2 NUMBER;
  7.  
  8.  
  9. CURSOR CUR1 IS
  10. SELECT CASE WHEN UPPER (col2) IN ('Q') THEN col1 ||'Request'
  11. WHEN UPPER (col2) IN ('R') THEN col1 ||'Response'
  12. WHEN UPPER (col2) IN ('*') THEN col1 ||'Unknown'
  13. ELSE col1 END col1, CNT TOTAL
  14. FROM ( SELECT
  15. col1, col2, COUNT (*) CNT
  16. FROM A_T2
  17. GROUP BY col1, col2)
  18. GROUP BY col1, col2, CNT
  19. ORDER BY col1;
  20.  
  21.  
  22.  
  23.  
  24. BEGIN
  25.  
  26.  
  27. v1 := 1;
  28. IF v1 > 0 THEN
  29. FOR CUR1_REC IN CUR1 LOOP
  30. v2 := ROUND((CUR1_REC.TOTAL/v1)*100, 4);
  31. END LOOP;
  32.  
  33.  
  34. END IF;
  35.  
  36.  
  37. END PROC_A_T2 ;
  38.  
  39.  
  1.  
  2. CREATE PROCEDURE PROC_A_T2()
  3. BEGIN
  4.  
  5.  
  6.  
  7.  
  8. DECLARE V1 INT;
  9. DECLARE V2 INT;
  10.  
  11.  
  12. DECLARE SWV_NO_DATA INT DEFAULT 0;
  13. DECLARE SWV_CUR1_COL1 TEXT;
  14. DECLARE SWV_CUR1_TOTAL BIGINT;
  15. DECLARE CUR1 CURSOR FOR SELECT CASE WHEN UPPER(COL2) IN('Q') THEN CONCAT(COL1,'Request')
  16. WHEN UPPER(COL2) IN('R') THEN CONCAT(COL1,'Response')
  17. WHEN UPPER(COL2) IN('*') THEN CONCAT(COL1,'Unknown')
  18. ELSE COL1 END COL1, CNT TOTAL
  19. FROM(SELECT
  20. COL1, COL2, COUNT(*) CNT
  21. FROM A_T2
  22. GROUP BY COL1,COL2) AS TABAL
  23. GROUP BY COL1,COL2,CNT
  24. ORDER BY ISNULL(COL1),COL1;
  25. DECLARE CONTINUE HANDLER FOR NOT FOUND SET SWV_NO_DATA = -1;
  26.  
  27.  
  28.  
  29.  
  30. SET V1 = 1;
  31. IF V1 > 0 THEN
  32. OPEN CUR1;
  33. SET SWV_NO_DATA = 0;
  34. FETCH CUR1 INTO SWV_CUR1_COL1,SWV_CUR1_TOTAL;
  35. WHILE SWV_NO_DATA = 0 DO
  36. SET V2 = ROUND((SWV_CUR1_TOTAL/V1)*100,4);
  37. SET SWV_NO_DATA = 0;
  38. FETCH CUR1 INTO SWV_CUR1_COL1,SWV_CUR1_TOTAL;
  39. END WHILE;
  40. SET SWV_NO_DATA = 0;
  41. CLOSE CUR1;
  42. END IF;
  43. END;
  44.  

7. Sequences

Sequences also undergo certain changes after the migration from Oracle to MySQL. As MySQL syntax doesn’t have sequences, conversion requires creating additional objects. Particularly, a table for preserving values, functions for getting current values, functions for subsequent values and procedures which create sequence equivalents by calling it.

OracleMySQL
  1.  
  2. create sequence "EXAMPLE_OF_SEQ" minvalue 1000 maxvalue 1000000000 cycle
  3.  
  1.  
  2. call SWP_CrtSeq('EXAMPLE_OF_SEQ',1,1,1000000000,1000,1,null);
  3.  
  4. DELIMITER //
  5. DROP PROCEDURE IF EXISTS SWP_CrtSeq;
  6. //
  7. create procedure SWP_CrtSeq(SeqN VARCHAR(50), SeqVal DECIMAL(30,0), SeqI BIGINT, SeqMx DECIMAL(30,0), SeqMn DECIMAL(30,0), SeqCc INT, SeqRest DECIMAL(30,0))
  8. SWL_return:
  9. begin
  10.  
  11. DECLARE sql_error INT;
  12. DECLARE RaiserrorMsg VARCHAR(1000);
  13.  
  14. IF EXISTS (SELECT 1 FROM SWT_Sequence WHERE SeqName = SeqN) then
  15. SET RaiserrorMsg = CONCAT(N'Sequence ', SeqN, N' already exists in the database.');
  16. SIGNAL SQLSTATE '99999' SET MESSAGE_TEXT = RaiserrorMsg;
  17. LEAVE SWL_return;
  18. end if;
  19.  
  20. if SeqI > 9999999999999999999999999999 or SeqI < -99999999999999999999999999 or SeqMx > 9999999999999999999999999999 or SeqMx < -99999999999999999999999999
  21. or SeqMn < -99999999999999999999999999 or SeqMn > 9999999999999999999999999999 or SeqRest > 9999999999999999999999999999 or SeqRest < -99999999999999999999999999
  22. or SeqVal > 9999999999999999999999999999 or SeqVal < -99999999999999999999999999 then
  23. SET RaiserrorMsg = N'A Sequence object definition value is invalid or out of range.';
  24. SIGNAL SQLSTATE '99999' SET MESSAGE_TEXT = RaiserrorMsg;
  25. LEAVE SWL_return;
  26. end if;
  27.  
  28. if SeqMx < SeqMn then
  29. SET RaiserrorMsg = N'MAXVALUE cannot be less than MINVALUE.';
  30. SIGNAL SQLSTATE '99999' SET MESSAGE_TEXT = RaiserrorMsg;
  31. LEAVE SWL_return;
  32. end if;
  33.  
  34. if SeqRest > SeqMx or SeqRest < SeqMn or SeqVal > SeqMx or SeqVal < SeqMn then
  35. SET RaiserrorMsg = N'Cannot set START value less than MINVALUE or greater than MAXVALUE.';
  36. SIGNAL SQLSTATE '99999' SET MESSAGE_TEXT = RaiserrorMsg;
  37. LEAVE SWL_return;
  38. end if;
  39.  
  40. insert into SWT_Sequence(SeqName, SeqValue, SeqInc, SeqMax, SeqMin, SeqCyc, SeqRestart) values(SeqN, SeqVal, SeqI, SeqMx, SeqMn, SeqCc, SeqRest);
  41. end;
  42.  
  43. //
  44. DELIMITER ;
  45.  
  46. DROP TABLE IF EXISTS SWT_Sequence;
  47. create table SWT_Sequence(SeqName varchar(50) primary key, SeqValue DECIMAL(30,0), SeqInc bigint, SeqMax DECIMAL(30,0), SeqMin DECIMAL(30,0), SeqCyc int, SeqRestart DECIMAL(30,0), SeqPrevRestart DECIMAL(30,0));
  48.  
  49. DELIMITER //
  50. DROP FUNCTION IF EXISTS SWF_NextVal;
  51. //
  52. create function SWF_NextVal(SeqN varchar(50))
  53. returns DECIMAL(30,0)
  54. deterministic
  55. begin
  56. DECLARE SeqVal DECIMAL(30,0);
  57. DECLARE RaiserrorMsg VARCHAR(1000);
  58. if exists(select 1 from SWT_Sequence where SeqName = SeqN) then
  59. select CASE WHEN SeqRestart is null THEN case when SeqValue = SeqMax and SeqCyc = 1 then SeqMin else SeqValue+SeqInc end
  60. ELSE SeqRestart END INTO SeqVal from SWT_Sequence where SeqName = SeqN;
  61. update SWT_Sequence set SeqValue = CASE WHEN SeqRestart is null THEN case when SeqValue = SeqMax and SeqCyc = 1 then SeqMin else SeqValue+SeqInc end
  62. ELSE SeqRestart END,SeqRestart = null,SeqPrevRestart = CASE WHEN SeqRestart IS NULL THEN SeqPrevRestart ELSE SeqRestart END where SeqName = SeqN;
  63. return SeqVal;
  64. else
  65. SET RaiserrorMsg = CONCAT(N'The specified sequence object ', SeqN, ' is not in the database.');
  66. SIGNAL SQLSTATE '99999' SET MESSAGE_TEXT = RaiserrorMsg;
  67. end if;
  68. end;
  69.  
  70. //
  71. DELIMITER ;
  72.  
  73. DELIMITER //
  74. DROP FUNCTION IF EXISTS SWF_CurrVal;
  75. //
  76. create function SWF_CurrVal(SeqN varchar(50))
  77. returns DECIMAL(30,0)
  78. deterministic
  79. begin
  80. DECLARE SeqVal DECIMAL(30,0);
  81. DECLARE RaiserrorMsg VARCHAR(1000);
  82. if exists(select 1 from SWT_Sequence where SeqName = SeqN) then
  83. select SeqValue INTO SeqVal from SWT_Sequence where SeqName = SeqN;
  84. return SeqVal;
  85. else
  86. SET RaiserrorMsg = CONCAT(N'The specified sequence object ', SeqN, ' is not in the database.');
  87. SIGNAL SQLSTATE '99999' SET MESSAGE_TEXT = RaiserrorMsg;
  88. end if;
  89. end;
  90. //
  91. DELIMITER ;
  92.  

We understand that the migration journey can be intricate, riddled with challenges. Ispirer Toolkit offers an intelligent approach to converting Oracle databases to MySQL. It eliminates the complexities by automating the entire process, leaving no room for error or uncertainty. From data extraction to transformation and loading, every step is orchestrated seamlessly, ensuring a smooth and error-free transition.

Picture this: a user-friendly interface that empowers you to select the necessary settings. With a few clicks, you effortlessly connect your source database to the target destination. Once these parameters are in place, a simple press of the "migrate" button sets the process in motion. The tool takes care of the rest – sql code conversion, data extraction, data type mapping, schema conversion, and more, all executed with precision.

This tool transcends the limitations of manual migration, providing a level of consistency, accuracy, and speed that human-driven processes struggle to match. By embracing automation, you empower your team to focus on higher-level tasks, leveraging your expertise where it matters most.

Try Ispirer Toolkit for free with a 30-days free trial and check the effectiveness of automated Oracle to MySQL migration.