Compare the speed of the following two scripts:
- Windows 7 connects local MySQL with localhost, which can be slow.
- Windows 7 connects local MySQL with 127.0.0.1, and the speed is normal.
My.ini is configured in the
Connect local mysql with localhost: slow
<?php
$start = Microtime (true);
$mysqli = new Mysqli (' 127.0.0.1 ', ' root ', ', ', ' MySQL '); The connection takes only 0.0025 seconds.
$mysqli = new mysqli (' localhost ', ' root ', ', ', ' MySQL '); The connection takes more than 1 seconds and is 400 times times slower than normal.
Echo Microtime (True)-$start;
Analysis:
1.my.ini in the configuration
, Win7 and its version of the system PHP with localhost to connect to MySQL time consuming more than 1 seconds, compared with the 127.0.0.1 connection is 400 times times slower.
2.my.ini in the configuration
, Win7 and above version of the system PHP with localhost connection mysql speed is normal, but with the 127.0.0.1 connection is not normal.
3. Remove Bind-address configuration, then use localhost or 127.0.0.1 connection MySQL speed is normal.
So: In the configuration of the
, you should use 127.0.0.1 to connect to the local MySQL database.
Install WordPress, phpMyAdmin and other PHP programs when the default use localhost to connect to the local MySQL database, then note that the default localhost to 127.0.0.1.
In addition, Windows 2008 and 2012 have the same problem with Windows 7.