Why is connecting to MySQL server so slow?

允我心安 提交于 2019-11-26 16:33:05

问题


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?


回答1:


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




回答2:


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:

skip-name-resolve

And voilá! Transactions now fly!




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/1292856/why-is-connecting-to-mysql-server-so-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!