How to Fix MySQL Error 3902 (ER_UNIT_NOT_FOUND)
You get mysql error 3902 when a query passes an unknown unit of measure. You fix it by checking the MySQL system catalog and using a valid unit name. MySQL maps this problem to symbol ER_UNIT_NOT_FOUND and SQLSTATE SU001. The database engine stops the query and says there is no unit of measure with that name. This issue happens during spatial calculations that convert distances between points. When the unit string does not match the internal list, the query fails right away. What causes mysql
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 3902 when a query passes an unknown unit of measure. You fix it by checking the MySQL system catalog and using a valid unit name.
MySQL maps this problem to symbol ER_UNIT_NOT_FOUND and SQLSTATE SU001. The database engine stops the query and says there is no unit of measure with that name. This issue happens during spatial calculations that convert distances between points. When the unit string does not match the internal list, the query fails right away.
What causes mysql error 3902 in spatial queries
MySQL includes built-in spatial tools that measure distances on a globe or flat plane. Many of these tools accept an optional unit name to format the output. When a developer or app sends a unit name, the engine checks a catalog table. If the string is missing from that table, the engine returns error 3902.
Simple typos are the most common cause for this error in daily work. A developer might write plural words like meters instead of the exact singular name. Case changes or extra spaces inside the text string can also break the lookup. Sometimes an app passes an abbreviation like km when the engine expects the full word.
Data pipeline bugs can also trigger this failure during batch runs. If a user picks a distance unit from a form, the app might pass it raw. When the front end and the database use different naming rules, queries will fail. Old migration scripts from other database engines can also bring in unsupported unit names.
How to find and fix the bad unit name safely
To fix this error, you must inspect the exact query that failed in production. Check your app error logs to find the string sent in the message. Next, read the spatial reference catalog inside your MySQL server to see valid unit names. You only need basic read permissions on system views to check this list.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Do not grant broad admin roles to developers just to debug a broken spatial query. Keep production roles tight and let engineers read the catalog through safe, scoped views. Once you find the right unit spelling, update the query in your app code. You should also add an input check in the app to block bad strings early.
How to prevent spatial unit errors in production
Hardcoding unit strings across many query files makes future updates hard to manage. Instead, store your allowed unit names in a shared app constant or lookup list. Test that list against your target MySQL version before you deploy new code. This small step stops bad strings before they ever reach the database engine.
When teams run manual queries to check spatial data, mistakes happen even more often. Giving engineers direct admin logins to run ad-hoc fixes creates security and audit risks. Instead, route database traffic through a central proxy that logs every query and user role. You can also apply data masking to rewrite emails, phone numbers, card numbers, and national IDs in results.
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 SQLSTATE SU001 mean in MySQL?
SQLSTATE SU001 is the standard state code paired with MySQL error 3902 and symbol ER_UNIT_NOT_FOUND. It tells the client app that a spatial function received an unknown unit of measure.
Where does MySQL store valid units of measure?
MySQL stores valid spatial units in its internal information schema under the spatial reference tables. You can run a read query on this view to see every supported unit name.
Can a database upgrade cause error 3902?
Standard units stay stable across versions, so upgrades rarely break working spatial queries. Still, moving SQL code from another database brand to MySQL often exposes unit naming differences.
Related guides
In this post