Menu

MySQL Error 1175: Safe Update Mode

Fix MySQL Error 1175 with a key-based WHERE clause or a carefully limited update, and check sql_safe_updates for the current session.

Posted on By
On this page

MySQL Error 1175 (HY000, ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE) occurs when safe update mode blocks an UPDATE or DELETE that has neither a key-based WHERE condition nor a LIMIT. The error message says the statement tried to change a table without a WHERE clause that uses a key. See the MySQL 8.4 error reference and sql_safe_updates.

Check whether safe update mode is enabled

sql_safe_updates is a session variable. Check it in the same connection that ran the failing statement:

SELECT @@SESSION.sql_safe_updates;

Some client options, including the mysql --safe-updates option, enable safe updates for the connection. A session setting can also be changed without changing the server’s global default.

Prefer a key-based condition

Suppose product_name is not indexed. Safe update mode can reject this statement even though it has a WHERE clause:

UPDATE products
SET discontinued = 1
WHERE product_name = 'Old model';

If the intent is to update one product, filter by its primary key:

UPDATE products
SET discontinued = 1
WHERE product_id = 42;

Before running a broad change, preview its target rows with a SELECT using the same condition. If the condition represents a common lookup, consider whether an index on that column fits the data model and query workload; do not add an index only to silence Error 1175.

Use a limit only when a batch is intended

Safe update mode also permits an update with LIMIT. Make the batch order explicit and verify each batch before repeating it:

UPDATE products
SET discontinued = 1
WHERE product_name = 'Old model'
ORDER BY product_id
LIMIT 100;

Without ORDER BY, the selected rows are not a deterministic batch. If the operation must update every matching row atomically, a LIMIT changes that behavior; plan the update deliberately instead of adding a limit merely to bypass the safeguard.

Disable the safeguard only for a reviewed bulk change

If a full-table change is genuinely intended, first verify the affected row count and the exact statement. You can temporarily disable safe updates for the current session, run the reviewed operation, and re-enable the safeguard:

SET SESSION sql_safe_updates = 0;

-- Run the reviewed UPDATE or DELETE here.

SET SESSION sql_safe_updates = 1;

This changes a safety check, not the correctness of the WHERE condition. Prefer a key-based condition when it expresses the intended rows. For standard UPDATE syntax and examples, see the MySQL UPDATE tutorial. Browse all MySQL error troubleshooting guides.