Tải bản đầy đủ - 0 (trang)
4-8. Sourcing Data from MySQL on a Regular Basis

4-8. Sourcing Data from MySQL on a Regular Basis

Tải bản đầy đủ - 0trang

Chapter 4 ■ SQL Databases


Use SSIS and use the MySQL ODBC driver to connect to the source database. The following describes how it

is done.


Launch the ODBC Data Source Administrator (odbcad32.exe or Control Panel ➤

System and Security ➤ Administrative Tools ➤ Data Sources ODBC). Click the System

DSN tab. You should see the dialog box shown in Figure 4-16.

Figure 4-16.  The ODBC Data Source Administrator


Click Add. Select the MySQL ODBC 3.51 driver (see Figure 4-17).



Chapter 4 ■ SQL Databases

Figure 4-17.  Adding a new System DSN using the ODBC Data Source Administrator


Click Finish. The ODBC Connector dialog box will appear. Enter the following


A data source name of your choosing. I am using MySQLAdam.

A description (if you want to add one)

The server name (or localhost)

The user you will be connecting as. I am using the root user.

The relevant password

The database to connect to

You should see something like Figure 4-18.




Chapter 4 ■ SQL Databases

Figure 4-18.  Configuring a MySQL ODBC DSN


Click Test to test the connection. Assuming that you receive confirmation that the

connection has been made, click OK twice to complete the DSN creation.


In a new or existing SSIS package, right-click in the Connection Managers tab and

select New Connection. . . (or right-click Connection Managers in the Solution

Explorer and select New Connection Manager).





Select the ODBC type from the list of providers, as shown in Figure 4-19.

Figure 4-19. Adding an ODBC connection manager in SSIS


Click Add. Select the System (or User) DSN that you just created (MySQLAdam in this

example). The dialog box should look like Figure 4-20.



Chapter 4 ■ SQL Databases

Figure 4-20.  Using an ODBC connection manager in SSIS


Click OK to complete the creation of the MySQL connection manager. Rename the

connection manager.


Add a Data Flow task. Double-click to edit.


Add an ODBC data source. Double-click to edit.


Set the ODBC connection manager to the name that you created in step 8.



Chapter 4 ■ SQL Databases


Set the data access mode to SQL command. Enter the SQL to determine the source

data. In this example, I suggest SELECT * FROM INFORMATION_SCHEMA.TABLES.


Click OK to confirm. Continue with your package creation, as described in Recipes 4-2

and 1-7, among others.

How It Works

There is not, at the time of writing, a MySQL-supported OLEDB provider. So the only solution is to import data using

ODBC. Obviously this is not ideal, but sometimes you have no choice. The disadvantages to this approach are

ODBC using the MySQL provider can be very slow.

Configuring the Microsoft OLEDB provider for ODBC drivers can be finicky.

The latest version of the MyODBC driver from the MySQL web site must be installed. Currently, it is 5.1.1, and

exists in both 32- and 64-bit versions. Enter MySQL ODBC in your favorite search engine. You should find the

relevant page on the MySQL site to download it.

One of the new features in SSIS 2012 is ODBC connection managers (thanks to Microsoft’s partnering

with Attunity), and this certainly makes life a little simpler as far as using ODBC is concerned. Once you have

configured the ODBC DSN, you can use it as the System DSN in the ODBC connection manager. The various

elements of the DSN are explained in Table 4-1.

Table 4-1.  The MySQL ODBC DSN



A data source name

You can choose any name you like, but obviously the simpler and

more memorable it is, the better.

A description

This is not compulsory, but can prove useful when returning to

DSNs months later when you have forgotten all about what it does.

The server name

This must be the exact name of the MySQL server.

The user you are connecting as

This user must have all the necessary rights to the source data.

The corresponding password

The database to connect to

Hints, Tips, and Traps

The DSN is limited to the selected database, so you will need to set up multiple DSNs for

ODBC connections to multiple databases.

To save a System DSN, you need to be running the ODBC Data Source Administration

Tool as a local system administrator (right-click the odbcad32.exe and select Run as


The current version of the MySQL ODBC driver will not list the available tables, so you

have to know the tables that you are looking for. If you do not have this information

on hand, then you can use the techniques given in Chapter 8 to discover it. Getting

source metadata can, however, be a lengthy process. So, once again, obtaining any

documentation about the source can save a lot of valuable time—your own!



Chapter 4 ■ SQL Databases

If the DSN contains the logon and password, you do not need to repeat them in SSIS.

If you cannot see the DSN in the list in the Connection Manager dialog box, then select

Use Connection String, and enter something like:

DRIVER = {MySQL ODBC 5.1 Driver};SERVER = localhost;DATABASE = AdamTest;UID = root

If you are working in a 64-bit environment with only the 32-bit driver installed, you will

need to set the Run64BitRuntime setting to False before running the package.

Once again, consider defining the connection managers at package level.

4-9. Importing MySQL Data on an “Ad Hoc” Basis


You want to import data from MySQL without the hassle of using SSIS.


Configure a linked server to link to a MySQL database. I’ll explain how it is done.


In SSMS, expand Server Objects. Then right-click Linked Servers and select New

Linked Server.


Enter a linked server name of your choosing. I am using MySQLLink here.


Click the Other Data Source radio button. Select “Microsoft OLEDB provider for

ODBC drivers” as the provider.


Enter a product name of your choosing.


Enter the System DSN that you created in the Recipe 4-8 (MySQLAdam) as the

Data Source.

You should see something like what’s shown in Figure 4-21.



Chapter 4 ■ SQL Databases

Figure 4-21.  Configuring a MySQL linked server


Click Security in the list on the left. Select the “Be made without using a Security

Context” radio button. The logon defined in the DSN provides the user ID and

password (see Figure 4-22).



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

4-8. Sourcing Data from MySQL on a Regular Basis

Tải bản đầy đủ ngay(0 tr)