博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在SQL Server Management Studio中创建和配置链接服务器以连接到MySQL
阅读量:2518 次
发布时间:2019-05-11

本文共 8334 字,大约阅读时间需要 27 分钟。

This article will guide you with all the necessary steps to successfully create a linked server in SSMS to connect to the MySQL database.

本文将指导您完成在SSMS中成功创建链接服务器以连接到MySQL数据库的所有必要步骤。

This article is divided in three sections:

本文分为三个部分:

  • driver for MySQL 驱动程序
  • Configure ODBC driver to connect to MySQL database

    配置ODBC驱动程序以连接到MySQL数据库
  • Create and configure a Linked Server using ODBC driver

    使用ODBC驱动程序创建和配置链接服务器

为MySQL安装ODBC驱动程序 (Installing ODBC driver for MySQL)

ODBC stands for Open Database Connectivity (Connector). It’s developed by Microsoft in the 1990s. Generally, that is API (Application Programming Interface) for accessing database systems.

ODBC代表开放式数据库连接(连接器)。 它由Microsoft在1990年代开发。 通常,这是用于访问数据库系统的API(应用程序编程接口)。

For non-Windows OS, (Java Database Connectivity) is used.

对于非Windows操作系统,使用 (Java数据库连接)。

Before installing the ODBC driver for MySQL on Windows, make sure that Microsoft Data Access Components (MDAC) are up to date and the is installed on your system.

在Windows上为MySQL安装ODBC驱动程序之前,请确保Microsoft数据访问组件(MDAC)是最新的,并且系统上已安装 。

Under this , the MySQL ODBC drivers for Windows can be downloaded and installed. There are two versions of MySQL ODBC drivers for Windows that can be installed, depending on which application will be used with:

在此 ,可以下载和安装WindowsMySQL ODBC驱动程序。 可以安装两个版本的Windows版MySQL ODBC驱动程序,具体取决于将与哪个应用程序一起使用:

MySQL Connection/ODBC for Windows
  • mysql-connector-odbc-8.0.17-win32.msi for 32-bit application

    用于32位应用程序的mysql-connector-odbc-8.0.17-win32.msi
  • mysql-connector-odbc-8.0.17-winx64.msi for 64-bit application

    用于64位应用程序的mysql-connector-odbc-8.0.17-winx64.msi

Installation of MySQL ODBC driver for Windows is straightforward. Double-click on the downloaded file, the Welcome dialog will appear:

WindowsMySQL ODBC驱动程序的安装非常简单。 双击下载的文件,将出现“ 欢迎”对话框:

MySQL Connection/ODBC wizard - Welcome dialog

After pressing the Next button, the License Agreement dialog appears. If you agree with the license agreement, press the I accept the terms in the license agreement radio button and click the Next button:

按“ 下一步”按钮后,将出现“ 许可协议”对话框。 如果您同意许可协议,请按“ 我接受许可协议中的条款”单选按钮,然后单击“ 下一步”按钮:

MySQL Connection/ODBC wizard - License Agreement dialog

Under the Setup Type dialog, choose the Typical radio button and press the Next button:

在“ 安装类型”对话框下,选择“ 典型”单选按钮,然后按“ 下一步”按钮:

MySQL Connection/ODBC wizard - Setup Type dialog

The Ready to Install the Program dialog shows what and where will be installed. Press the Install button to install ODBC driver:

准备安装程序”对话框显示将要安装的内容和位置。 按下安装按钮以安装ODBC驱动程序:

MySQL Connection/ODBC wizard -Ready to Install the Program dialog

After a couple of seconds, installation of ODBC driver for MySQL is finished:

几秒钟后,用于MySQL的ODBC驱动程序的安装完成

MySQL Connection/ODBC wizard - Wizard Completed dialog

To confirm that ODBC driver for MySQL is installed on machine can be checked from Control Panel:

要确认是否已在计算机上安装了MySQL的ODBC驱动程序,可以从“控制面板”中进行检查:

Check is it the ODBC driver for MySQL installed on machine via Control Panel

Another way to check is via the dialog box:

另一种检查方法是通过“ 对话框:

Check is it the ODBC driver for MySQL installed on machine via ODBC Data Source Administrator

Under the Drivers tab of the ODBC Data Source Administrator dialog box, check if the MySQL ODBC Drivers exist:

在“ ODBC数据源管理器”对话框的“ 驱动程序”选项卡下,检查MySQL ODBC驱动程序是否存在:

Check is it the ODBC driver for MySQL installed on machine via ODBC Data Source Administrator and Drivers tab

