MySQL As Linked Server

Introduction

As a develeper and DBA, sometimes you need to deal all kinds of databases. We have been getting a lot of inquiries and requests to make MySQL OLE DB Provider capable for developers and/or DBAs like you to setup MySQL as linked server in MS SQL Server. After reading this page, we hope you will know:

Setup Linked Server

If you have done some kind of linked server setup, it shall be easy for you. Here are some steps you need to follow in order to setup MySQL as Linked Server using MySQL OLE DB Provider.

If you have done some kind of linked server setup, it shall be easy for you. Here are some steps you need to follow in order to setup MySQL as Linked Server using MySQL OLE DB Provider.

  • Install MySQL OLE DB Provider on SQL Server 2005 database server
  • Activate the provider you just installed
  • Open Microsft SQL Server Management Studio and connect to SQL Server 2005
  • In the Object Explorer, expend Server Objects (F1)
  • Right click on Linked Servers, select New Linked Server, you see the New Linked Server form (F2)
MS SQL Server Management Studio
F1. Microsoft SQL Server Management Studio

EXEC master.dbo.sp_MSset_oledb_prop N'OleMySql.MySqlSource', 'AllowInProcess', 1 GO

Query MySQL As Linked Server

Select Statement

select * from openquery(MYLINKEDSVR, 'select * from tb_alltypes')

Insert Statement

insert openquery (MYLINKEDSVR, 'select id, name, address from cust where id=0')

values(6300, 'Greg Oden', 'Rose Garden, Cherry City, OR')

Delete Statement

delete from openquery(MYLINKEDSVR, 'select id, name, address from cust') where id=4200

Update Statement

update openquery(MYLINKEDSVR, 'select id, name, address from cust order by id')

set id = 6001 where id=3201

Limitation

The current implementation regarding linked server works with MySQL 5.0 or newer. There is no plan to make it also work with MySQL 4.1 or older.
To delete/update records, the select statement inside openquery must include either primary key or unique index