It depends on how you are executing those queries:
- If you are loading an SQL file, execute then with
--force, and errors will be ignored (all errors! So if you want to catch other possible issues, that is going to be a problem)
- If run from an application, you can execute each command individually and only ignore on truncate for the specific
table not found error
- With some sql logic, you can check for table existence on information_schema.tables, although you may need to create a procedure just for that (raw command line doesn't allow for programming logic directly).
I think implementing that outside of SQL would be the preferred method (there is no "good" dynamic SQL execution on MySQL (other than tricks with prepared statements). E.g. a bash one liner (no error or escaping handling):
mysql -BN -e "SELECT CONCAT(TABLE_SCHEMA, '.', TABLE_NAME)
WHERE table_schema in ('schemas', 'to', 'process')
AND table_name like '\_%\_tmp'"
| while read table; do mysql -e "TRUNCATE TABLE $table"; done