Migración de Oracle a MySql en Ubuntu 8.04

Ya pude lograr la migracion de Oracle a MySql en Ubuntu, el problema estaba en la maquina virtual de java.

En esta parte se supone que tenemos ya instalado Oracle y MySql. Se van a migrar los datos contenidos en el esquema HR con la cuenta hr/hr (no olvidar desbloquear) en Oracle, a la base de datos prueba en Mysql.

Crear en mysql la base de datos.
mysql> create database prueba;

Ahora lo que necesitamos es:

Instalar la maquina virtual de Java:
$ sudo apt-get install sun-java6-jdk

Descargar MySql Migration Tool que es parte de MySql GUI Tools
Descargar: Generic x86 Linux TAR (bundled dependencies)
Desempaquetar archivo: tar -xzvf mysql-gui-tools-5.0r12.tar.gz, creara un subdirectorio mysql-gui-tools-5.0

Editar archivos run_migration_simple (si vamos a usar desde la consola) y run_migration (si vamos a hacerlo desde ncurses). Los archivos estan en ~/mysql-gui-tools-5.0/migration-tool-script. El archivo debe quedar asi:

#!/bin/sh

# Change the following paths to your local installation of JRE 1.6
if test “x$JRE_LIB_BASE” = x; then
JRE_LIB_BASE=”/usr/lib/jvm/java-6-sun/jre/lib/i386″
fi

if [ ! -d $JRE_LIB_BASE ]; then
echo “JRE not found. Please make sure JRE (1.6.0 recommended) is installed and update the $0 script to point to the correct path”
exit 1
fi

JRE_LIB_PATHS=”$JRE_LIB_BASE:$JRE_LIB_BASE/server”

LD_LIBRARY_PATH=”java:$JRE_LIB_PATHS:$LD_LIBRARY_PATH”
export LD_LIBRARY_PATH

export GRT_JVM_PATH=”$JRE_LIB_BASE/server/libjvm.so”

./grtsh -x scripts/MigrationScript.lua

Descargar el Driver JDBC para la conexion a Oracle
Escoger: Oracle Database 10g (10.1.0.5),(10.1.0.4),(10.1.0.2) drivers
Descargar: ojdbc14.jar

Copiar el driver a ~/mysql-gui-tools-5.0/migration-tool-script/java/lib

Ejecutar y seguir los pasos:
$ ~/mysql-gui-tools-5.0/migration-tool-script/./run_migration_simple

MySQL Migration Toolkit – Script Version 1.1.9exp
————————————————-
Initializing migration environment…
Initialisation complete.

*******************************
* Source database connection. *
*******************************

Please choose a database system:
——————————–
1. MaxDB Database Server
2. Generic Jdbc
3. MS SQL Server
4. Oracle Database Server
5. MS Access
6. Sybase Server
7. MySQL Server
0. Abort

Source Database System: 4

Please choose a connection:
—————————
1. Create new connection
0. Abort
-1.Delete a connection

Connection: 1

Creating new connection to Oracle Database Server …
—————————————————–
Please enter the connection parameters.
Please choose a driver:
1. Oracle Thin JDBC Driver using SID
2. Oracle Thin JDBC Driver using Service
0. Abort

Driver: 1

SID: XE
Hostname: localhost
Port: [1521] 1521
Username: hr
Password: hr
Connection String: jdbc:oracle:thin:hr/hr@localhost:1521:XE

Connection name (leave blank not to store): hr

Testing connection to Oracle Database Server …
————————————————
Initializing JDBC driver …
Driver class Oracle Thin JDBC Driver using SID
Opening connection …
Connection jdbc:oracle:thin:hr/hr@localhost:1521:XE
Getting version information …
Initializing JDBC driver …
Driver class Oracle Thin JDBC Driver using SID
Test completed successfully.

*******************************
* Target database connection. *
*******************************

Please choose a database system:
——————————–
1. MySQL Server
0. Abort

Source Database System: 1

