Take it from someone who has done this (and has been operating on MySQL for years and regrets it), you’ll want to use PostgreSQL if you have control over your tech stack. It has an extension called PostGIS (in addition to other database features not present in MySQL) that will allow you to do much more of this kind of processing at the database level. MySQL’s geometry support is unfortunately primitive.
Also - help appreciated in improving Wikidata. I built a few tools you may want to check out that can assist with working with it:
- Announcing📣: US boundary tagging QA checker
- 🎉 Announcing: human-readable wikidata browser plugins for openstreetmap.org
There is also a tool called QuickStatements that’s capable of bulk changes to Wikidata (for example, bulk setting P131 after running spatial queries…)
Lastly, because Wikidata has a rich relationship model, it can handle a lot more of the real-world complexity, such as cities and town which span more than one county (good luck with that one…)
You’re also going to need to figure out what to do in places that don’t have municipalities. Hawaii, Maryland, and Virginia have been the biggest offenders so far. Those are places where CDPs can be good substitutes.
Between OSM and Wikidata there should be a pretty complete representation of the real-world boundary scheme, or at least, the ability to store it for places that are incomplete.