MemoryLeak
MemoryLeak

Reputation: 7318

Why is connecting to MySQL server so slow?

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?

Upvotes: 25

Views: 73862

Answers (5)

Rob
Rob

Reputation: 464

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.

Upvotes: 0

Davide Ungari
Davide Ungari

Reputation: 1960

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

Upvotes: 45

baltaruiz
baltaruiz

Reputation: 191

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!

Upvotes: 19

Matt
Matt

Reputation: 91

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

Upvotes: 9

Makach
Makach

Reputation: 7559

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.

Upvotes: 1

Related Questions