du127953 2011-12-07 19:19
浏览 148
已采纳

为什么简单的MySQL查询需要超过5秒才能执行?

Update 2011/12/12: Now isolated as FastCGI on my (IIS-based) hosting package. I had them turn it off because a scheduled task kept timing out. I know where I am now. Thanks again, all.

Mark Iliff


Update 2011/12/11: OK, I have to put my hands up to inadvertent misdirection.

Thanks to your many suggestions I've now identified this as a problem with PHP pages on my hosting package, not specifically MySQL. An empty PHP page still takes 5-6 seconds to load, whereas the same page with an ASP or HTML extension loads too fast to measure. I'm taking this up with my hosting provider.

Sorry for not thinking to check this first and thanks for pitching in: much appreciated.

Mark Iliff


I'm relatively new to MySQL/PHP and suspect I'm doing something stupid with the following:

        <?
        // Slave page: block/unblock merchant
        $id = $_POST["id"] ;
        $val = $_POST["val"] ;

        if ( isset( $id ) && isset( $val ) ) {
            $conx = mysqli_connect ( "sql05", $dbAc, $dbPwd, "finewine" ) 
                or die ("Conx failed") ;

            // update record
            $sql = "UPDATE wsMerchants SET 
                blockem = ".$val.", updateDT = '".date( "Y-m-d H:i:s" )."' 
                WHERE id = ".$id.";" ;
            $result = mysqli_query( $conx, $sql ) ;

            //tidy
            mysqli_close( $conx ) ;
            };
        ?>

Result of SHOW CREATE:
CREATE TABLE `wsmerchants` (
 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 `merchant` text NOT NULL,
 `country` tinytext NOT NULL,
 `blockem` tinyint(1) DEFAULT '0',
 `benchmark` tinyint(1) DEFAULT '0',
 `createDT` datetime NOT NULL,
 `updateDT` datetime NOT NULL,
 UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=119 DEFAULT CHARSET=utf8

I'm calling this from JQuery (using $.post). The db table has 29 records and 7 fields.

It works, but incredibly slowly.

With sad old Access (+ Classic ASP) queries like this are, for all practical purposes, instantaneous. In MySQL, according to the timer in Firebug, the query takes 5-6 seconds.

I'm running MySQL 5.0.51a + PHP 5.2.13 in a hosted Windows environment.

I've rootled around other questions in here but they mainly seem to involve complex SQL queries.

  • 写回答

3条回答 默认 最新

  • dongmeirang4679 2011-12-07 19:25
    关注

    Other issues aside, I doubt the bottleneck here is the query.

    First, try the query from the MySQL console to ensure your database server is ok.

    Then, make a simple test script that only connects to the database and does not perform any queries. Make sure you place something after the connect call so that you can see when it finishes connecting.

    That's my guess anyway - is that the bottleneck lies in the database connection.

    One more thing, is this an AMP stack (WAMP, XAMPP) in Windows, or are you running PHP through IIS?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler