I know you'd have to use SHOW DATABASES, SHOW TABLES and SHOW COLUMNS, but how to use them correctly in a mysql procedure is a little out of my league. Am not sure how to check for the right datatype to match your value. Hopefully someone else will pick this up.
What means "optimum code" ? In number of code lines? In performance? In usability?
Maybe I would try to solve this not in MySQL but in plain text format on a dump file with regular expressions (grep or, in PHP, preg). This could be the optimum in coding efficiency.
If you're in one of those predicaments where cls.__private attributes just aren't enough since they can easily be accessed through inst._cls__private, and you need something a little more secure, here's ...