Fix MySQL Workbench Safe Mode – UPDATE or DELETE Blocked
In this tutorial, you'll learn about Fix MySQL Workbench Safe Mode. We cover key concepts, practical examples, and best practices.
You write a straightforward UPDATE or DELETE in MySQL Workbench:
DELETE FROM users WHERE status = 'inactive';
And get:
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column.
You know the query is safe, but Workbench blocks it.
Wrong ❌
You try to work around it by adding an artificial key condition:
DELETE FROM users WHERE status = 'inactive' AND id > 0;
This works — but it's a hack. You might forget to do it next time, or accidentally run an unsafe query because you're numb to the warning.
You consider disabling safe mode globally, which defeats the purpose entirely.
Right ✅
Option A — Toggle safe mode for the session:
- In the query toolbar, find the Safe Updates icon (a yellow triangle with a key)
- Click it to toggle → icon turns grey → safe mode off
- Run your query again
DELETE FROM users WHERE status = 'inactive';
1175 rows affected in 43 ms
Option B — Use a key column properly:
DELETE FROM users
WHERE status = 'inactive'
AND id IN (SELECT id FROM users WHERE status = 'inactive' LIMIT 1000);
Or for UPDATE:
UPDATE users SET status = 'archived'
WHERE id IN (SELECT id FROM (SELECT id FROM users WHERE status = 'inactive' LIMIT 1000) AS tmp);
Option C — Disable permanently (for trusted dev environments):
SET SQL_SAFE_UPDATES = 0;
Or in Workbench preferences: Edit → Preferences → SQL Editor → ☐ Safe Updates (rejects UPDATE/DELETE with no restrictions).
Root Cause
MySQL Workbench enables SQL_SAFE_UPDATES by default. This session variable prevents UPDATE and DELETE statements that lack a key‑based WHERE clause. The goal is to prevent accidental mass updates — but it triggers even on obviously safe queries.
Prevention
- Keep safe mode ON in production — it's a safety net.
- Toggle it off per‑session when running batch operations where you've verified the WHERE clause.
- Use
SELECT count(*)with the same WHERE to preview the affected rows before running the DELETE/UPDATE. - For recurring batch jobs, write stored procedures that explicitly
SET SQL_SAFE_UPDATES = 0at the start.
Common Mistakes with workbench safe mode
- Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad - Mixing let bindings with <- bindings in do notation, producing type errors
These mistakes appear frequently in real-world MYSQL code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Safe query practices are covered in the DodaTech MySQL Workbench Safety course.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro