300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 如何在SQL Server Management Studio中创建和配置链接服务器以连接到MySQL

如何在SQL Server Management Studio中创建和配置链接服务器以连接到MySQL

时间:2020-04-03 20:10:35

相关推荐

如何在SQL Server Management Studio中创建和配置链接服务器以连接到MySQL

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:

本文分为三个部分:

ODBC driver for MySQL ODBC驱动程序 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, JDBC (Java Database Connectivity) is used.

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

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

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

Under this link, 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-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, theWelcomedialog will appear:

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

After pressing theNextbutton, theLicense Agreementdialog appears. If you agree with the license agreement, press theI accept the terms in the license agreementradio button and click theNextbutton:

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

Under theSetup Typedialog, choose theTypicalradio button and press theNextbutton:

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

TheReady to Install the Programdialog shows what and where will be installed. Press theInstallbutton to install ODBC driver:

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

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

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

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

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

Another way to check is via the ODBC Data Source Administrator dialog box:

另一种检查方法是通过“ ODBC数据源管理器”对话框:

Under theDriverstab of theODBC Data Source Administratordialog box, check if the MySQL ODBC Drivers exist:

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

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

To connect to MySQL database using ODBC drivers, in theODBC Data Source Administratordialog, under theSystem DSNtab, press theAddbutton:

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

In theCreate New Data Sourcedialog, select theMySQL ODBC Driverand press theFinishbutton:

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

In theMySQL Connector/ODBC Data Source Configurationdialog:

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

For theData Source Nametext box, enter the data source name by choice. In theDescriptiontext box, enter the description of the data source if needed.

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

Use the TCP/IP Server or Named Pipe connection method to connect to MySQL by selecting appropriate radio button.

通过选择适当的单选按钮,使用TCP / IP服务器或命名管道连接方法连接到MySQL。

In this example, theTCP/IP Serverradio button is selected. In the text box, type a host name or IP address of the MySQL server. By default, the host name islocalhostand IP address is127.0.0.1. In thePortbox, enter the TCP/IP port on which the MySQL server is listed. By default, it is3306port.

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

In theUserbox, type the name of the user needed to connect to the MySQL database and, in thePasswordbox, type a user password. Under theDatabasecombo box, choose the database for which want to establish connection:

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

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

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

Also, the data source name will appear in theSystem DSNtab of theODBC Data Source Administratordialog:

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

使用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, inObject Explorer,under theServer Objectsfolder, right-click on theLinked Serversfolder and, from the menu, select theNew Linked Serveroption:

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

TheNew Linked Serverdialog will appear. Here will be entered configuration to connect to MySQL server:

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

In theLinked servertext box of theGeneraltab, enter the name of how the linked server will be called (e.g. MYSQL_SERVER).

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

Choose theOther data sourceradio button and from theProviderlist, choose the Microsoft OLE DB Provider for ODBC Drivers item:

选择“其他数据源”单选按钮,然后从“提供程序”列表中,选择“ Microsoft OLE DB Provider for ODBC Drivers”项:

Under theProduct namebox, enter any appropriate (valid) name. For theData source, it should be entered the name of ODBC data source:

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

In theSecuritytab, click theBe made using this security contextradio button and in theRemote loginandWith passwordboxes, enter the user name and password that exist in the MySQL server instance, that is chosen as data source:

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

Under theServer Optionstab, set theRPCandRPC Outfields toTrue:

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

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 theSecurityandServer Optionstabs can be found on the How to create and configure a linked server in SQL Server Management Studio page.

在“ 如何在SQL Server Management Studio中创建和配置链接的服务器”页上,可以找到“安全性”和“服务器选项”选项卡下的选项的更多信息。

After all options under theNew Linked Serverdialog are set, press theOKbutton. Newly created linked server should appear in theLinked Serversfolder:

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

Before start to querying data from MySQL database, go to theProvidersfolder under theLinked Serverfolder, right-click on theMSDASQLprovider and, from the context menu, choose thePropertiescommand:

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

In theProvider Optionsdialog, check theNested queries,Level zero only,Allow in process,Support ‘Like’ operatorcheck boxes:

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

For example, if theAllow in processcheck 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:

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

How to query Excel data using SQL Server linked servers 如何使用SQL Server链接服务器查询Excel数据 How to create and configure a linked server in SQL Server Management Studio 如何在SQL Server Management Studio中创建和配置链接服务器 How to create, configure and drop a SQL Server linked server using Transact-SQL 如何使用Transact-SQL创建,配置和删除SQL Server链接服务器 How to create a linked server to an Azure SQL database 如何创建到Azure SQL数据库的链接服务器 How to configure a Linked Server using the ODBC driver 如何使用ODBC驱动程序配置链接服务器

翻译自: /how-to-create-and-configure-a-linked-server-to-connect-to-mysql-in-sql-server-management-studio/

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。