I have a long script that I need to run on several different databases (all witht he same tables and field names).
What I would like to do is something like this:
It will work if you concat the entire query. Try:
set @db = 'mydb'; set @tble = 'table'; set @query = concat('INSERT INTO tablefoo SELECT * FROM ', @db, '.', @tble); PREPARE stmt FROM @query; EXECUTE stmt; DEALLOCATE PREPARE stmt;