https://stackoverflow.com/questions/9479056/table-exists-method-might-not-be-working-properly https://dba.stackexchange.com/questions/53836/how-long-will-it-take-to-rename-table INSERT with check exist (normally we often using UNIQUE key then INSERT IGNORE). https://stackoverflow.com/questions/3164505/mysql-insert-record-if-not-exists-in-table https://stackoverflow.com/questions/38601880/unable-to-rename-table-due-to-metadata-lock RENAME TABLE will terminate the transaction. You can do both renames in a single, atomic, statement (no transaction): RENAME TABLE `main_territorypricing` TO `main_territorypricing2`, `main_territorypricing1` TO `main_territorypricing`; It will have to wait for any other connections that are busy with any of the tables; make sure you don't have some connection not letting go. https://tech.smartling.com/wrangling-gigantic-tables-in-mysql-universal-language-40274d89151b Copy data between databases. https://stackoverflow.com/questions/12242...
Some tribes of the programmer clan.