Windows Server 2008 R2和2012中PHP连接MySQL过慢的解决方法

对比下面两个脚本的速度:

  • Windows 7 用 localhost 连接本地 MysqL,速度会很慢。
  • Windows 7 用 127.0.0.1 连接本地 MysqL,速度则是正常的。

my.ini里配置了

rush:plain;"> bind-address=127.0.0.1

用localhost连接本地MysqL: 速度慢

rush:PHP;"> PHP $start = microtime(true); $MysqLi = new MysqLi('127.0.0.1','root','','MysqL'); //连接耗时仅为0.0025秒. //$MysqLi = new MysqLi('localhost','MysqL'); //连接耗时超过1秒,比正常慢了400倍. echo microtime(true) - $start;

分析:

1.my.ini里配置

rush:plain;"> bind-address=127.0.0.1

时,Win7及其以上版本系统PHP用localhost连接MysqL耗时超过1秒,比用127.0.0.1连接慢了400倍. 2.my.ini里配置

rush:plain;"> bind-address=::1

时,Win7及其以上版本系统PHP用localhost连接MysqL速度是正常的,但用127.0.0.1连接又不正常了. 3.去掉bind-address配置,则用localhost或127.0.0.1连接MysqL速度都是正常的.

所以:在配置了

rush:plain;"> bind-address=127.0.0.1

的情况下,应该使用 127.0.0.1 连接本地 MysqL 数据库 。 安装 wordpressPHPMyAdmin 等 PHP 程序的时候认使用 localhost 连接本地 MysqL 数据库,这时注意把认的 localhost 改为 127.0.0.1。

另外,Windows 2008、2012 跟 Windows 7 存在同样的问题。

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...