67

I am trying to delete all records from a table. My query is:

delete from tableName.

But it reports the following error:

Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor -> Query Editor and reconnect."

How do I resolve this?

Kev
  • 118,037
  • 53
  • 300
  • 385
Sami
  • 3,956
  • 9
  • 37
  • 52
  • 5
    I might be missing something, but the error message already tells you what to do: *toggle the option in Preferences -> SQL Editor -> Query Editor and reconnect.* –  Nov 11 '11 at 07:53
  • i am using mySQL Workbench and it thorws this error. – Sami Nov 11 '11 at 08:14
  • Ok...MySQL Workbench is telling how to solve this: *toggle the option in Preferences -> SQL Editor -> Query Editor and reconnect.*. Have you tried that? If you have and it still doesn't work then flag to re-open. – Kev Nov 11 '11 at 11:05
  • 1
    There are two solutions here 1. delete from table where 1=1 . 2. truncate – lokeshjain2008 Jan 23 '14 at 14:42
  • I had this problem today and resolved it by adding a limit clause `delete from tableName limit 1000`, you can replace 1000 by whatever the count of the table is (`select count(*) from tableName`) – Bug Killer Sep 18 '14 at 14:49
  • I learned there was a setting for when deleting in mysql from this not real question – Lealo Aug 17 '17 at 03:12

2 Answers2

94

truncate tableName

That is what you are looking for.

Truncate will delete all records in the table, emptying it.

Thirler
  • 20,239
  • 14
  • 63
  • 92
69

It’s because you tried to update a table without a WHERE that uses a KEY column.

The quick fix is to add SET SQL_SAFE_UPDATES=0; before your query :

SET SQL_SAFE_UPDATES=0; 

Or

close the safe update mode. Edit -> Preferences -> SQL Editor -> SQL Editor remove Forbid UPDATE and DELETE statements without a WHERE clause (safe updates) .

BTW you can use TRUNCATE TABLE tablename; to delete all the records .

jincy mariam
  • 589
  • 6
  • 7
Sandeep Pathak
  • 10,567
  • 8
  • 45
  • 57
  • For the record, the latest version (and may be the previous ones) also fail when you use TRUNCATE TABLE. Also, the error is still the same, however the option is in Edit->Preferencie -> SQL Queries (and not in SQL Editor). – magallanes Oct 19 '12 at 14:53