MySQL applies these rules when
CREATE
TABLE ... SELECT
statements are replicated:
CREATE TABLE ... SELECT
always performs an implicit commit (Statements That Cause an Implicit Commit).If the destination table does not exist, logging occurs as follows. It does not matter whether
IF NOT EXISTS
is present.STATEMENT
orMIXED
format: The statement is logged as written.ROW
format: The statement is logged as aCREATE TABLE
statement followed by a series of insert-row events.
If the statement fails, nothing is logged. This includes the case that the destination table exists and
IF NOT EXISTS
is not given.If the destination table exists and
IF NOT EXISTS
is given, MySQL ignores the statement completely; nothing is inserted or logged.
MySQL 5.6 does not allow a
CREATE
TABLE ... SELECT
statement to make any changes in
tables other than the table that is created by the statement.
Some older versions of MySQL permitted these statements to do
so; this means that, when using replication between a MySQL 5.6
or later replica and a source running a previous version of
MySQL, a
CREATE
TABLE ... SELECT
statement causing changes in other
tables on the source fails on the replica, causing replication
to stop. To prevent this from happening, you should use
row-based replication, rewrite the offending statement before
running it on the source, or upgrade the source to MySQL
5.6. (If you choose to upgrade the source, keep in
mind that such a
CREATE
TABLE ... SELECT
statement fails following the upgrade
unless it is rewritten to remove any side effects on other
tables.)