Please choose a connection:
—————————
1. Create new connection
0. Abort
-1.Delete a connection

Connection: 1

Creating new connection to MySQL Server …
——————————————-
Please enter the connection parameters.
Please choose a driver:
1. MySQL JDBC Driver 5.0
0. Abort

Driver: 1

Hostname: localhost
Port: [3306] 3306
Username: root
Password: password
Default Schema: (information_schema, blogWP, hr, maacnet, maacnetWP, mysql, prueba) prueba
Connection String: jdbc:mysql://localhost/?user=root&password=password

Connection name (leave blank not to store): hr

Testing connection to MySQL Server …
————————————–
Initializing JDBC driver …
Driver class MySQL JDBC Driver 5.0
Opening connection …
Connection jdbc:mysql://localhost/?user=root&password=password
Getting version information …
Initializing JDBC driver …
Driver class MySQL JDBC Driver 5.0
Test completed successfully.

*****************************
* Fetching source schemata. *
*****************************
List of source schemata fetched successfully.

*********************
* Schema selection. *
*********************

Choose the schemata to migrate …
———————————-
1. ANONYMOUS
2. CTXSYS
3. DBSNMP
4. DIP
5. FLOWS_020100
6. FLOWS_FILES
7. HR
8. MDSYS
9. OUTLN
10. SYS
11. SYSTEM
12. TSMSYS
13. XDB
0. Abort

Schemata: (ids seperate with ,) 7

Selected schema(ta):
——————–
HR

Accept selection: (1. Yes, 2. Reselect, 0. Abort) 1

************************
* Reverse engineering. *
************************

