1. 从MySQL网站下载最新的MySQL ODBC驱动:http://dev.mysql.com/downloads/connector/odbc/ 目前的版本是5.3.2
2. 在SQL Server所在的服务器安装
3. 在SQL Server建立Linkserver,可通过如下脚本实现:
[sql] view plain copy
- USE [master]
- GO
-
- EXEC master.dbo.sp_addlinkedserver @server = N'linkmysql',
- @srvproduct = N'mysql123', @provider = N'MSDASQL',
- @provstr = N'Driver={MySQL ODBC 5.3 Unicode Driver};Server=localhost;Database=test;User=root;Password=123456;',
- @catalog = N'test';
之后可以通过OPENQUERY的方式调用MySQL的数据:
[sql] view plain copy
- INSERT INTO OPENQUERY(linkmysql, 'select * from test.t1') VALUES ( 1 );
- SELECT * FROM OPENQUERY(linkmysql, 'select * from test.t1');
-
- UPDATE OPENQUERY(linkmysql, 'select * from test.t1') SET a = 2;
- SELECT * FROM OPENQUERY(linkmysql, 'select * from test.t1');
-
- DELETE FROM OPENQUERY(linkmysql, 'select * from test.t1');
- SELECT * FROM OPENQUERY(linkmysql, 'select * from test.t1');