Create a linked server to MySQL from SQL Server


By:   |   Updated: 2016-12-09   |   Comments (5)   |   Related: More > Linked Servers


Problem

SQL Server Linked Servers are used to query remote databases and in this tip we will learn how to configure a linked server for a MySQL server from SQL Server.

Solution

Here are the steps to create a linked server to a MySQL server.

First we need to create an ODBC data source to the MySQL server on the box where SQL Server is installed. In my case I have MySQL and SQL Server installed on the same box.

Go to Start > Administrative Tools > Data Sources (ODBC) > System DSN and select Add

ODBC Connections

Select the MySQL ODBC driver.

mysql driver in ODBC

Give the data source name of your choice. Input the TCP/IP Server address, port, user and password for the MySQL server and click OK.

Connection Details for MySQL

Now open SQL Server Management Studio (SSMS) and login to SQL Server.

In the Object Explorer for the SQL Server instance, go to Server Objects and right click and select New > Linked Server...

Give the linked server a name of your choice.

Under the Provider drop down select Microsoft OLEDB Provider for ODBC Drivers.

Input the Product name as MySQL and enter the data source name which was created earlier.

New Linked Serverin SQL Server Management Studio

Go to the Security tab and enter the remote login and password (on the bottom) and click OK.

Security Properties for a Linked Server

Now test the linked server which was just created and you should be able to see the objects for the MySQL data source (note I hid the names of the tables from my server in the image below).

Test Linked Server in SQL Server Management Studio

Next Steps



Last Updated: 2016-12-09


get scripts

next tip button



About the author
MSSQLTips author Ranga Babu Ranga Babu is a SQL Server DBA with experience on performance tuning and high availability.

View all my tips
Related Resources





Comments For This Article




Thursday, September 26, 2019 - 6:14:22 AM - Shazli Back To Top (82574)

i have followed all step but it gives error one thing i want to clear is in security tab which server credentials i should use i have entered MySQL user and password thats root


Thursday, August 23, 2018 - 11:12:20 AM - Kumar Back To Top (77291)

 Thanks. it worked.  even though I see all the tables but I do not see columns in any table that means no data. Am I missing something?

am using MySQL 5.7 on AWS and SSMS 14.0


Thursday, November 23, 2017 - 12:08:44 PM - Adrian Back To Top (70136)

 Hi Ranga,

great post, it saves me precious time,

 

thank you!

 


Monday, July 17, 2017 - 10:44:33 AM - Jerry Francis Back To Top (59476)

One piece missing:   How to perform a select statement for the new link.  MySQL has different structure from MSSQL (schema=database).  As a SQL Server admin, I have no idea how MySQL works.  Would be great if you could provide.


Friday, May 12, 2017 - 12:49:08 PM - Toby Back To Top (55700)

 Thanks a million for this well written guide. Worked a treat!

 



download





Recommended Reading

How to setup linked servers for SQL Server and Oracle 64 bit client

Querying Active Directory Data from SQL Server

Creating a SQL Server Linked Server to SQLite to Import Data

Access MySQL data from SQL Server via a Linked Server

Understanding SQL Server Linked Servers








get free sql tips
agree to terms