配置ODBC驱动程序以连接到MySQL数据库 (Configure ODBC driver to connect to MySQL database)

To connect to MySQL database using ODBC drivers, in the ODBC Data Source Administrator dialog, under the System DSN tab, press the Add button:

要使用ODBC驱动程序连接到MySQL数据库,请在“ ODBC数据源管理器”对话框的“ 系统DSN”选项卡下,按“ 添加”按钮:

System DSN tab of the ODBC Data Source Administrator dialog

In the Create New Data Source dialog, select the MySQL ODBC Driver and press the Finish button:

在“ 创建新数据源”对话框中,选择“ MySQL ODBC驱动程序” ,然后按“ 完成”按钮:

Create New Data Source to connect to MySQL

In the MySQL Connector/ODBC Data Source Configuration dialog:

在“ MySQL连接器/ ODBC数据源配置”对话框中:

Connector/ODBC configuration dialog to connect to MySQL database

For the Data Source Name text box, enter the data source name by choice. In the Description text box, enter the description of the data source if needed.

对于“ 数据源名称”文本框,通过选择输入数据源名称。 如果需要,在“ 描述”文本框中,输入数据源的描述。

Use the or connection method to connect to MySQL by selecting appropriate radio button.

通过选择适当的单选按钮,使用或连接方法连接到MySQL。

In this example, the TCP/IP Server radio button is selected. In the text box, type a host name or IP address of the MySQL server. By default, the host name is localhost and IP address is 127.0.0.1. In the Port box, enter the TCP/IP port on which the MySQL server is listed. By default, it is 3306 port.

在此示例中,选择了“ TCP / IP服务器”单选按钮。 在文本框中,输入MySQL服务器的主机名或IP地址。 默认情况下,主机名是localhost ,IP地址是127.0.0.1 。 在“ 端口”框中,输入列出了MySQL服务器的TCP / IP端口。 默认情况下,它是3306端口。

In the User box, type the name of the user needed to connect to the MySQL database and, in the Password box, type a user password. Under the Database combo box, choose the database for which want to establish connection:

在“ 用户”框中,键入连接到MySQL数据库所需的用户名,然后在“ 密码”框中,键入用户密码。 在“ 数据库”组合框下,选择要为其建立连接的数据库:

Connector/ODBC connection parameters to connect to MySQL database

To test if it is connected to MySQL database configured correctly, press the Test button. The following message will appear if the connection is established successfully:

要测试它是否连接到正确配置MySQL数据库,请按“ 测试”按钮。 如果成功建立连接,将出现以下消息:

Connect to MySQL database established succesfully

Also, the data source name will appear in the System DSN tab of the ODBC Data Source Administrator dialog:

同样,数据源名称将出现在“ ODBC数据源管理器”对话框的“ 系统DSN”选项卡中:

Newly created data source name in the System DSN tab of the ODBC Data Source Administrator dialog

使用ODBC驱动程序创建和配置链接服务器 (Create and configure a Linked Server using ODBC driver)

Now, when the ODBC driver for MySQL has been installed and ODBC driver to connect to MySQL database has been configured, configuring Linked Server in SSMS to connect to MySQL can begin.

现在,当已经安装了用于MySQL的ODBC驱动程序并且已经配置了用于连接到MySQL数据库的ODBC驱动程序时,就可以开始在SSMS中配置链接服务器来连接到MySQL。

Go to SSMS, in Object Explorer, under the Server Objects folder, right-click on the Linked Servers folder and, from the menu, select the New Linked Server option:

转到SSMS,在“ 对象资源管理器 ”中的“ 服务器对象”文件夹下,右键单击“ 链接服务器”文件夹,然后从菜单中选择“ 新建链接服务器”选项:

Context menu to create a linked server

The New Linked Server dialog will appear. Here will be entered configuration to connect to MySQL server:

将出现“ 新建链接服务器”对话框。 在这里输入连接到MySQL服务器的配置:

The New Linked Server dialog

In the Linked server text box of the General tab, enter the name of how the linked server will be called (e.g. MYSQL_SERVER).

在“ 常规”选项卡的“ 链接服务器”文本框中,输入将如何调用链接服务器的名称(例如,MYSQL_SERVER)。

Choose the Other data source radio button and from the Provider list, choose the item:

选择“ 其他数据源”单选按钮,然后从“ 提供程序”列表中,选择“ 项:

The New Linked Server dialog  - ODBC Drivers

Under the Product name box, enter any appropriate (valid) name. For the Data source, it should be entered the name of ODBC data source:

产品名称框下,输入任何适当的(有效)名称。 对于数据源 ,应输入ODBC数据源的名称:

