为什么连接 MySQL 服务器这么慢?
我使用 JDBC 连接 MySQL。当位于 localhost:3306
时,一切正常。
但是当我将应用程序移动到内网的另一台计算机上,并使用
连接 MySQL 数据库时,大约需要 1 分钟才能成功连接 MySQL。这是怎么回事?
I use JDBC to connect to MySQL. When it’s at localhost:3306
, everything is OK.
But when I move my application to another computer in the intranet, and use <Intranet-IP>:3306
to connect to the MySQL database, it takes about 1 minute to connect to MySQL successfully. What’s up with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
嗯,这可能是 DNS 问题。您可以通过在配置文件中使用
--skip-name-resolve
选项启动mysqld
来禁用 DNS 主机名查找。阅读此处了解更多详细信息: http://dev.mysql.com /doc/refman/5.0/en/host-cache.html
Well it could be a DNS problem. You can disable DNS host name lookups by starting
mysqld
with the--skip-name-resolve
option in the configuration file.Read here for more details: http://dev.mysql.com/doc/refman/5.0/en/host-cache.html
--skip-name-resolve
对我来说非常有用。为了使其永久化,我只需在文件
my.ini
的[mysql]
部分的末尾添加这一行:瞧!交易现在飞速发展!
The
--skip-name-resolve
worked great for me.To make it permanent, I just add this line at the end of file
my.ini
in the[mysql]
section:And voilá! Transactions now fly!
对我来说,这是我在这里找到的解决方案,如果启用了 IP6 连接,到“localhost”的连接可能会很慢,而是使用 IP 地址 127.0.0.1。这对我有用。
这个解决方案解决了我的mysql连接速度慢的问题
For me it was this solution I found here, If IP6 connectivity is enabled, connection to "localhost" may be slow, instead use the ip address, 127.0.0.1. This worked for me.
my mysql slow to connect problem was solved by this solution
防火墙、互联网、路由等都会减慢您的连接速度。
您应该将数据库放在内部网上。将其保留在本地并位于大型防火墙后面。当然,您可以在计算机之间设置防火墙和安全措施。我建议你不要以这种方式将你的 mysql 数据库连接暴露到未经过滤的互联网上。
firewalls, Internet, routing etc etc slows down your connection.
You should put your database on a intra net instead. Keep it local and behind your big firewall. You can of course have firewall and security between computers. I'd recommend that you didn't expose your mysql database connection to the Internet unfiltered that way.
评论/发现一个非常老的问题。
背景 - 典型:从 Windows(各种)连接到 win 或 Linux 服务器上的 sql 服务器慢...数秒(甚至从 VBox 上的 win 客户端连接到同一主机上的服务器)
skip-name-resolve
,dns-bind
- 尝试了各种方法,但没有效果。查看手册 - 连接字符串选项 - 没有时间了解它们的含义,一一设置并尝试 - 只要没有任何中断。
将
sslmode=none;
添加到连接字符串...连接时间实际上少于 1/10。亚秒级连接,毫秒!注意:
它位于小型办公室专用 LAN 中,因此不要担心任何安全问题
...它有效...我会接受。
comment / finding to a really REALLY old question.
background - typical: connecting from windows (various) to sql server on win or linux server slow ... multiple seconds (even from win client on VBox to server on same host)
skip-name-resolve
,dns-bind
- tried all sorts, regardless no effect.Looked at the manual - connection string options - no time to learn what they mean, one-by-one set-and-try - as long as nothing breaks.
adding
sslmode=none;
to connection string ... connecting in literally less than 1/10th the time. sub-second connections, milliseconds!Note:
It's in a small office private LAN so don't GAS any security FUD
... It works ... I'll take it.