windows 在本地连接到 MySQL 的最佳方式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/271864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:34:40  来源:igfitidea点击:

Best way to connect to MySQL locally?

mysqlwindows

提问by Waleed Eissa

MySQL offers many ways (on Windows) to connect to it, those are:

MySQL 提供了多种方式(在 Windows 上)连接到它,它们是:

  • Shared memory
  • Named pipes
  • TCP/IP
  • 共享内存
  • 命名管道
  • TCP/IP

My question is, if MySQL will be run on the same machine of the web server, then which method is best for security and performance?

我的问题是,如果 MySQL 将在 Web 服务器的同一台机器上运行,那么哪种方法最适合安全和性能?

P.S. This is a one web server scenario, no web farm.

PS 这是一个单一的网络服务器方案,没有网络农场。

Thanks

谢谢

回答by Jimoc

In terms of performance if both are running on the same machine then shared memory is the better option as it wont run into issues with firewall software that may be on the machine or installed at a later date.

就性能而言,如果两者都在同一台机器上运行,那么共享内存是更好的选择,因为它不会遇到可能在机器上或以后安装的防火墙软件的问题。

However if in the future you need to seperate the web server and database due to upsizing, you will need to make changes to support this.

但是,如果将来由于升级而需要将 Web 服务器和数据库分开,则需要进行更改以支持这一点。

Therefore in the long run the better option is to go with TCP/IP as this will allow the servers to be seperated with the minimum of heartache.

因此,从长远来看,更好的选择是使用 TCP/IP,因为这将使服务器以最小的心痛分开。

回答by Vladislav Vaintroub

TCP/IP in all cases

所有情况下的 TCP/IP

I'd say the same, it is the only configuration that is tested thoroughly in development. Also

我会说同样的,它是唯一在开发中经过彻底测试的配置。还

1) named pipes are not a guarantee for security. One can access them via \ServerName\pipe\PipeName (and Connector/NET can do exactly that, even if C client won't).

1) 命名管道不能保证安全。可以通过 \ServerName\pipe\PipeName 访问它们(即使 C 客户端不会,Connector/NET 也可以做到这一点)。

2) Shared memory has couple of shortcomings. For example, it is impossible to know if shared memory client has died. That is, if application has exited without disconnect, on the server side resources are not cleaned (for the n wait_timeout period which 8 hours by default). Also, there is excessive synchronization when using shared memory.

2)共享内存有几个缺点。例如,无法知道共享内存客户端是否已死。也就是说,如果应用程序在没有断开连接的情况下退出,则不会清除服务器端的资源(默认为 8 小时的 n wait_timeout 时间段)。此外,使用共享内存时存在过度同步。

3) Localhost TCP access is very fast, at least on modern Windows, though I believe it was not the case until Vista/WS2008. I benchmarked it against pipes, there is no notable difference. As for security, this is what firewall is for.

3) 本地主机 TCP 访问速度非常快,至少在现代 Windows 上是这样,尽管我相信在 Vista/WS2008 之前情况并非如此。我针对管道对其进行了基准测试,没有显着差异。至于安全性,这就是防火墙的用途。

回答by Aistis Raudys

Shared memory is 4 times more faster than tcp/ip. To insert simple row into the table takes ~200 microseconds using tcp/ip and ~55 microseconds using shared memory (on my i5 3ghz). Tested using c/connector. Using net/connector speed increase is only about 3 times.

共享内存比 tcp/ip 快 4 倍。使用 tcp/ip 将简单行插入表中需要约 200 微秒,使用共享内存需要约 55 微秒(在我的 i5 3ghz 上)。使用 c/connector 测试。使用网络/连接器的速度提升只有 3 倍左右。

回答by Vanja

I'd say named pipes as it does provide significant difference than TCP/IP (tested with large dump imported).

我会说命名管道,因为它确实提供了与 TCP/IP 的显着差异(使用导入的大型转储进行测试)。

But you might need to consider how the actual application on the web server will perform using any of these connections, because the driver might not be capable of working with named pipes for example.

但是您可能需要考虑 Web 服务器上的实际应用程序将如何使用这些连接中的任何一个来执行,因为例如驱动程序可能无法使用命名管道。

I had problems with php (on windows) and named pipes so you'd need to check that part of the story as well.

我在使用 php(在 Windows 上)和命名管道时遇到了问题,因此您还需要检查故事的那部分。

回答by Vanja

For security reasons, it is clearly beneficial to disable TCP/IP-networking. I'm working on a .NET app, and I have had no problems connecting over a named pipe using the MySql connector. It works with the Mysql GUI tools as well :), and thats all I require.

出于安全原因,禁用 TCP/IP 网络显然是有益的。我正在开发一个 .NET 应用程序,使用 MySql 连接器通过命名管道进行连接时没有遇到任何问题。它也适用于 Mysql GUI 工具:),这就是我所需要的。

回答by Jairo Andres Velasco Romero

For better performance I can hint you some samples depending on where are located client and server:

为了获得更好的性能,我可以根据客户端和服务器的位置提示您一些示例:

Same machine: Shared memory, then named pipes, then TCP/IP

同一台机器:共享内存,然后是命名管道,然后是 TCP/IP

Different machine: TCP/IP

不同的机器:TCP/IP

The reason is when you are in the same machine sharing memory avoids the roundtrip through the network stack hosted in the operating system. Shared memory is a more efficient IPC method.

原因是当您在同一台机器上共享内存时,可以避免通过操作系统中托管的网络堆栈进行往返。共享内存是一种更高效的 IPC 方法。

回答by jishi

Shared memory or named pipes gives less overhead than TCP/IP, however, do windows even support named pipes?

共享内存或命名管道的开销比 TCP/IP 少,但是,Windows 甚至支持命名管道吗?

TCP/IP is the most compatible and scalable way to go on the other hand, and many connectors doesn't even support anything else afaik.

另一方面,TCP/IP 是最兼容和可扩展的方式,许多连接器甚至不支持其他任何东西。

You shouldn't restrict your scenario to "same machine" or plattform "windows" if you don't have to, it's always good to have scalability in mind.

如果不需要,您不应该将您的场景限制为“同一台机器”或平台“windows”,考虑到可扩展性总是好的。

回答by Seun Osewa

Just use 'localhost' for now.

现在只需使用“本地主机”。

回答by Marko

TCP/IP in all cases.

在所有情况下都是 TCP/IP。