简体   繁体   English

C#MYSQL-穿越防火墙的“隧道”

[英]C# MYSQL - “Tunnel” past firewall

I have a C# application connecting to an external MYSQL database, all works fine but the company it is used on has MYSQL connections blocked and I cant have it allowed. 我有一个C#应用程序连接到外部MYSQL数据库,一切正常,但使用该公司的公司的MYSQL连接被阻止,我不允许它。 I am rather new to C# and MYSQL and have researched HTTP and SSH tunneling but I don't see how to implement it into a C# program. 我是C#和MYSQL的新手,并且研究过HTTP和SSH隧道,但是我看不到如何将其实现到C#程序中。

I need a way to get and send data to the MYSQL database around the firewall. 我需要一种获取和发送数据到防火墙周围的MYSQL数据库的方法。 Can someone please explain to me what my best option is and how to use it. 有人可以告诉我我最好的选择是什么以及如何使用它。

Microsoft Windows include a firewall which specifically blocks ports. Microsoft Windows包括专门阻止端口的防火墙。 If you plan on using MySQL through a network port then you should open and create an exception for this port before performing the installation. 如果计划通过网络端口使用MySQL,则应在执行安装之前打开并为此端口创建一个例外。 To check and if necessary add an exception to the firewall settings: 要检查并在必要时向防火墙设置添加例外:

First ensure that you are logged in as an Administrator or a user with Administrator privileges. 首先,请确保您以管理员或具有管理员权限的用户身份登录。

  1. Go to the Control Panel, and double click the Windows Firewall icon. 转到控制面板,然后双击Windows防火墙图标。
  2. Choose the Allow a program through Windows Firewall option and click the Add port button. 选择“允许程序通过Windows防火墙”选项,然后单击“添加端口”按钮。
  3. Enter MySQL into the Name text box and 3306 (or the port of your choice) into the Port number text box. 在“名称”文本框中输入MySQL,在“端口号”文本框中输入3306 (或您选择的端口)。
  4. Also ensure that the TCP protocol radio button is selected. 还要确保已选择“ TCP协议”单选按钮。
  5. If you wish, you can also limit access to the MySQL server by choosing the Change scope button. 如果愿意,还可以通过选择“更改范围”按钮来限制对MySQL服务器的访问。
  6. Confirm your choices by clicking the OK button. 单击确定按钮,确认您的选择。

Additionally, when running the MySQL Installation Wizard on Windows 7 or newer, ensure that you are logged in as a user with administrative rights. 此外,在Windows 7或更高版本上运行MySQL安装向导时,请确保您以具有管理权限的用户身份登录。

When using Windows Vista or newer, you may want to disable User Account Control (UAC) before performing the installation. 使用Windows Vista或更高版本时,您可能需要在执行安装之前禁用用户帐户控制(UAC)。 If you do not do so, then MySQL may be identified as a security risk, which will mean that you need to enable MySQL. 如果您不这样做,则可能会将MySQL视为安全风险,这意味着您需要启用MySQL。 You can disable the security checking by following these instructions: 您可以按照以下说明禁用安全检查:

Try to Open Control Panel. 尝试打开控制面板。

  1. Under the User Accounts and Family Safety, select Add or remove user accounts. 在“用户帐户和家庭安全”下,选择“添加或删除用户帐户”。
  2. Click the Got to the main User Accounts page link. 单击“转到主用户帐户”页面链接。
  3. Click on Turn User Account Control on or off. 单击“打开或关闭用户帐户控制”。 You may be prompted to provide permission to change this setting. 可能会提示您提供更改此设置的权限。 Click Continue. 单击继续。
  4. Deselect or uncheck the check box next to Use User Account Control (UAC) to help protect your computer. 取消选中或取消选中“使用用户帐户控制(UAC)”旁边的复选框,以帮助保护您的计算机。 Click OK to save the setting. 单击确定保存设置。

You will need to restart to complete the process. 您将需要重新启动以完成该过程。 Click Restart Now to reboot the machine and apply the changes. 单击立即重新启动以重新启动计算机并应用更改。 You can then follow the instructions below for installing Windows. 然后,您可以按照以下说明安装Windows。

Connecting to MySQL Remotely from Windows with SSH 使用SSH从Windows远程连接到MySQL

This section describes how to get a secure connection to a remote MySQL server with SSH. 本节介绍如何使用SSH与远程MySQL服务器建立安全连接。 The information was provided by David Carlson . 该信息由David Carlson提供。

  1. Install an SSH client on your Windows machine. 在Windows计算机上安装SSH客户端。 As a user, the best nonfree one I have found is from SecureCRT from http://www.vandyke.com/ . 作为用户,我发现最好的非免费软件来自http://www.vandyke.com/的 SecureCRT。 Another option is f-secure from http://www.f-secure.com/ . 另一种选择是来自http://www.f-secure.com/的 f-secure。 You can also find some free ones on Google at http://directory.google.com/Top/Computers/Internet/Protocols/SSH/Clients/Windows/ . 您还可以在http://directory.google.com/Top/Computers/Internet/Protocols/SSH/Clients/Windows/上找到一些免费的工具。
  2. Start your Windows SSH client. 启动Windows SSH客户端。 Set Host_Name = yourmysqlserver_URL_or_IP. 设置Host_Name = yourmysqlserver_URL_or_IP。 Set userid=your_userid to log in to your server. 设置userid = your_userid登录到服务器。 This userid value might not be the same as the user name of your MySQL account. 该userid值可能与您的MySQL帐户的用户名不同。
  3. Set up port forwarding. 设置端口转发。 Either do a remote forward (Set local_port: 3306, remote_host: yourmysqlservername_or_ip, remote_port: 3306 ) or a local forward (Set port: 3306, host: localhost, remote port: 3306). 进行远程转发(设置local_port:3306,remote_host:yourmysqlservername_or_ip,remote_port:3306)或进行本地转发(设置端口:3306,主机:localhost,远程端口:3306)。
  4. Save everything, otherwise you will have to redo it the next time. 保存所有内容,否则下次必须重做。
  5. Log in to your server with the SSH session you just created. 使用刚刚创建的SSH会话登录到服务器。
  6. On your Windows machine, start some ODBC application (such as Access). 在Windows计算机上,启动一些ODBC应用程序(例如Access)。
  7. Create a new file in Windows and link to MySQL using the ODBC driver the same way you normally do, except type in localhost for the MySQL host server, not yourmysqlservername. 在Windows中创建一个新文件,并使用ODBC驱动程序链接到MySQL,方法与通常相同,不同的是键入MySQL主机服务器的localhost,而不是yourmysqlservername。

At this point, you should have an ODBC connection to MySQL, encrypted using SSH. 此时,您应该与MySQL建立ODBC连接,并使用SSH加密。

References: 参考文献:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM