Export data from MySQL to SQL Server

Problem

Many people want to create a customized migration process using SQL Server Integration Services (SSIS), but it is hard to start working with heterogeneous databases like MySQL, Postgres, DB2, etc. Check out this tip to learn about how to import data from heterogeneous databases like MySQL to SQL Server.

Solution

In this example, the database used to import data from is the Test Database in MySQL which is installed by default. We will import data from MySQL to SQL Server using SQL Server Integration Services.

MySQL Prerequisites

To follow the steps in this tip it is necessary to have the following software installed:

Let’s create a table in MySQL called myTable with a column called myColumn then insert some data in the table:

use MySQL;
create table myTable(myColumn varchar(20));
insert into myTable(myColumn) values("John");
insert into myTable(myColumn) values("Jane");
insert into myTable(myColumn) values("Arnold");
insert into myTable(myColumn) values("Jessica");

Using SQL Server Integration Services to import data from MySQL to SQL Server

Here are the steps to create the SSIS project:

  1. Start SQL Server Business Intelligence Development Studio and start an Integration Service Project.
  2. Create a new project and select Integration Services Project.
  3. microsoft visual studio
  4. In the toolbox drag and drop the Data flow task onto the design surface of the Control Flow tab.
  5. data flow task
  6. Double click in the Data Flow task in the Design pane.
  7. data flow task
  8. In the Data Flow tab, drag and drop the ADO.NET Source and ADO.NET Destination to the design pane, join both tasks with the green arrow.
  9. destination
  10. Go to Windows start menu | Administrative tools | Data Sources (ODBC) and click the Add button.
  11. administrator
  12. Select the MySQL ODBC driver and press Finish.  Please note this driver is installed with the connector specified in the prerequisites section above.
  13. create new data source
  14. Specify the Data Source Name. e.g. “MySQL conn”.
  15. Specify the TCP/IP Server.  It can be the IP or the localhost if the machine used is the local machine.
  16. Specify the user, in this case root and the password.  Ask to the MySQL administrator if you do not know the user database password).
  17. Select the MySQL database.
  18. connector
  19. Congratulations! You have a ODBC connection. Now let’s use it in SSIS and return to the SSIS project.
  20. Double click in the ADO Net Source and press the new button.
  21. source editor
  22. Press the new button again to add a connection.
  23. connection manager
  24. This is important, in the provider, select the .NET Providers\ODBC Data Provider. The ODBC connection will be displayed. Select the connection created in step 8 and press OK.
  25. connection manager
  26. In the ADO.NET source editor, in Data access mode, select SQL Command.
  27. In the SQL command test, write “select * from myTable” and press OK.  In this step you are writing the query to access to MySQL table created at the beginning.
  28. source editor
  29. Double click in the ADO.NET Destination task and in the Connection manager press New.
  30. destination editor
  31. In the Configure ADO.NET Connection Manager press new again.
  32. manager
  33. In the connection manager specify the SQL Server instance name (in this example the localhost is a dot) and select a Database where you want to import the MySQL Database and press OK.  In this example the Adventureworks database is used, but any database can be used instead.
  34. adventure works
  35. In the ADO.NET Destination Editor, click new in the Use a table or view option.
  36. destination editor
  37. In the Create Table box, use this code:
  38.  CREATE TABLE "myTable" ( 
      "myColumn" nvarchar(20) 
    ) 
    create table
  39. In the ADO.NET Destination Editor, click the Mapping page and press OK.
  40. destination editor
  41. We are ready. Press the Start Debugging icon as shown below.
  42. start debugging
  43. You will see the tasks in green which means the tasks were completed successfully with the associated row count.
  44. net destination
  45. Last, but not least, open the Microsoft SQL Server Management Studio and verify in the instance and database used that the new table myTable was created and also that it contains the data specified.
  46. management studio

Next Steps

Leave a Reply

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