Mysql连接 - 通过IP然后域连接更快?

问题</ strong> </ p>

此更快</ p>

  $ servername =“125.125.55.10”; 
$ username =“username”;
$ password =“password”;
$ conn = new mysqli($ servername, $ username,$ password);
</ code> </ pre>

或者这个?</ p>

  $ servername =“mysql.server.com  “; 
$ username =”username“;
$ password =”password“;
$ conn = new mysqli($ servername,$ username,$ password);
</ code> </ pre>

或它对速度没有影响?</ p>

我不知道它是否有任何实际用途,但毫秒是毫秒...... </ p>
\ n

谢谢</ p>
</ div>

展开原文

原文

Question

Is faster this

$servername = "125.125.55.10";
$username = "username";
$password = "password";
$conn = new mysqli($servername, $username, $password);

or this?

$servername = "mysql.server.com";
$username = "username";
$password = "password";
$conn = new mysqli($servername, $username, $password);

or it has no effect to speed?

I do not know if it has any practical use, but millisecond is milisecond....

Thank you

2个回答



是的,它可以被认为稍快一些,因为不需要将域解析为IP地址(DNS查找)。 但是,大多数现代技术将在建立连接时缓存IP地址,这意味着不必为每个到同一地址的连接进行DNS查找。 因此,除了第一次连接到站点之外,差异是可以忽略的,甚至最多只能持续几秒钟。 </ p>
</ div>

展开原文

原文

Yes, it could be considered slightly faster, as there is no need to resolve the domain to an IP address (DNS lookup). However, most modern technologies will cache the IP address when a connection is made, meaning a DNS lookup does not have to be made for every connection to the same address. So the difference is neglible, apart from the first time you connect to a site, and even then only for a few seconds at most.

doupo1865
doupo1865 啊。 我忘了这是件事。
大约 4 年之前 回复
dongtanliefang8765
dongtanliefang8765 我需要15点声望才能投票:(
大约 4 年之前 回复
dqvy87517
dqvy87517 没问题。 如果这对你有所帮助,可以考虑将upvoting和标记视为已接受!
大约 4 年之前 回复
douwo5710
douwo5710 很好,非常感谢。
大约 4 年之前 回复
douzhang3822
douzhang3822 DNS查询时间? 您可以使用network-speed.com/dnstime.php等工具检查服务器的时间
大约 4 年之前 回复
douxi5940
douxi5940 谢谢,有什么办法可以衡量吗?
大约 4 年之前 回复

The thing is, the first time your web-server will access mysql-database, it will cache resolved hostname. The problem with using IPs is that it's basically hardcode, it's hard to grep, IP can change far more frequently then hostname, etc. More than that: spending your time on premature optimizations like

  • connect using hostname/ip
  • connect using unix socket/tcp socket
  • use persistent connections or not?

is a waste of time, if your tables/scripts are not optimized.

what to look for in database (sql/nosql) performance:

  • learn to use your dbms indexes / learn "EXPLAIN query"
  • never update huge number of rows one by one, update in batch-mode only
  • while developing a project, generate a LOT (>500k of rows) of fake data and insert it to database, this way you will know when your 'perfect query' is slow before your production server suffers
duanlei1957
duanlei1957 谢谢,这非常有帮助。
大约 4 年之前 回复
dongxu4023
dongxu4023 是的,最好使用主机名并专注于更重要的东西。 使用你喜欢的任何东西--pdo / mysqli,它们都不被弃用。 不要关注它们,实现细节。 学习使用SQL / composer / frameworks。
大约 4 年之前 回复
doujie9882
doujie9882 好吧,最好使用主机名并专注于更重要的东西,比如使用mysqli而不是PDO?
大约 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问