Mysql library fixes

Fixes for #14857 (database upgrade from Frodo to Gotham Alpha)
Fixed situation with triggers not copied when upgrading MySQL db
Moved triggers creation code to separate sub to ensure that they are equal for db create and update to last version
Some SQL code cleanup