• Save
Database migration
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,014
On Slideshare
1,014
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Database Migration Wizard:Table of Contents(1) ODBC Libraries :MySQL Workbench provides the ability to migrate ODBC compliant databases toMySQL. The MySQL Workbench Migration Wizard was added in MySQLWorkbench 5.2.41.Convert (migrate) different database types, including MySQL, across serversConvert tables and copy data, but will not convert stored procedures,views, or triggersAllows customization and editing during the migration processWorks on Linux, Mac OS X, and Microsoft WindowsThis is not an exhaustive list. The following sections discuss these and additionalmigration capabilities. Set up may be the most challenging aspect of using theMySQL Workbench Migration Wizard. There is the installation section, whichdescribes setting up ODBC requirements for Linux, Mac OS X, and MicrosoftWindows, and the Database Product Specific Notes section that references setupconditions for each RDBMS.The MySQL Workbench Migration Wizard uses ODBC to connect to a sourcedatabase, except for MySQL. You will need the ODBC driver installed thatcorresponds to the database you want to migrate from. For example, PostgreSQLcan be migrated with the psqlodbc ODBC driver; Microsoft SQL Server can bemigrated using the native Microsoft SQL Server driver on Windows or withFreeTDS on Linux and Mac OS X.The following diagram shows the general components involved in an ODBCconnection:
  • 2. MySQL Workbench migration installation diagram(i) ODBC LibrariesLinux :iODBC: MySQL Workbench binaries provided by Oracle already include iODBC andno additional action is required. If you compile it yourself, you must install iODBCor unixODBC. iODBC is recommended. You can use the iODBC library provided byyour distribution.pyodbc: is the Python module used by MySQL Workbench to interface with ODBC,and may be used to migrate ODBC compliant databases such as PostgreSQL andDB2. In Windows and Mac OS X, it is included with Workbench. In Linux, binariesprovided by Oracle also include pyodbc.If youre using a self-compiled binary, make sure you have the latest version, andthat it is compiled against the ODBC manager library that you chose, whether it isiODBC or unixODBC. As of version 3.0.6, pyodbc will compile against unixODBC bydefault. If you are compiling against iODBC then you must perform the followingsteps:
  • 3. 1. Install the development files for iODBC. Usually you just need to install thelibiodbc-devel or libiodbc2-dev package provided by your distribution.2. In the pyodbc source directory, edit the setup.py file and around line 157,replace the following line: settings[libraries].append(odbc) withsettings[libraries].append(iodbc)3. Execute the following command as the root user: CFLAGS=`iodbc-config --cflags` LDFLAGS=`iodbc-config --libs` python setup.py install.(ii) ODBC Drivers :For each RDBMS, you need its corresponding ODBC driver, which must also beinstalled on the same machine that MySQL Workbench is running on. This driver isusually provided by the RDBMS manufacturer, but in some cases they can also beprovided by third party vendors or open source projects.Operating systems usually provide a graphical interface to help set up ODBCdrivers and data sources. Use that to install the driver (i.e., make the ODBCManager "see" a newly installed ODBC driver). You can also use it to create a datasource for a specific database instance, to be connected using a previouslyconfigured driver. Typically you need to provide a name for the data source (theDSN), in addition to the database server IP, port, username, and sometimes thedatabase the user has access to.If MySQL Workbench is able to locate an ODBC manager GUI for your system, a“Plugins”,”Start ODBC – Administrator” menu item be present under the Pluginsmenu as a convenience shortcut to start it.Linux: There are a few GUI utilities, some of which are included withunixODBC. Refer to the documentation for your distribution. iODBCprovides iodbcadm-gtk. Official binaries of MySQL Workbench include itand it can be accessed through the “Plugins”, “Start ODBC Administrator”menu item.Mac OS X: You can use the ODBC Administrator tool, which is provided as aseparate download from Apple. If the tool is installed in the/Applications/Utilities folder, you can start it through the “Plugins”, “StartODBC Administrator” menu item.
  • 4. Microsoft Windows: You can use the Data Sources (ODBC) tool underAdministrative Tools. And it can be started through the “Plugins”, “StartODBC Administrator” menu item.ODBC Driver architectureSince the ODBC driver needs to be installed in the client side, you will need anODBC driver that supports your client’s operating system and architecture. Forexample, if you are running MySQL Workbench from Linux x64, then you need aLinux x64 ODBC driver for your RDBMS. In Mac OS X, MySQL Workbench is built asa 32-bit application, so you need the 32-bit drivers.(2) Migration Overview :(i) A visual guide to performing a database migration(ii) Migrating from supported databases(iii) Migrating from unsupported (generic) databasesThe Migration Wizard performs the following steps when migrating a database toMySQL:1. Connects to the source RDBMS and retrieves a list of availabledatabases/schemas.2. Reverse engineers selected database/schemas into a internalrepresentation specific to the source RDBMS. This step will also performthe renaming of objects/schemas depending on the type of object namemapping method that is chosen.3. Automatically migrates the source RDBMS objects into MySQL specificobjects.a. Target schema objects are created.b. Target table objects are created.i. Columns for each table are copied.A. Datatypes are mapped to MySQL datatypes.B. Default values are mapped to a MySQL supporteddefault value, if possible.ii. Indexes are converted.iii. Primary Keys are converted.iv. Triggers are copied, and commented out if the source is notMySQL.
  • 5. c. Foreign Keys for all tables (of all schemas) are converted.d. View objects are copied, and commented out if the source is notMySQL.e. Stored Procedure and Function objects are copied, and commentedout if the source is not MySQL.4. Provides an opportunity to review the changes, for editing and correctingerrors in the migrated objects.5. Creates the migrated objects in the target MySQL server. If there are errors,you can return to the previous step and correct them, and retry the targetcreation.6. Copy data of the migrated tables from the source RDBMS to MySQL.MySQL Workbench provides support for migrating from some specific RDBMSproducts. The Migration Wizard will provide the best results when migrating fromsuch products. However, in some cases, other unsupported database productscan also be migrated by using its Generic database support, as long as you havean ODBC driver for it. In this case, the migration will be less automatic, but shouldstill work nonetheless.(i) A visual guide to performing a database migration (GUI with screen shots)http://dev.mysql.com/doc/workbench/en/wb-migration-overview-steps.html(ii) Migrating from supported databases:When a supported RDBMS product is being migrated, the MySQL WorkbenchMigration Wizard will automatically convert as much information as it can, butyou may still be required to manually edit the automatically migrated schema fordifficult cases, or when the default mapping is not as desired.Generally speaking, only table information and its data are automaticallyconverted to MySQL. Code objects such as views, stored procedures, and triggers,are not. But supported RDBMS products will be retrieved and displayed in thewizard. You can then manually convert them, or save them for converting at alater time.
  • 6. The following RDBMS products and versions are currently tested and supportedby the MySQL Workbench Migration Wizard, although other RDBMS products canalso be migrated with Section 10.2.3, “Migrating from unsupported (generic)databasesMicrosoft SQL Server 2000Microsoft SQL Server 2005Microsoft SQL Server 2008Microsoft SQL Server 2012MySQL Server 4.1 and greater as the source, and MySQL Server 5.1 andgreater as the targetPostgreSQL 8.0 and greaterSybase Adaptive Server Enterprise 15.x and greater(iii) Migrating from unsupported (generic) databases:Most ODBC compliant databases may be migrated using the generic databasesupport. In this case, code objects will not be retrieved from the source database;only tables and data.When using the generic support, column datatypes are mapped using thefollowing steps:1. It searches for the first entry in the Generic Datatype Mapping Table for thesource type name. If the length/scale ranges of the entry matches thesource column, it will pick that type. Otherwise, it continues searching.2. If no matches were found in the generic table, then it tries to directly mapthe source type to a MySQL type of the same name.3. If the source type name doesnt match any of the MySQL datatypes, thenitwill not be converted and an error is logged. You can then manually specifythe target datatype in the Manual Object Editing step of the wizard.(3) Conceptual DBMS equivalents :Handling Microsoft SQL Server and MySQL structural differences:A Microsoft SQL Server database is made up of one catalog and one or moreschemata. MySQL only supports one schema for each database (or rather, aMySQL database is a schema) so this difference in design must be planned for.The Migration Wizard must know how to handle the migration of schemata for
  • 7. the source (Microsoft SQL Server) database. It can either keep all of the schemataas they are (the Migration Wizard will create one database per schema), or mergethem into a single MySQL database. Additional configure options include: eitherremove the schema names (the Migration Wizard will handle the possible namecollisions that may appear along the way), and an option to add the schema nameto the database object names as a prefix.FYI…..http://dev.mysql.com/doc/workbench/en/wb-migration-database-concepts.html(4) Microsoft SQL Server migration(i) Preparations(ii) Drivers(iii) Connection Setup(iv) Microsoft SQL Server Type MappingIntroduction:The MySQL Workbench Migration Wizard is tested against the following MicrosoftSQL Server versions: 2000, 2005, 2008, and 2012.(i) Preparations:To be able to migrate from Microsoft SQL Server, ensure the following:The source SQL Server instance is running, and accepts TCP connectionsYou know the IP and port of the source SQL server instance. If you will bemigrating using a Microsoft ODBC driver for SQL Server (the default inWindows), you will need to know the host and the name of the SQL Serverinstance.Make sure that the SQL Server is reachable from where you will be runningMySQL Workbench. More specifically, check the firewall settings.Make sure that the account you will use has proper privileges to thedatabase that will be migrated.
  • 8. (ii) Drivers:(I) Windows(II) Linux(I) Windows:Microsoft Windows XP or newer includes an ODBC driver for Microsoft SQLServer, so there are no additional actions required.(II) Linux:Setting up drivers on Linux.FreeTDS:FreeTDS version 0.92 or greater is required. Note that many distributions shipolder versions of FreeTDS, so it may need to be installed separately. Additionally,the FreeTDS version provided by distributions may also be compiled for the wrongODBC library (usually to unixODBC instead of iODBC, which MySQL Workbenchuses). Because of that you will probably need to build this library yourself.Important: using FreeTDS with iODBCWhen compiling FreeTDS for use with iODBC (the default with the officialbinaries), you must compile it with the --enable-odbc-wide command line optionfor the configure script. Failing to do so will result in crashes and otherunpredictable errors.A script is provided to compile FreeTDS using the options required for MySQLWorkbench You can find it in the /usr/share/mysql-workbench/extras/build_freetds.sh directory in Linux orMySQLWorkbench.app/Contents/SharedSupport/build_freetds.sh folder in theMac. To use it, follow these steps:1. Make sure you have the iODBC headers installed. In Linux, install thelibiodbc-devel or libiodbc2-dev package from your distribution. In Mac OSX, the headers come with the system and no additional action is requiredfor this step.2. mkdir ~/freetds to create a directory - within the users home directory.3. Copy the build_freetds.sh script to ~/freetds4. Get the latest FreeTDS sources from ftp://ftp.freetds.org/pub/freetds/ andplace it in the ~/freetds directory. Make sure to get version 0.92 or newer.
  • 9. 5. cd ~/freetds6. Execute build_freetds.sh7. After compilation is done, install it using make install from the path givenby the script.8. Install the driver in the ODBC Administrator, to make the ODBC subsystemto recognize it. The name of the driver file is libtdsodbc.so and is located in/usr/lib or /usr/local/libOnce the driver is installed, you should be able to create data sources for it fromthe ODBC Administrator GUI. Protocol version selection in FreeTDSWhen using FreeTDS, TDS_VERSION=7.0 is needed in the connection string. If youpick a FreeTDS specific connection method option in the connection dialog, thatoption is added to the connection string automatically.(III) Connection Setup:Using an ODBC Data Source ,Using Connection Parameters(IV) Microsoft SQL Server Type Mapping:http://dev.mysql.com/doc/workbench/en/wb-migration-database-mssql-typemapping.html(5) PostgreSQL migration :(i) Preparations(ii) Drivers(iii) Connection Setup(iv) PostgreSQL Type MappingNative support for PostgreSQL 8.x and 9.x was added in MySQL Workbench5.2.44. MySQL Workbench versions prior to this would migrate PostgreSQL usingthe generic migration support.(i) Preparations:(I) Microsoft Windows(II) Linux
  • 10. (III) Mac OS XBefore proceeding, you will need the following:Follow the installation guide for installing iODBC on your system.Access to a running PostgreSQL instance with privileges to the database youwant to migrate, otherwise known as the "source database." The MigrationWizard officially supports PostgreSQL 8.0 and above, although olderversions may work.Access to a running MySQL Server instance with privileges to the databaseyou want to migrate. The Migration Wizard officially supports MySQL 5.0and above.MySQL Workbench 5.2.44 or newer.(I) Microsoft Windows:Download and install the MSI package for psqlODBC. Choose the newest file fromhttp://www.postgresql.org/ftp/odbc/versions/msi/, which will be at the bottomof the downloads page. This will install psqlODBC on your system and allow you tomigrate from Postgresql to MySQL using MySQL Workbench.(II) Linux :After installing iODBC, proceed to install the PostgreSQL ODBC drivers.Download the psqlODBC source tarball file fromhttp://www.postgresql.org/ftp/odbc/versions/src/. Use the latest versionavailable for download, which will be at the bottom of the downloads page. Thefile will look similar to psqlodbc-09.01.0200.tar.gz. Extract this tarball to atemporary location, open a terminal, and cd into that directory. The installationprocess is:shell> cd the/src/directoryshell> ./configure --with-iodbc --enable-pthreadsshell> makeshell>sudo make installVerify the installation by confirming that the file psqlodbcw.so is in the/usr/local/lib directory.
  • 11. Next, you must register your new ODBC Driver.Open the iODBC Data Source Administrator application by either executingiodbcadm-gtk in the command-line, or by launching it from the Overview page ofthe MySQL Workbench Migration Wizard by clicking the Open ODBCAdministrator button. Go to the ODBC Drivers tab in the iODBC Data SourceAdministrator. It should look similar to:Figure: The iODBC Data Source AdministratorClick Add a driver then fill out the form with the following values:Description of the driver: psqlODBCDriver file name: /usr/local/lib/psqlodbcw.soSetup file name: No value is needed hereAnd lastly, clicking OK will complete the psqlODBC driver registration.
  • 12. (III) Mac OS X :To compile psqlODBC on Mac OS X, you will need to have Xcode and its"Command Line Tools" component installed on your system, as this includes therequired gcc compiler. Xcode is free, and available from the AppStore. And afterinstalling Xcode, open it and go to Preferences, Downloads, Components, andthen install the "Command Line Tools" component.Download the psqlODBC source tarball file fromhttp://www.postgresql.org/ftp/odbc/versions/src/. Use the latest versionavailable for download, which will be at the bottom of the downloads page. Thefile will look similar to psqlodbc-09.01.0200.tar.gz. Extract this tarball to atemporary location, open a terminal, and cd into that directory. The installationprocess is:shell> cd the/src/directoryshell> ./configure --with-iodbc --enable-pthreadsshell> CFLAGS="-arch i386 -arch x86_64" makeshell>sudo make install(ii) Drivers:If you are compiling psqlodb, first configure with the --without-libpq option.(iii) Connection Setup:After loading the Migration Wizard, click on the Start Migration button in theOverview page to begin the migration process. You will first connect to the sourcePostgreSQL database. Here you will provide the information about the PostgreSQLRDBMS that you are migrating from, the ODBC driver that will be used for themigration, and all of the parameters required for the connection. The name of theODBC driver is the one you set up when you registered your psqlODBC driver withthe driver manager.Opening the Database System dropdown will reveal each RDBMS that issupported on your system. Select PostgreSQL from the list. Below that is the
  • 13. Stored Connection dropdown, which is optional. Stored connections will be listedhere, which connections are saved after defining a connection with the Storeconnection for future use as checkbox enabled.The three Connection Method options are:ODBC (manually entered parameters): Each parameter, like a username, isdefined separatelyODBC Data Source: For pre-configured data sources (DSN)ODBC (direct connection string): A full ODBC connection stringNote :The psqlODBC driver does not allow a connection without specifying a databasename. The migration process is similar to other databases.(iv) PostgreSQL Type Mapping:http://dev.mysql.com/doc/workbench/en/wb-migration-database-postgresql-typemapping.html(6) MySQL migration:IntroductionNotes about copying MySQL, and what you can do with it.(7) Using the MySQL Workbench Migration Wizard :(i) Connecting to the databases :A connection is made to the source and target database servers.Source Connection Setup:The Source Connection offers the MySQL, Microsoft SQL Server, and GenericRDBMS database system options. This selection determines the availableParameters and Advanced configuration options. This connection definition maybe saved using the Store connection for future use as option, and there is also theTest Connection option.
  • 14. Target Connection SetupThe MySQL Server that will be home to the newly migrated database.(ii) Schemata Retrieval and Selection :Fetch Schemata ListThe names of available schemas will be retrieved from the source RDBMS. Theaccount used for the connection will need to have appropriate privileges forlisting and reading the schemas you want to migrate. Target RDBMS connectionsettings will also be validated.The steps that are performed include: connects to the source DBMS, checks theconnection, and retrieves the schema list from the source.Schemata SelectionSelect the schemata that you want to migrate.(iii) Reverse Engineering :This is an automated step, where the actions include: Connect to the sourceDBMS, Reverse engineer the selected schemata, and perform post-processing ifneeded.(iv) Object Selection :By default, all table objects will be migrated. Use the “Show Selection” button inorder to disable individual table objects from being migrated.(v) Migration :Reverse engineered objects from the source RDBMS will be automaticallyconverted to MySQL compatible objects. Default data type and default columnvalue mappings will be used. You will be able to review and edit the generatedobjects and column definitions in the next step.The steps performed include migrating the selected objects, and generating theSQL CREATE statements.
  • 15. (vi) Manual Editing :The migrated objects may be reviewed and edited here. You can manually editthe generated SQL before applying them to the target database. Target schemasand tables may be renamed, and column definitions may be changed, by double-clicking on them.By default, the “All Objects” View is loaded. Other View options include“Migration Problems” and “Column Mappings”.All Objects: Shows all objects, which can also be edited by double-clicking.Migration Problem: Will list all of the migration problems, or report that nomapping problems were found.Column Mappings: Displays all of the schema columns, which may also beedited. There is an advanced “Show Code and Messages” option thatdisplays the SQL CREATE script for the selected object.(vii) Target Creation Options :Defines addition settings for the target schema.Configuration options include:Create schema in target RDBMS:Create a SQL script file:An option to keep the schemata if they already exist. Objects that alreadyexist will not be recreated or update.(viii) Schema Creation :The SQL scripts generated for the migrated schema objects will now be executedin the target database. You can monitor execution in the logs; if errors exist thenthey will be fixed in the next step. Table data will be migrated in a later step aswell.This is an automated step, where the actions include: Create Script File, Connectto Target Database, and Create Schemata and Objects.
  • 16. (ix) Create Target Results :Scripts to create the target schemas were executed, but the data has not yet beenmigrated. This step allows reviewing a creation report. If there are any errors,then you can manually fix the scripts and click “Recreate Objects” to retry theschema creation or return to the Manual Editingpage to correct them there, andthen retry the target creation.To edit, first select the object, and then the SQL CREATE Script will be shown forthe selected object. Edit it there, then press “Apply” to save.(x) Data Migration Setup :Provides additional options for data transfer, including the ability to set up ascript to automate this transfer in the future.(xi) Bulk Data Transfer :The transfer is executed here.(xii) Migration Report :Displays the final report that can be reviewed to ensure a proper migration wasexecuted.