为什么连接到 MySQL 服务器这么慢?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1292856/
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-08-31 13:54:15  来源:igfitidea点击:

Why is connecting to MySQL server so slow?

mysqlperformanceintranet

提问by MemoryLeak

I use JDBC to connect to MySQL. When it's at localhost:3306, everything is OK.

我使用 JDBC 连接到 MySQL。当它在 时localhost:3306,一切正常。

But when I move my application to another computer in the intranet, and use <Intranet-IP>:3306to connect to the MySQL database, it takes about 1 minute to connect to MySQL successfully. What's up with this?

但是当我将我的应用程序移动到内网的另一台计算机上,并使用<Intranet-IP>:3306连接到MySQL数据库时,大约需要1分钟才能成功连接到MySQL。这是怎么回事?

回答by Davide Ungari

Well it could be a DNS problem. You can disable DNS host name lookups by starting mysqldwith the --skip-name-resolveoption in the configuration file.

嗯,这可能是 DNS 问题。您可以从配置文件中mysqld--skip-name-resolve选项开始禁用 DNS 主机名查找。

Read here for more details: http://dev.mysql.com/doc/refman/5.0/en/host-cache.html

阅读此处了解更多详细信息:http: //dev.mysql.com/doc/refman/5.0/en/host-cache.html

回答by Balta Ruiz

The --skip-name-resolveworked great for me.

--skip-name-resolve工作对我来说太棒了。

To make it permanent, I just add this line at the end of file my.iniin the [mysql]section:

为了使其永久化,我只需my.ini在该[mysql]部分的文件末尾添加这一行:

skip-name-resolve

And voilá! Transactions now fly!

瞧!现在交易飞起来!

回答by Matt

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.

对我来说,我在这里找到了这个解决方案,如果启用了 IP6 连接,连接到“localhost”可能会很慢,而是使用 IP 地址 127.0.0.1。这对我有用。

my mysql slow to connect problem was solved by this solution

我的 mysql 连接缓慢问题已通过此解决方案解决

回答by Makach

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.

你应该把你的数据库放在内部网上。将其保留在本地并位于大型防火墙之后。您当然可以在计算机之间设置防火墙和安全性。我建议您不要以这种方式未经过滤地将 mysql 数据库连接暴露给 Internet。