Reverse engineering Oracle Database Server …
———————————————-
Initializing JDBC driver …
Driver class Oracle Thin JDBC Driver using SID
Opening connection …
Connection jdbc:oracle:thin:hr/hr@localhost:1521:XE
Initializing JDBC driver …
Driver class Oracle Thin JDBC Driver using SID
Opening connection …
Connection jdbc:oracle:thin:hr/hr@localhost:1521:XE
Getting version information …
Initializing JDBC driver …
Driver class Oracle Thin JDBC Driver using SID
Build simple Oracle datatypes.
Fetch the number of tables in the schema HR.
SELECT COUNT(*) AS TABLECOUNT FROM ALL_TABLES t, ALL_OBJECTS a WHERE t.OWNER=? AND a.OWNER=t.OWNER AND a.OBJECT_NAME=t.TABLE_NAME AND a.OBJECT_TYPE=’TABLE’ AND a.STATUS=’VALID’
Fetching 7 table(s) of the schema HR.
SELECT t.* FROM ALL_TABLES t, ALL_OBJECTS a WHERE t.OWNER=? AND a.OWNER=t.OWNER AND a.OBJECT_NAME=t.TABLE_NAME AND a.OBJECT_TYPE=’TABLE’ AND a.STATUS=’VALID’ ORDER BY t.OWNER, t.TABLE_NAME
Processing table COUNTRIES.
Processing table DEPARTMENTS.
Processing table EMPLOYEES.
Processing table JOBS.
Processing table JOB_HISTORY.
Processing table LOCATIONS.
Processing table REGIONS.
Fetch column information.
Fetching column information.
SELECT tc.TABLE_NAME, tc.COLUMN_NAME, tc.DATA_TYPE, tc.DATA_TYPE_MOD, tc.CHAR_LENGTH, tc.DATA_LENGTH, tc.DATA_PRECISION, tc.DATA_SCALE, tc.NULLABLE, tc.DEFAULT_LENGTH, tc.DENSITY, tc.NUM_NULLS, tc.NUM_BUCKETS, tc.CHARACTER_SET_NAME, tc.DATA_DEFAULT FROM ALL_TAB_COLUMNS tc, ALL_TABLES t WHERE tc.OWNER=? AND t.OWNER=tc.OWNER AND tc.TABLE_NAME=t.TABLE_NAME ORDER BY tc.TABLE_NAME, tc.COLUMN_ID
Fetch PK information.
Fetching primary key information.
SELECT c.TABLE_NAME, i.COLUMN_NAME FROM ALL_CONSTRAINTS c, ALL_TABLES t, ALL_IND_COLUMNS i WHERE c.OWNER=? AND t.OWNER=c.OWNER AND c.TABLE_NAME=t.TABLE_NAME AND c.CONSTRAINT_TYPE=’P’ AND c.INDEX_NAME=i.INDEX_NAME AND i.TABLE_OWNER=c.OWNER AND i.TABLE_NAME=c.TABLE_NAME ORDER BY c.TABLE_NAME
Fetch index information.
Fetching indices information.
SELECT i.*, ic.COLUMN_NAME, ic.COLUMN_LENGTH, ic.DESCEND FROM ALL_INDEXES i, ALL_IND_COLUMNS ic, ALL_CONSTRAINTS c, ALL_TABLES t WHERE i.TABLE_OWNER=? AND t.OWNER=i.OWNER AND i.TABLE_NAME=t.TABLE_NAME AND ic.TABLE_OWNER=i.TABLE_OWNER AND ic.TABLE_NAME=i.TABLE_NAME AND ic.INDEX_NAME=i.INDEX_NAME AND c.OWNER(+)=i.OWNER AND c.CONSTRAINT_NAME(+)=i.INDEX_NAME AND (c.CONSTRAINT_TYPE is null OR c.CONSTRAINT_TYPE<>‘P’) ORDER BY i.TABLE_NAME, ic.INDEX_NAME, ic.COLUMN_POSITION
Fetch FK information.
Fetching FK information.
SELECT c.TABLE_NAME, c.CONSTRAINT_NAME, c.”DEFERRABLE”, c.DELETE_RULE, cc.COLUMN_NAME, r.OWNER AS R_SCHEMA, r.TABLE_NAME AS R_TABLE, rc.COLUMN_NAME AS R_COLUMN FROM ALL_CONSTRAINTS c, ALL_CONS_COLUMNS cc, ALL_CONSTRAINTS r, ALL_CONS_COLUMNS rc WHERE c.OWNER=? AND c.CONSTRAINT_TYPE = ‘R’ AND c.R_OWNER=r.OWNER AND c.R_CONSTRAINT_NAME=r.CONSTRAINT_NAME AND c.CONSTRAINT_NAME = cc.CONSTRAINT_NAME AND c.OWNER = cc.OWNER AND r.CONSTRAINT_NAME = rc.CONSTRAINT_NAME AND r.OWNER = rc.OWNER AND cc.POSITION = rc.POSITION ORDER BY c.TABLE_NAME, c.CONSTRAINT_NAME, cc.POSITION
Fetch trigger information.
Fetching FK information.
SELECT t.TABLE_NAME, t.TRIGGER_NAME, t.TRIGGER_TYPE, t.TRIGGERING_EVENT, t.BASE_OBJECT_TYPE, t.COLUMN_NAME, t.REFERENCING_NAMES, t.WHEN_CLAUSE, t.STATUS, t.DESCRIPTION, t.ACTION_TYPE, t.TRIGGER_BODY FROM ALL_TRIGGERS t, ALL_TABLES ta WHERE t.TABLE_OWNER=? AND ta.OWNER=t.OWNER AND t.TABLE_NAME=ta.TABLE_NAME ORDER BY t.TABLE_NAME
Fetch all views of the schema HR.
SELECT v.*, c.STATUS as CHECK_ENABLED FROM ALL_VIEWS v, ALL_CONSTRAINTS c, ALL_OBJECTS a WHERE v.OWNER=? AND c.TABLE_NAME(+)=v.VIEW_NAME AND c.CONSTRAINT_TYPE(+)=’V’ AND a.OWNER=v.OWNER AND a.OBJECT_NAME=v.VIEW_NAME AND a.OBJECT_TYPE=’VIEW’ AND a.STATUS=’VALID’ ORDER BY v.OWNER, v.VIEW_NAME
Processing view EMP_DETAILS_VIEW.
Fetching column information.
SELECT tc.TABLE_NAME, tc.COLUMN_NAME FROM ALL_TAB_COLUMNS tc, ALL_VIEWS v WHERE tc.OWNER=? AND v.OWNER=tc.OWNER AND tc.TABLE_NAME=v.VIEW_NAME ORDER BY tc.TABLE_NAME, tc.COLUMN_ID
Views fetched.
Fetch count of stored procedures of the schema HR.
SELECT COUNT(*) AS NUM FROM ALL_PROCEDURES p, ALL_OBJECTS a WHERE p.OWNER=? AND a.OWNER=p.OWNER AND a.OBJECT_NAME=p.OBJECT_NAME AND (a.OBJECT_TYPE=’PROCEDURE’ OR a.OBJECT_TYPE=’FUNCTION’) AND a.STATUS=’VALID’ ORDER BY p.OBJECT_NAME
Fetching 2 stored procedure(s) of the schema HR.
SELECT p.*, (SELECT max(s.TYPE) FROM ALL_SOURCE s WHERE s.OWNER=? AND s.NAME=p.OBJECT_NAME) as TYPE FROM ALL_PROCEDURES p, ALL_OBJECTS a WHERE p.OWNER=? AND a.OWNER=p.OWNER AND a.OBJECT_NAME=p.OBJECT_NAME AND (a.OBJECT_TYPE=’PROCEDURE’ OR a.OBJECT_TYPE=’FUNCTION’) AND a.STATUS=’VALID’ ORDER BY p.OBJECT_NAME
SELECT TEXT FROM ALL_SOURCE WHERE OWNER=? AND NAME=? ORDER BY LINE
Processing procedure ADD_JOB_HISTORY.
Processing procedure ADD_JOB_HISTORY.
Processing procedure SECURE_DML.
Processing procedure SECURE_DML.
Stored procedures fetched.
Fetch the number sequences of the schema HR.
SELECT COUNT(*) AS NUM FROM ALL_SEQUENCES s, ALL_OBJECTS a WHERE s.SEQUENCE_OWNER=? AND a.OWNER=s.SEQUENCE_OWNER AND a.OBJECT_NAME=s.SEQUENCE_NAME AND a.OBJECT_TYPE=’SEQUENCE’ AND a.STATUS=’VALID’
Fetch 3 sequence(s) of the schema HR.
SELECT s.SEQUENCE_NAME, s.MIN_VALUE, s.MAX_VALUE, s.INCREMENT_BY, s.CYCLE_FLAG, s.ORDER_FLAG, s.CACHE_SIZE, s.LAST_NUMBER FROM ALL_SEQUENCES s, ALL_OBJECTS a WHERE s.SEQUENCE_OWNER=? AND a.OWNER=s.SEQUENCE_OWNER AND a.OBJECT_NAME=s.SEQUENCE_NAME AND a.OBJECT_TYPE=’SEQUENCE’ AND a.STATUS=’VALID’ ORDER BY s.SEQUENCE_NAME
Sequences fetched.

