對(duì)比下面兩個(gè)腳本的速度:
Windows 7 用 localhost 連接本地 MySQL,速度會(huì)很慢。 Windows 7 用 127.0.0.1 連接本地 MySQL,速度則是正常的。my.ini里配置了
bind-address=127.0.0.1
用localhost連接本地MySQL: 速度慢
<?php$start = microtime(true);$mysqli = new mysqli('127.0.0.1', 'root', '', 'mysql'); //連接耗時(shí)僅為0.0025秒.//$mysqli = new mysqli('localhost', 'root', '', 'mysql'); //連接耗時(shí)超過(guò)1秒,比正常慢了400倍.echo microtime(true) - $start;
分析:
1.my.ini里配置
bind-address=127.0.0.1
時(shí),Win7及其以上版本系統(tǒng)PHP用localhost連接MySQL耗時(shí)超過(guò)1秒,比用127.0.0.1連接慢了400倍.
2.my.ini里配置
bind-address=::1
時(shí),Win7及其以上版本系統(tǒng)PHP用localhost連接MySQL速度是正常的,但用127.0.0.1連接又不正常了.
3.去掉bind-address配置,則用localhost或127.0.0.1連接MySQL速度都是正常的.
所以:在配置了
bind-address=127.0.0.1
的情況下,應(yīng)該使用 127.0.0.1 連接本地 MySQL 數(shù)據(jù)庫(kù) 。
安裝 WordPress、phpMyAdmin 等 PHP 程序的時(shí)候默認(rèn)使用 localhost 連接本地 MySQL 數(shù)據(jù)庫(kù),這時(shí)注意把默認(rèn)的 localhost 改為 127.0.0.1。
另外,Windows 2008、2012 跟 Windows 7 存在同樣的問(wèn)題。
新聞熱點(diǎn)
疑難解答
圖片精選