Windows Server 2008 R2和2012中PHP连接MySQL过慢的解决方法
对比下面两个脚本的速度:
- Windows7用localhost连接本地MySQL,速度会很慢。
- Windows7用127.0.0.1连接本地MySQL,速度则是正常的。
my.ini里配置了
bind-address=127.0.0.1
用localhost连接本地MySQL:速度慢
<?php
$start=microtime(true);
$mysqli=newmysqli('127.0.0.1','root','','mysql');//连接耗时仅为0.0025秒.
//$mysqli=newmysqli('localhost','root','','mysql');//连接耗时超过1秒,比正常慢了400倍.
echomicrotime(true)-$start;
分析:
1.my.ini里配置
bind-address=127.0.0.1
时,Win7及其以上版本系统PHP用localhost连接MySQL耗时超过1秒,比用127.0.0.1连接慢了400倍.
2.my.ini里配置
bind-address=::1
时,Win7及其以上版本系统PHP用localhost连接MySQL速度是正常的,但用127.0.0.1连接又不正常了.
3.去掉bind-address配置,则用localhost或127.0.0.1连接MySQL速度都是正常的.
所以:在配置了
bind-address=127.0.0.1
的情况下,应该使用127.0.0.1连接本地MySQL数据库。
安装WordPress、phpMyAdmin等PHP程序的时候默认使用localhost连接本地MySQL数据库,这时注意把默认的localhost改为127.0.0.1。
另外,Windows2008、2012跟Windows7存在同样的问题。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下