Common SQL Errors

MySQL Error 3120: ER_TABLESPACE_IS_NOT_EMPTY - How to Fix and Prevent

Galaxy Team
August 8, 2025

MySQL raises this error when you try to drop or discard a tablespace that still contains tables, indexes, or undo logs.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 3120 (ER_TABLESPACE_IS_NOT_EMPTY)?

ER_TABLESPACE_IS_NOT_EMPTY appears when MySQL refuses to drop or discard a tablespace that still holds objects. Confirm all tables are removed or moved, then retry the DROP TABLESPACE or ALTER TABLE ... DISCARD TABLESPACE command.

Error Highlights

Typical Error Message

ER_TABLESPACE_IS_NOT_EMPTY

Error Type

Storage Engine Error

Language

MySQL

Symbol

ER_TABLESPACE_IS_NOT_EMPTY was added in 5.7.6.

Error Code

3120

SQL State

HY000

Explanation

Table of Contents

What is MySQL error 3120 (ER_TABLESPACE_IS_NOT_EMPTY)?

The message Tablespace `%s` is not empty means MySQL detected data inside the target tablespace right before executing a DROP TABLESPACE or DISCARD TABLESPACE operation.

The storage engine halts the operation to protect remaining tables, indexes, or undo logs from accidental loss.

What Causes This Error?

The most common trigger is running ALTER TABLE mytable DISCARD TABLESPACE while rows or indexes are still resident in the .ibd file.

Administrators also see the error after issuing DROP TABLESPACE when child tables are still assigned to the same space.

How to Fix ER_TABLESPACE_IS_NOT_EMPTY

First verify which objects live in the space using INFORMATION_SCHEMA.INNODB_SYS_TABLES or SHOW CREATE TABLE for each candidate table.

Once all objects are handled, reissue the DROP or DISCARD command and MySQL will complete successfully.

Common Scenarios and Solutions

Partitioned tables often leave fragments in the target file. Use ALTER TABLE ... REMOVE PARTITIONING to consolidate before dropping.

When foreign key relationships exist, drop or move dependent tables to another space prior to the main operation.

Best Practices to Avoid This Error

Always audit the tablespace with INFORMATION_SCHEMA views before destructive operations.

Automate checks in deployment scripts to confirm space usage counts are zero before attempting DROP or DISCARD.

Related Errors and Solutions

ER_IB_MSG_762 indicates a tablespace name collision during import. Resolve by renaming the .ibd file or choosing a unique space ID.

ER_TABLESPACE_EXISTS emerges when the target space already exists during CREATE TABLESPACE. Verify names and remove unused spaces.

Common Causes

Typical Causes

Object residue left after incomplete DROP TABLE statements.

Hidden indexes or partition fragments still assigned to the space.

Active undo logs when using file-per-table and the space is targeted too early.

Related Errors

ER_TABLESPACE_EXISTS

Appears when attempting to create a tablespace that already exists. Fix by dropping or renaming the existing space.

ER_TABLESPACE_MISSING

Raised when a referenced tablespace cannot be found on disk. Verify file paths and metadata.

FAQs

Does this error affect replication?

The statement is written to the binary log only if it succeeds, so replicas stay consistent.

Can I disable the safety check?

No. MySQL storage engine enforces it to protect data integrity.

Which MySQL versions raise error 3120?

It was introduced in 5.7.6 and persists in all later major versions.

How does Galaxy help prevent it?

Galaxy highlights dependent objects in an interactive schema tree, making it easy to confirm a tablespace is empty before executing destructive SQL.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo