Mysql – thesql connection is slow (5seconds)

connectiondebianlagMySQLslow-connection

After building my webapp on a first boot i create 2 connections to mysql on debian then 1-2 (r/w) for every page after that. The connection consistently take 5.2 seconds to connect. Debian is in a VM running in my OS. Why is the connection taking this long?

At times it will take < 0.1 seconds which is great but 5.2 x2-3 on every run is to much. Has anyone experience this problem? how do i solve it?

note: I am using .NET to connect. Not that it matters. and its mysql v5

-edit- After checking firewall settings and doing many things i could not figure the problem out. I found a noinstall release of mysql and used that. Connections are lightning fast.

Best Answer

Obfuscurity may be right. First thing I would check is reverse DNS. To troubleshoot this try setting the --skip-name-resolve flag to mysqld:

http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_skip-name-resolve

Also make sure to add your hostname/ip to /etc/hosts