MySQL connection to IP is faster then a hostname?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

MySQL connection to IP is faster then a hostname?

Post by kaisellgren »

Hi,

Is it true that entering an IP instead of a hostname for MySQL is faster? Eg, entering 127.0.0.1 instead of localhost.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: MySQL connection to IP is faster then a hostname?

Post by John Cartwright »

I would assume so since the hostname needs to be translated into an IP eventually. However, I would assume the difference is a few microns.
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: MySQL connection to IP is faster then a hostname?

Post by kaisellgren »

Jcart wrote:I would assume so since the hostname needs to be translated into an IP eventually. However, I would assume the difference is a few microns.
But it does exist. So it could be worth using the actual IP (if it's static).
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: MySQL connection to IP is faster then a hostname?

Post by alex.barylski »

The difference is minimal enough, doing so would be moot. It would be the same as not using whitespace in your source code, so that it tokenized faster.

The problem with using an IP is it's concrete and you do not own an IP address, so much as you do a domain. So while connecting using an IP is technically faster, it's a tradeoff you make for far more flexible, easy to follow source code.

Sometimes it is a delicate balance between ease of use, flexibility, etc over performance, but in this case, I would strongly encourage using a domain not an IP -- unless you have too.

This value is likely cached somewhere locally anyways, so I wouldn't worry to much about it.

Cheers,
Alex
Post Reply