MySQL 8.4Lab-verified · 2026-12-01

MySQL ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column

sql_safe_updates is on, and the UPDATE or DELETE has no WHERE condition that can use a key (index).

MySQL 8.4.13
1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column.

Jump to a cause

  1. 01UPDATE with WHERE on a column that has no index
  2. 02DELETE FROM table with no WHERE
  3. 03WHERE DATE(created_at) = ... on an indexed column
  4. 04An indexed string column is compared to an unquoted number

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-12-01 · container image mysql:8.4

ERROR 1175 is not a data problem. It is a guard: with sql_safe_updates = 1, MySQL refuses UPDATE and DELETE statements whose WHERE cannot use a key, because they might touch every row.

On the MySQL 8.4 server used here the default is 0 for both session and global, so the error appears only when a client or session turns it on. Each case below starts with SET SESSION sql_safe_updates = 1. 4 cases reproduced on MySQL 8.4.

01UPDATE with WHERE on a column that has no index

name has no index, so WHERE name = 'kim' cannot use a key. It matches only one row, but safe update mode does not look at that.

Setup
Setuprun as lab_a
CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(20), status VARCHAR(10));
INSERT INTO users VALUES (1, 'kim', 'active'), (2, 'lee', 'active');
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
SET SESSION sql_safe_updates = 1;
UPDATE users SET status = 'locked' WHERE name = 'kim';
✕ ERROR
Query OK, 0 rows affected (0.00 sec)

ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column.
Checkrun as lab_a
SELECT id, name, status FROM users WHERE name = 'kim';
OUTPUT
+----+------+--------+
| id | name | status |
+----+------+--------+
|  1 | kim  | active |
+----+------+--------+
1 row in set (0.00 sec)

Look up the primary key first (SELECT id ... WHERE name = 'kim' returned id 1), then update by key: UPDATE users SET status = 'locked' WHERE id = 1; worked with safe mode still on (1 row affected).

After the fixrun as lab_a
SET SESSION sql_safe_updates = 1;
UPDATE users SET status = 'locked' WHERE id = 1;
SELECT * FROM users;
✓ SUCCESS
Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

+----+------+--------+
| id | name | status |
+----+------+--------+
|  1 | kim  | locked |
|  2 | lee  | active |
+----+------+--------+
2 rows in set (0.00 sec)

02DELETE FROM table with no WHERE

Clearing a work table with DELETE FROM temp_import; has no WHERE at all, which is exactly what safe update mode blocks.

Setup
Setuprun as lab_a
CREATE TABLE temp_import (id INT PRIMARY KEY, line VARCHAR(100));
INSERT INTO temp_import VALUES (1, 'a'), (2, 'b'), (3, 'c');
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
SET SESSION sql_safe_updates = 1;
DELETE FROM temp_import;
✕ ERROR
Query OK, 0 rows affected (0.00 sec)

ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column.
Checkrun as lab_a
SELECT @@SESSION.sql_safe_updates AS session_value, @@GLOBAL.sql_safe_updates AS global_value;
OUTPUT
+---------------+--------------+
| session_value | global_value |
+---------------+--------------+
|             0 |            0 |
+---------------+--------------+
1 row in set (0.00 sec)

If you really mean all rows, switch it off for that one statement and back on: SET SESSION sql_safe_updates = 0; → DELETE (3 rows affected) → SET SESSION sql_safe_updates = 1;. The setting is per session; a new session here showed 0 for both session and global.

After the fixrun as lab_a
SET SESSION sql_safe_updates = 1;
SET SESSION sql_safe_updates = 0;
DELETE FROM temp_import;
SET SESSION sql_safe_updates = 1;
SELECT COUNT(*) FROM temp_import;
✓ SUCCESS
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 3 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

+----------+
| COUNT(*) |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)

03WHERE DATE(created_at) = ... on an indexed column

created_at has an index (idx_created), but wrapping it in DATE() means the index cannot be used, so it counts as a WHERE without a key.

Setup
Setuprun as lab_a
CREATE TABLE orders (id INT PRIMARY KEY, created_at DATETIME, status VARCHAR(10), KEY idx_created (created_at));
INSERT INTO orders VALUES (1, '2026-11-01 09:00:00', 'new'), (2, '2026-11-02 10:00:00', 'new');
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
SET SESSION sql_safe_updates = 1;
UPDATE orders SET status = 'closed' WHERE DATE(created_at) = '2026-11-01';
✕ ERROR
Query OK, 0 rows affected (0.00 sec)

ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column.
Checkrun as lab_a
SHOW INDEX FROM orders;
OUTPUT
+--------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| Table  | Non_unique | Key_name    | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
+--------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| orders |          0 | PRIMARY     |            1 | id          | A         |           2 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
| orders |          1 | idx_created |            1 | created_at  | A         |           2 |     NULL |   NULL | YES  | BTREE      |         |               | YES     | NULL       |
+--------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
2 rows in set (0.00 sec)

