在搭建mysql主从复制结构后,发现mysql从库的日志中频繁出现以下警告:
[Warning] Statement may not be safe to log in statement format. Statement: UPDATE `ecshop`.`peixun_sessions` SET expiry = '1300718449', ip = '119.36.87.150', userid = '0', adminid = '0', user_name='0', user_rank='0', discount='1', email='0', data = 'a:3:{s:7:\"from_ad\";i:0;s:7:\"referer\";s:4:\"本站\";s:10:\"login_fail\";i:0;}' WHERE sesskey = '815b45228773afe524f7651ad9b8e84f' LIMIT 1
经过检查,这是因为加有limit导致,MySQL认为添加limit会导致主从库数据可能不一致,就出现警告,解决方式有多种,但是对一个处于生产环境中的MySQL主从结构,建议还是从程序入手,尽可能不要修改MySQL配置(既然已经MySQL稳定运行,擅自修改其配置,就可能存在风险)
修改ecshop的源文件 includes/cls_session.php
大约228行左右找到
return $this->db->query('UPDATE ' . $this->session_table . " SET expiry = '" . $this->_time . "', ip = '" . $this->_ip . "', userid = '" . $userid . "', adminid = '" . $adminid . "', user_name='" . $user_name . "', user_rank='" . $user_rank . "', discount='" . $discount . "', email='" . $email . "', data = '$data' WHERE sesskey = '" . $this->session_id . "' LIMIT 1");
将最后的LIMIT 1去掉,即:
return $this->db->query('UPDATE ' . $this->session_table . " SET expiry = '" . $this->_time . "', ip = '" . $this->_ip . "', userid = '" . $userid . "', adminid = '" . $adminid . "', user_name='" . $user_name . "', user_rank='" . $user_rank . "', discount='" . $discount . "', email='" . $email . "', data = '$data' WHERE sesskey = '" . $this->session_id . "'");
再找到destroy_session方法的定义中:
$this->db->query('DELETE FROM ' . $this->session_data_table . " WHERE sesskey = '" . $this->session_id . "' LIMIT 1");
return $this->db->query('DELETE FROM ' . $this->session_table . " WHERE sesskey = '" . $this->session_id . "' LIMIT 1");
同样,将 limit 1去掉