Compare the speed of the following two scripts:
- Windows 7 uses localhost to connect to local MySQL at a very slow speed.
- Windows 7 uses 127.0.0.1 to connect to local MySQL, and the speed is normal.
The My.ini is configured in
bind-address=127.0.0.1
Connect local mysql with localhost: slow speed
<?php$start = Microtime (true); $mysqli = new mysqli (' 127.0.0.1 ', ' root ', ' ', ' MySQL '); Connection time is 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:
Configuration in 1.my.ini
bind-address=127.0.0.1
, Win7 and above versions of PHP connect MySQL with localhost for more than 1 seconds, 400 times times slower than the 127.0.0.1 connection.
Configuration in 2.my.ini
Bind-address=::1
, Win7 and above version of the system PHP with localhost connection mysql speed is normal, but with 127.0.0.1 connection is not normal.
3. Remove Bind-address configuration, it is normal to connect MySQL speed with localhost or 127.0.0.1.
So: In the configuration of the
case, you should use 127.0.0.1 to connect to the local MySQL database.
When installing WordPress, phpMyAdmin and other PHP programs, the default is to use localhost to connect to the local MySQL database, this time attention to the default localhost changed to 127.0.0.1.
In addition, Windows 2008, 2012 and Windows 7 have the same problem.
The above describes the Windows Server R2 and 2012 PHP connection MySQL too slow solution, including aspects of the content, I hope the PHP tutorial interested in a friend helpful.