MySQL & MariaDB error 1175: You are using safe update mode
You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column. (5.7.44) · You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column (10.6.28) sql_safe_updates is on, and the UPDATE or DELETE has no WHERE condition on a key column and no LIMIT. MySQL Workbench and `mysql --safe-updates` turn this on to stop accidental full-table changes.
| MySQL | MariaDB | |
|---|---|---|
| Symbol | ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE | ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE |
| SQLSTATE | HY000 | HY000 |
| Type | Server error | Server error |
| Versions | every release since 5.0 active | every release since 5.5 active |
What it means
You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column. Safe update mode refuses UPDATE and DELETE statements that could touch every row: no WHERE at all, or a WHERE that can’t use an index, and no LIMIT.
Why it happens
- MySQL Workbench enables safe updates by default (Edit → Preferences → SQL Editor → “Safe Updates”), so a statement that works in your application fails in Workbench.
mysql --safe-updates(or--i-am-a-dummy) on the command line.- The WHERE filters on a non-indexed column (
WHERE status = 'old').
How to fix it
- Filter on a key:
WHERE id = 2, orWHERE id IN (…)with literal ids. - Add a
LIMIT(allowed even without a key condition):UPDATE t SET … WHERE status = 'old' LIMIT 1000; - If you really mean to change many rows:
SET SESSION sql_safe_updates = 0;, run the statement, then switch it back on. In Workbench you can also untick the preference and reconnect. - Better still, index the column you filter on.
Reproduce it yourself
These steps are the exact test our harness runs. Use a scratch server, never production.
Connect with
mysql -u root -pand create a scratch database and the test data:CREATE DATABASE demo; USE demo; CREATE TABLE t (id INT PRIMARY KEY, status VARCHAR(10)); INSERT INTO t VALUES (1,'new'),(2,'old');Run:
SET SESSION sql_safe_updates = 1; UPDATE t SET status = 'done' WHERE status = 'old';
You get: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column(11.8.9)
Verified fixes
Filter on a key column, or add a LIMIT
SET SESSION sql_safe_updates = 1; UPDATE t SET status = 'done' WHERE id = 2; UPDATE t SET status = 'done' WHERE status = 'new' LIMIT 10; SELECT COUNT(*) FROM t WHERE status = 'done';Or switch safe updates off for this session only
SET SESSION sql_safe_updates = 1; SET SESSION sql_safe_updates = 0; UPDATE t SET status = 'done' WHERE status = 'old'; SELECT COUNT(*) FROM t WHERE status = 'done';
Tested on
| Step | MySQL | MariaDB | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 5.7 | 8.0 | 8.4 | 9 | 10.6 | 10.11 | 11.4 | 11.8 | |
| sql_safe_updates is on (MySQL Workbench sets it) and WHERE doesn't use a key repro | ✓ 1175 | ✓ 1175 | ✓ 1175 | ✓ 1175 | ✓ 1175 | ✓ 1175 | ✓ 1175 | ✓ 1175 | ✓ 1175 |
| Filter on a key column, or add a LIMIT fix | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Or switch safe updates off for this session only fix | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Related errors
- 1205
ER_LOCK_WAIT_TIMEOUTexplained
How the message changed between versions
| MySQL from | Symbol | Message |
|---|---|---|
| 5.0.96 | ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE | You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column |
| 5.7.44 | ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE | You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column. %s |
| 8.0.11 | ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE | You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column |
| 8.0.16 | ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE | You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column. %s |