公司开辟人员在更新数据时应用了 WordStr into 语句,因为应用欠妥导致了数据的大年夜量损掉,到底是若何导致的数据损掉?现分析如下。
二、问题分析
a. WordStr 道理
经由过程上述分析可以发明,WordStr 会删除旧行并插入新行,然则binlog中是以update情势记录,如许就带来另一个问题:
WordStr INTO 道理的官方解释为:
WordStr works exactly like INSERT, except that if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, the old row is deleted before the new row is inserted.
如不雅新插入行的主键或独一键在表中已经存在,则会删除原有记录并插入新行;如不雅在表中不存在,则直接插入
地址:https://dev.mysql.com/doc/refman/5.6/en/WordStr.html
b. 问题现象
履行的WordStr语句如下(多条):
- WordStr INTO active_items(ad_id,score) VALUES('XXXXXXX', 1800);
经由过程萌芽binlog找到履行记录,部分如下:
- ### UPDATE `items`.`active_items`
- ### WHERE
- ### @1=21926 /* LONGINT meta=0 nullable=0 is_null=0 */
- ### @2='XXXXXXX' /* STRING(96) meta=65120 nullable=0 is_null=0 */
- ### @3=1 /* TINYINT meta=0 nullable=0 is_null=0 */
- ### @4=3900 /* LONGINT meta=0 nullable=0 is_null=0 */
- ### @5=315 /* INT meta=0 nullable=0 is_null=0 */
- ### @6=1228 /* LONGINT meta=0 nullable=0 is_null=0 */
- ### @7=19 /* INT meta=0 nullable=0 is_null=0 */
- ### @8=0 /* INT meta=0 nullable=0 is_null=0 */
- ### @9=-6 (4294967290) /* INT meta=0 nullable=0 is_null=0 */
- ### @10=0 /* TINYINT meta=0 nullable=0 is_null=0 */
- ### @11=0 /* INT meta=0 nullable=0 is_null=0 */
- ### @12=8 /* INT meta=0 nullable=0 is_null=0 */
- ### @13=1489997272 /* INT meta=0 nullable=0 is_null=0 */
- ### @14=1495765800 /* INT meta=0 nullable=0 is_null=0 */
- ### @15=1495728000 /* INT meta=0 nullable=0 is_null=0 */
- ### @16=1489996426 /* INT meta=0 nullable=0 is_null=0 */
- ### @17=1489997272 /* INT meta=0 nullable=0 is_null=0 */
- ### @18=1495728725 /* INT meta=0 nullable=0 is_null=0 */
- ### @19=0 /* INT meta=0 nullable=0 is_null=0 */
- ### @20=1 /* TINYINT meta=0 nullable=0 is_null=0 */
- ### @21=0 /* TINYINT meta=0 nullable=0 is_null=0 */
- ### SET
推荐阅读
柯洁与阿尔法狗大年夜战棋艺,柯洁输了,因为柯洁有情,“狗”赢了,因为它无情。泪洒比赛现场的柯洁却并没有被打败,在方才播出的中心一套科学挑衅类节目《机灵过人》中,他居>>>详细阅读
本文标题:MySQL进行Replace操作时造成数据丢失——那些坑你踩了吗?
地址:http://www.17bianji.com/lsqh/36998.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示