Mysql – How to prevent crashes connected with dropped tables during thesql import

importMySQL

I have made a mysql dump with mysqldump, tables are dropped and re-created with

DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (

However for a read-intensive database I sometimes get crashes connected with table "users" missing completely – this must happen when table is dropped and immediately created again. How do I make mysql wait until table is created?

Best Answer

This is a big problem with the design of your system!

You are apparently performing DDL on a running application. This is never a good idea. The one Open Source server which does support transactional DDL is PostgreSQL - from here:

You can't recover from an add/drop on a database or tablespace, but all other catalog operations are reversible.

MySQL even in its latest version (as of 05/2018) - verion 8, doesn't support tranactional DDL - from here:

Some statements cannot be rolled back. In general, these include data definition language (DDL) statements, such as those that create or drop databases, those that create, drop, or alter tables or stored routines.

This page goes on to say:

You should design your transactions not to include such statements. If you issue a statement early in a transaction that cannot be rolled back, and then another statement later fails, the full effect of the transaction cannot be rolled back in such cases by issuing a ROLLBACK statement. [Emphasis mine]

What, exactly, will, or will not, be rolled back isn't specified in detail - bit of a lottery situation which will require lots of testing! I wouldn't open that can of worms if I were you!

Could you possibly expand expand on your question by letting us know why, exactly, you feel that you need to issue such commands against a running application and maybe we can help you find a more suitable alternative solution?