Use MySQL to delete terms to save me from the single-term manual delete process.

I needed to delete a bunch (Over 100) of child terms from a Vocabulary and save the parents.
I needed to do this without sitting in front of a web browser and waiting for a page to load every time.

Disclaimer: BYODD (Backup YOur Database, Dummy!) before attempting any instructions on this site. Owners AND all Affiliates are NOT responsible for anything YOU screw up by following any instructions you find here.

Anyway... I'll cut to the chase... then explain. here are the queries I ran:


mysql> create table temp1 as select d.*,h.parent from term_data d, term_hierarchy h where d.tid=h.tid and d.vid=21 and h.parent!=0;
Query OK

I'm probably wrong about this and just don't know how to do it... but I was unable to delete rows from multiple tables at a time so I created a temp table from the select statement above which included all the terms that were not parent terms (parent != 0)


mysql> delete from term_data where tid in (select tid from temp1);
Query OK

Delete the terms that exist in the temp table.


mysql> delete from term_hierarchy where tid in (select tid from temp1);
Query OK, 139 rows affected (0.18 sec)

Delete the terms from hierarchy that exist in the temp table.

Technologies: