Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Binding MySQL to run from the public or private LAN IP address - which one is faster

So we have 2 servers all running at the same web host. We have bind MySQL to listen on the public ip-address of the database server and the web server connects to it from the public ip. Both servers run on the same private network.

Currently, the DB connect method from our php script takes about 3ms to connect to the MySQL database server host.

My question is, would MySql data interaction from the web server be faster if we bind it to listen on the private lan address on the database server instead of the public IP? or is it the same regardless and it wont make a different.

i have moved this question to server fault Binding MySQL to run from the public or private LAN IP address - which one is faster

share|improve this question

migrated from Oct 15 '12 at 3:28

This question came from our site for professional and enthusiast programmers.

marked as duplicate by John Gardeniers, mulaz, Magellan, Brent Pabst, Scott Pack Oct 18 '12 at 17:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

I would be curious to know [a] why you are binding MySQL on the public IP and [b] how you are timing your connect code. – Burhan Khalid Oct 14 '12 at 7:38
why on earth is your mysql db on a public ip ? this is HUGE SECURITY RISK, even if it were slower with the private ip there must be very good reasons to put a mysql server on a public ip and even then you will need to setup very tight security! – Yahia Oct 14 '12 at 7:39
it is question for serverfault – zb' Oct 14 '12 at 7:41
@Yahia We bind MySQL to listen on the private IP at first but MySQL wont start after that. We will secure the server so that no other ip can connect to it except the ip of the web server. – Lamin Barrow Oct 14 '12 at 7:44
@BurhanKhalid we got the code time from the code debug profile from in the framework we are using – Lamin Barrow Oct 14 '12 at 7:46
up vote 1 down vote accepted

Zero difference. Seriously. Same Network (LAN) should be below 1ms either way. It most likely takes MySQL more time to process a Login than it takes the OS to allocat buffers etc.

3MS should not bbe a Problem, especially when your programmer was not an idiot and used Connection pooling.

answers a question about it. if you really open and Close a Connection on every page / use, then - well, another not too competent progarmmer. Happens.

It it still takes 3ms, and that still is a Problem (which Points to other Problems in your architecture, because 3ms should not be a Problem to start with), then an in depth Analysis is required - by a specialist. Because then it is not as easy as "use a private or a public ip".

share|improve this answer

In this case, the better question to ask is: "am I willing to trade off security concerns for performance?".

Having your database accessible via public IP is an extremely risky deployment and you need very good security to make sure nothing bad is happening. If you have a public IP, people can and will poke at it; both out of curiosity and potential malice. The odds that you'll be hacked or otherwise compromised are almost certainly 100%.

Performance-wise, I'd expect you to get much better performance hitting the private IP within the same network than going to the public IP. In a private LAN you have much more control over what traffic may hit the port vs. on the public IP.

Bottom line: it's just not worth it to put your database on a public IP unless you have a very good reason.

Hope this helps!

share|improve this answer
Thanks. Thats helps a lot. We had problem with MySQL when we set it to listen on the private IP. It just wont start – Lamin Barrow Oct 14 '12 at 7:58
@LaminBarrow then you should put effort into figuring out why it won't start on a proper IP. Running it on public IP is not an acceptable solution to any competent admin. – Mxx Oct 15 '12 at 5:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.