mysql使用了读写分离;主从同步;当日志文件过大表过大的时候会导致;读写主从有一定的延迟导致从数据库被剔除;使用information_schema删除表信息;过大查询也会导致从库被剔除之前就尝试过一次查询information_schema中的COLUMNS表导致入宽太多兆导致从库挂了。
//清理erp日志记录
public function actionClearErpLog()
{
$sql = "SELECT
CONCAT('TRUNCATE table ', table_name) as table_name
FROM
information_schema.tables
WHERE table_name LIKE 'xcxmall_erp%' and table_schema = 'saasmall'";
$data = \Yii::$app->db->createCommand($sql)->queryAll();
foreach ($data as $k => $v) {
\Yii::$app->db->createCommand($v['table_name'])->execute();
}
}