Reverse engineering completed successfully.

**************************
* Get migration methods. *
**************************

Fetching available migration methods …
—————————————-

**********************
* Setup ignore list. *
**********************

Your current ignore list:
————————-

Oracle Table
None

Oracle View
None

Oracle Routine
None

Oracle Sequence
None

1. Accept ignore list
2. Add item to ignore list
3. Delete item from ignore list
0. Abort

Selection: 1

*************************
* Performing migration. *
*************************

Starting Oracle migration…
Migrating schema HR …

Migrating tables …
Migrating table COUNTRIES
Migrating table DEPARTMENTS
Migrating table EMPLOYEES
Migrating table JOBS
Migrating table JOB_HISTORY
Migrating table LOCATIONS
Migrating table REGIONS
Migrating views …
Migrating view EMP_DETAILS_VIEW
Migrating routines …
Migrating routine ADD_JOB_HISTORY
Migrating routine SECURE_DML
Migration completed.
Migration completed successfully.

***************************
* Generate target objects *
***************************

Create object online or write a SQL create script? (1. online, 2. script, 3. both, 0. abort) 2

Write create script.

**********************
* Bulk data transfer *
**********************

Write a SQL insert script? (1. yes, 2. no, 0. abort) 1

Execute bulk data transfer
————————–
Opening output script file …
Initializing source JDBC driver …
Initializing JDBC driver …
Driver class Oracle Thin JDBC Driver using SID
Opening connection …
Connection jdbc:oracle:thin:hr/hr@localhost:1521:XE
Processing schema HR …
Getting the number of rows of table COUNTRIES
SELECT count(*) AS total_num FROM “HR”.”COUNTRIES”
Transfering data from table COUNTRIES (25/25 rows)
SELECT “COUNTRY_ID”, “COUNTRY_NAME”, “REGION_ID” FROM “HR”.”COUNTRIES”
Open source resultset.
Started row transfer
Getting the number of rows of table DEPARTMENTS
SELECT count(*) AS total_num FROM “HR”.”DEPARTMENTS”
Transfering data from table DEPARTMENTS (27/27 rows)
SELECT “DEPARTMENT_ID”, “DEPARTMENT_NAME”, “MANAGER_ID”, “LOCATION_ID” FROM “HR”.”DEPARTMENTS”
Open source resultset.
Started row transfer
Getting the number of rows of table EMPLOYEES
SELECT count(*) AS total_num FROM “HR”.”EMPLOYEES”
Transfering data from table EMPLOYEES (107/107 rows)
SELECT “EMPLOYEE_ID”, “FIRST_NAME”, “LAST_NAME”, “EMAIL”, “PHONE_NUMBER”, “HIRE_DATE”, “JOB_ID”, “SALARY”, “COMMISSION_PCT”, “MANAGER_ID”, “DEPARTMENT_ID” FROM “HR”.”EMPLOYEES”
Open source resultset.
Started row transfer
100 rows transfered.
Getting the number of rows of table JOBS
SELECT count(*) AS total_num FROM “HR”.”JOBS”
Transfering data from table JOBS (19/19 rows)
SELECT “JOB_ID”, “JOB_TITLE”, “MIN_SALARY”, “MAX_SALARY” FROM “HR”.”JOBS”
Open source resultset.
Started row transfer
Getting the number of rows of table JOB_HISTORY
SELECT count(*) AS total_num FROM “HR”.”JOB_HISTORY”
Transfering data from table JOB_HISTORY (10/10 rows)
SELECT “EMPLOYEE_ID”, “START_DATE”, “END_DATE”, “JOB_ID”, “DEPARTMENT_ID” FROM “HR”.”JOB_HISTORY”
Open source resultset.
Started row transfer
Getting the number of rows of table LOCATIONS
SELECT count(*) AS total_num FROM “HR”.”LOCATIONS”
Transfering data from table LOCATIONS (23/23 rows)
SELECT “LOCATION_ID”, “STREET_ADDRESS”, “POSTAL_CODE”, “CITY”, “STATE_PROVINCE”, “COUNTRY_ID” FROM “HR”.”LOCATIONS”
Open source resultset.
Started row transfer
Getting the number of rows of table REGIONS
SELECT count(*) AS total_num FROM “HR”.”REGIONS”
Transfering data from table REGIONS (4/4 rows)
SELECT “REGION_ID”, “REGION_NAME” FROM “HR”.”REGIONS”
Open source resultset.
Started row transfer
Data bulk transfer finished.

Migration finished.
——————-

Se generan scripts Creates.sql e Inserts.sql, ¡estamos listos para la migracion!.
Ejecutar:
# mysql prueba < Creates.sql # mysql prueba < Inserts.sql

Ahora no queda mas que verificar los datos 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.