How to Fix MySQL Error 3120 (ER_TABLESPACE_IS_NOT_EMPTY)
You get mysql error 3120 when you try to drop a tablespace that holds tables. To fix it, you must drop or move every table inside that tablespace first. MySQL maps this failure to symbol ER_TABLESPACE_IS_NOT_EMPTY and SQLSTATE HY000. The engine returns the message that the named tablespace is not empty. This rule stops you from deleting active table data by mistake. Why mysql error 3120 happens in the engine MySQL lets you group multiple tables into one shared general tablespace. This setup
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You get mysql error 3120 when you try to drop a tablespace that holds tables. To fix it, you must drop or move every table inside that tablespace first.
MySQL maps this failure to symbol ER_TABLESPACE_IS_NOT_EMPTY and SQLSTATE HY000. The engine returns the message that the named tablespace is not empty. This rule stops you from deleting active table data by mistake.
Why mysql error 3120 happens in the engine
MySQL lets you group multiple tables into one shared general tablespace. This setup differs from file-per-table storage, where each table has its own file. When you drop a file-per-table table, the engine deletes its storage file right away.
A general tablespace acts like a shared folder for many tables. If you ask the engine to drop that shared space, it checks the metadata. If even one table remains inside, the engine blocks the drop request. It raises mysql error 3120 to keep your data safe.
This error often surprises teams during schema cleanups. An engineer drops a few known tables and thinks the space is clear. Still, hidden tables, archive tables, or old partitions may still live there. Partitioned tables can also keep a single partition inside the shared space. As long as one table object links to that space, the drop fails.
Orphaned metadata can also trigger this issue after a crash. If a past table drop failed midway, the data dictionary might still list the table. The storage engine checks the dictionary before it deletes any disk files.
How to find remaining tables in the tablespace
Before you can remove the tablespace, you must list everything inside it. Do not guess which tables use the space. Instead, query the system metadata catalog to see the exact list of tables.
Your database admin or read-only role can check the information schema views. Look for table records and partition records that match the target tablespace name. Check every schema on the server, not just your main app schema. A shared tablespace can hold tables from many different databases at the same time.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Make sure you also check for partitioned tables. A table might store most partitions in one place and one partition in your target space. Once you have the full list, review each table with your team. Decide which tables you need to keep and which ones you can delete.
How to fix the error and drop the tablespace
After you find the remaining tables, you have two ways to empty the space. You can move the tables to new storage, or you can drop them. Pick the path that fits your data retention rules.
If a table still holds live app data, move it out of the shared space. You can run an alter table operation to reassign its tablespace to file-per-table storage. You can also move the table into a different general tablespace. Note that moving a table rebuilds it and uses disk and CPU resources. Run table moves during low traffic hours so you do not slow down user requests.
If the remaining tables hold old test data or temp records, drop them. Double-check your backups before you delete any table in production. Watch out for foreign key links between tables. If a parent table links to a child table, drop them in the right order. Never turn off foreign key checks in production just to rush a cleanup.
Once you move or drop the last table, check the metadata view one more time. Confirm that zero tables and zero partitions reference the target space. Now you can run the drop tablespace action again. The engine will see that the space is empty and remove the file from disk.
Keep your access rules tight during this whole fix. Engineers do not need full superuser rights on the server to check metadata. Grant read roles for the check phase, and use reviewed change flows for the drop phase.
Check MySQL queries and results on the wire
MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.
Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.
Frequently asked questions
What does ER_TABLESPACE_IS_NOT_EMPTY mean in MySQL?
It means you tried to drop a general tablespace that still contains one or more tables. MySQL blocks the action until you remove or move every table inside that space.
Can I force MySQL to drop a non-empty tablespace in one step?
No, MySQL does not have a cascade option for dropping general tablespaces. You must drop or move each individual table before you can drop the tablespace itself.
Why does a tablespace still show as not empty after I drop my schema?
A general tablespace is not tied to a single database schema. Tables or partitions from another schema on the same server still live inside that shared tablespace.
Related guides
In this post