SHOW INDEX confirms idx_created on created_at. Write a range on the bare column instead: WHERE created_at >= '2026-11-01' AND created_at < '2026-11-02'. It updated 1 row with safe mode on.

After the fixrun as lab_a
SET SESSION sql_safe_updates = 1;
UPDATE orders SET status = 'closed'
WHERE created_at >= '2026-11-01' AND created_at < '2026-11-02';
SELECT * FROM orders;
✓ SUCCESS
Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

+----+---------------------+--------+
| id | created_at          | status |
+----+---------------------+--------+
|  1 | 2026-11-01 09:00:00 | closed |
|  2 | 2026-11-02 10:00:00 | new    |
+----+---------------------+--------+
2 rows in set (0.00 sec)

04An indexed string column is compared to an unquoted number

phone is VARCHAR(20) with the index idx_phone, but WHERE phone = 01012345678 compares it to a number without quotes, and the UPDATE failed with 1175. The 8.4 message spells out why: Cannot use range access on index 'idx_phone' due to type or collation conversion on field 'phone'.

Comparing a string column with a number makes MySQL convert every row, so the index cannot be used, and safe update mode sees no WHERE on a key column.

Setup
Setuprun as lab_a
CREATE TABLE members (id INT PRIMARY KEY, phone VARCHAR(20), status VARCHAR(10), KEY idx_phone (phone));
INSERT INTO members VALUES (1, '01012345678', 'active'), (2, '01098765432', 'active');
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
SET SESSION sql_safe_updates = 1;
UPDATE members SET status = 'blocked' WHERE phone = 01012345678;
✕ ERROR
Query OK, 0 rows affected (0.00 sec)

ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column. Cannot use range access on index 'idx_phone' due to type or collation conversion on field 'phone'
Check the causerun as lab_a
EXPLAIN SELECT * FROM members WHERE phone = 01012345678;
EXPLAIN SELECT * FROM members WHERE phone = '01012345678';
OUTPUT
+----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table   | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | members | NULL       | ALL  | idx_phone     | NULL | NULL    | NULL |    2 |    50.00 | Using where |
+----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+
1 row in set, 3 warnings (0.00 sec)

+----+-------------+---------+------------+------+---------------+-----------+---------+-------+------+----------+-------+
| id | select_type | table   | partitions | type | possible_keys | key       | key_len | ref   | rows | filtered | Extra |
+----+-------------+---------+------------+------+---------------+-----------+---------+-------+------+----------+-------+
|  1 | SIMPLE      | members | NULL       | ref  | idx_phone     | idx_phone | 83      | const |    1 |   100.00 | NULL  |
+----+-------------+---------+------------+------+---------------+-----------+---------+-------+------+----------+-------+
1 row in set, 1 warning (0.00 sec)

EXPLAIN for the numeric comparison shows type ALL and key NULL (full scan). With quotes it shows type ref and key idx_phone.

Checkrun as lab_a
SELECT column_name, data_type FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'members' AND column_name = 'phone';
OUTPUT
+-------------+-----------+
| COLUMN_NAME | DATA_TYPE |
+-------------+-----------+
| phone       | varchar   |
+-------------+-----------+
1 row in set (0.00 sec)

Writing the value as a string, '01012345678', updated 1 row with safe update mode still on. A number also drops the leading zero, so always quote values for string columns such as phone numbers and codes.

After the fixrun as lab_a
SET SESSION sql_safe_updates = 1;
UPDATE members SET status = 'blocked' WHERE phone = '01012345678';
SELECT * FROM members ORDER BY id;
✓ SUCCESS
Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

+----+-------------+---------+
| id | phone       | status  |
+----+-------------+---------+
|  1 | 01012345678 | blocked |
|  2 | 01098765432 | active  |
+----+-------------+---------+
2 rows in set (0.00 sec)

FAQ

How do I fix MySQL error 1175?

Put a key column in the WHERE (for example the primary key), or if you really mean to change many rows, run SET SESSION sql_safe_updates = 0 before the statement and set it back to 1 after.

How do I disable safe update mode in MySQL?

SET SESSION sql_safe_updates = 0; It only affects the current session. Check it with SELECT @@SESSION.sql_safe_updates, @@GLOBAL.sql_safe_updates.

My WHERE column has an index, why do I still get 1175?

Wrapping the column in a function such as DATE() stops the index from being used. Rewrite it as a range on the bare column (created_at >= ... AND created_at < ...).

Is the safe update mode on by default?

Not on the MySQL 8.4 server here: both session and global values were 0. It is switched on by the client or by SET SESSION sql_safe_updates = 1.

1175 says due to type or collation conversion even though the column is indexed.

The value's type does not match the column. In the run above, a VARCHAR column was compared to an unquoted number, so the index could not be used. Quoting the value let the UPDATE run with safe update mode on.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13