In the Security tab, click the Be made using this security context radio button and in the Remote login and With password boxes, enter the user name and password that exist in the MySQL server instance, that is chosen as data source:

在“ 安全性”选项卡中,单击“ 使用此安全性上下文进行访问”单选按钮,然后在“ 远程登录”和“ 使用密码”框中,输入MySQL服务器实例中存在的用户名和密码,并选择该用户名和密码作为数据源:

The New Linked Server dialog  - Security tab

Under the Server Options tab, set the RPC and RPC Out fields to True:

在“ 服务器选项”选项卡下,将“ RPC”和“ RPC Out”字段设置为True:

The New Linked Server dialog  -Server Options tab

In case when these two options are not set to true and execute a code like this:

如果这两个选项未设置为true并执行如下代码:

EXEC ('SELECT * FROM test.table1') AT MYSQL_SERVER

The following error may appear:

可能会出现以下错误:

Msg 7411, Level 16, State 1, Line 1

Server ‘MYSQL_SERVER’ is not configured for RPC.

消息7411,第16级,状态1,第1行

未为RPC配置服务器“ MYSQL_SERVER”。

More about options under the Security and Server Options tabs can be found on the page.

在“ 页上,可以找到“ 安全性”和“ 服务器选项”选项卡下的选项的更多信息。

After all options under the New Linked Server dialog are set, press the OK button. Newly created linked server should appear in the Linked Servers folder:

设置“ 新链接服务器”对话框下的所有选项后,按“ 确定”按钮。 新创建的链接服务器应出现在“ 链接服务器”文件夹中:

MySQL linked server

Before start to querying data from MySQL database, go to the Providers folder under the Linked Server folder, right-click on the MSDASQL provider and, from the context menu, choose the Properties command:

在开始从MySQL数据库查询数据之前,请转到Linked Server文件夹下的Providers文件夹,右键单击MSDASQL Provider,然后从上下文菜单中选择Properties命令:

MSDASQL provider

In the Provider Options dialog, check the Nested queries, Level zero only, Allow in process, Support ‘Like’ operator check boxes:

在“ 提供程序选项”对话框中,选中“ 嵌套查询” ,“ 仅零级” ,“ 允许进行中” ,“ 支持”操作员复选框。

Provider Options dialog

For example, if the Allow in process check box is not checked, when executing code like this:

例如,如果未选中“ 允许进行中”复选框,则在执行如下代码时:

SELECT *FROM OPENQUERY(MYSQL_SERVER, 'SELECT * FROM test.table1')

The following error message may appear:

可能会出现以下错误消息:

Msg 7399, Level 16, State 1, Line 1

The OLE DB provider “MSDASQL” for linked server “MYSQL_SERVER” reported an error. Access denied.
Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE DB provider “MSDASQL” for linked server “MYSQL_SERVER”.

消息7399,级别16,状态1,第1行

链接服务器“ MYSQL_SERVER”的OLE DB提供程序“ MSDASQL”报告了一个错误。 拒绝访问。
Msg 7350,第16级,州2,第1行
无法从OLE DB提供程序“ MSDASQL”获取链接服务器“ MYSQL_SERVER”的列信息。

More useful articles about linked server can be found under these links:

在这些链接下可以找到有关链接服务器的更多有用文章:

翻译自:

转载地址:http://swnwd.baihongyu.com/

你可能感兴趣的文章
推荐系统的几种常见模型概述
查看>>
针对移动手机漏洞与安全支付现状分析
查看>>
[mysql] 一次sql耗时高引发报警的分析和处理
查看>>
把UIGestureRecognizer 中的点击事件变成Block
查看>>
清浮动的几种方法
查看>>
[LeetCode] Bold Words in String 字符串中的加粗单词
查看>>
EBS-利用form个性化 调用报表【Z】
查看>>
解决javah生成.h头文件找不到找不到android.support.v7.app.AppCompatActivity的问题
查看>>
字符数组在C++、C#等语言中的操作
查看>>
Cookie中的HttpOnly
查看>>
Fresco 源码分析(二) Fresco客户端与服务端交互(1) 解决遗留的Q1问题
查看>>
每天一个linux命令(44):top命令
查看>>
IOS内测分发策略
查看>>
shell笔记-local、export用法 、declare、set
查看>>
Java面向对象——类的成员
查看>>
servlet2.3/2.5/3.0/3.1的xml名称空间备忘
查看>>
清理:终结处理和垃圾回收
查看>>
2014年最新前端开发面试题(题目列表+答案 完整版)
查看>>
MySQL 常用
查看>>
基于vue + typescrpt +vuecli 搭建开发环境
查看>>