在PHP脚本中的UPDATE语句到mysql DB的时间

时间:2015-05-10 13:50:43

标签: php mysql ubuntu server my.cnf

每个评论问题的编辑正则表达式

我正在绞尽脑汁试图在我的mysql服务器上加速这个脚本。它正在运行ubuntu,我跟随每篇文章关于调整my.cnf的建议,因为它涉及到innodb:

 $cleanSelect = mysqli_query($conn,"SELECT id, cleanShipment, cleanBOL, cleanInvoice, cleanBatch from MASTER_dups where
  division in (select division from MASTER_import)
  AND (cleanShipment REGEXP '[A-Za-z]'
  OR cleanInvoice REGEXP '[A-Za-z]'
  OR cleanBatch REGEXP '[A-Za-z]'
  OR cleanBOL REGEXP '[A-Za-z]')");
while ($row = mysqli_fetch_array($cleanSelect)) {
$id =  $row['id'];
$cleanShipment =  $row['cleanShipment'];
$cleanBOL =  $row['cleanBOL'];
$cleanBatch =  $row['cleanBatch'];
$cleanInvoice =  $row['cleanInvoice'];

$pattern = '/[A-Za-z]/';

$cleanShipment = preg_replace($pattern, '', $row['cleanShipment']);
$cleanBOL = preg_replace($pattern, '', $row['cleanBOL']);
$cleanBatch = preg_replace($pattern, '', $row['cleanBatch']);
$cleanInvoice = preg_replace($pattern, '', $row['cleanInvoice']);

$cleanShipment = !empty($cleanShipment) ? "$cleanShipment" : "";
$cleanBOL = !empty($cleanBOL) ? "$cleanBOL" : "";
$cleanBatch = !empty($cleanBatch) ? "$cleanBatch" : "";
$cleanInvoice = !empty($cleanInvoice) ? "$cleanInvoice" : "";


$updateMasterDups = 
"UPDATE MASTER_dups set cleanShipment = '$cleanShipment', 
cleanBOL = '$cleanBOL',
cleanBatch = '$cleanBatch',
cleanInvoice = '$cleanInvoice'
where id = $id";

 if (!mysqli_query($conn,$updateMasterDups))
   {
   echo("Error description: " . mysqli_error($conn)."<br>".$updateMasterDups."<br>");
   }
}

服务器上的硬件有点旧,但它有一个太字节硬盘和8GB内存。这个相同的代码在我的MacBook Pro上可以在2分钟内完成超过一百万行....唯一的问题是硬件吗?在我的服务器设置上,它需要一个多小时。下面是PHP,我只是想从4个字符串中删除任何alpha字符。这些cols中的每一个都被索引,但是甚至在每次更新之前尝试删除索引似乎都没有做任何改变。

session_start();
$_SESSION['ctables'] = $_SESSION['ctables'] * 1000;

0 个答案:

没有答案