完蛋,公司被一條 update 語句干趴了!
大家好,我是小林。

為什么會(huì)發(fā)生這種的事故?
又該如何避免這種事故的發(fā)生?




select ... from語句,其他語句都會(huì)被鎖住不能執(zhí)行,業(yè)務(wù)會(huì)因此停滯,接下來等著你的,就是老板的挨罵。sql_safe_updates 參數(shù)設(shè)置為 1,開啟安全更新模式。官方的解釋:
If set to 1, MySQL aborts UPDATE or DELETE statements that do not use a key in the WHERE clause or a LIMIT clause. (Specifically, UPDATE statements must have a WHERE clause that uses a key or a LIMIT clause, or both. DELETE statements must have both.) This makes it possible to catch UPDATE or DELETE statements where keys are not used properly and that would probably change or delete a large number of rows. The default value is 0.
使用 where,并且 where 條件中必須有索引列;
使用 limit;
同時(shí)使用 where 和 limit,此時(shí) where 條件中可以沒有索引列;
使用 where,并且 where 條件中必須有索引列;
同時(shí)使用 where 和 limit,此時(shí) where 條件中可以沒有索引列;
force index([index_name]) 可以告訴優(yōu)化器使用哪個(gè)索引,以此避免有幾率鎖全表帶來的隱患。force index([index_name]) 可以告訴優(yōu)化器使用哪個(gè)索引。評(píng)論
圖片
表情
