Creating a Link Server to MYSQL from MSSQL

There might be situations where you need to apply CRUD  operations (
Create, Read, Update, Delete) on data residing in a MYSQL server database from SQL server. In order to do this you will need to create a link service from SQL server to MYSQL. The Steps are outlined below:

1. Install the MYSQL ODBC driver on the server with the MSSQL server installation.
2. Enter details for the MYSQL ODBC settings.
3. Create a link service to MYSQL using SSMS ( SQL Server Management Studio)
4. You will need an user account on the mysql server which can perform CRUD operations
 along with enable remote connections to the MYSQL installation. (See Troubleshooting steps below)
4. Test the connection.

Install MYSQL ODBC Driver Download  ( and install the latest MYSQL ODBC driver from the MYSQL server site. Select the version which corresponds to your installation of MSSQL usually the 64bit version. Note This needs to be done on the server with the MSSQL installed instance.

Once installed open Windows->Control Panel\All Control Panel Items\Administrative Tools\
Look for the ODBC  Datasource and double click. Verify that the driver is installed.

Click on the system tab and click Add

Select MYSQL ODBC  x.x Driver

Enter the details of your MYSQL installation. Pay attention to the name given to the data source name as this would be the name used under link services. Enter the IP Address of the MYSQL server, Username and password. Test the connection. If all goes well the allowed schemas would appear in the list of databases as shown below. Tick the boxes for multiple queries. Leave the rest of the tabs default.Could experiment later based on additional needs.

Troubleshooting Steps
If the above did not work. Verify that you have a telnet client installed on your computer.(Google this one  if needed as this is one of the setting under windows programs). Please verify that remote connection is enabled on the mysql server. To do this open a command prompt using cmd. (Open with Administrator rights). enter

c:\>telnet  x.x.x.x 3308

where the x.x.x.x is the IP address and 3308 is the default port MySQL listens too for requests. Also check any firewall settings.

You are now done with the ODBC setup.

Create a Link Service on your MSSQL

To do this open my SSMSO with sa privileges and click on Server Objects - > Linked Servers
Right click to create a new Link service.

Enter the following information. Note the data source name is the ODBC name given during driver setup. Verify the provider matches as below:

Select the security tab and enter the MYSQL user name and password.

 Server option as below

You are done.  If the setup was successful, refresh the screen F5 then expand the MYSQL object which should display the database and table names as below:

Writing a query to access the MYSQL Data. Note some fields are not compatible with MSSQL and will need a cast to convert this to a varchar type. I will explain this later in another post. For now, open a New Query window and enter the following select statement.
select * from openquery(MYSQL,'select * from')

There should be a result similar to the following

Your Link server is up and running. See My next post on doing insert, update and delete statements.


Popular posts from this blog

Using SSRS web services to render a report as a PDF

Integrating MIGS eGate Payment gateway using C# for Oz businesses (Server-Hosted Payment method)

Troubleshooting Database Mail: General steps