This section discusses how MySQL replicates
CREATE
TABLE ... SELECT
statements.
These behaviors are not dependent on MySQL version:
CREATE TABLE ... SELECT
always performs an implicit commit (Section 12.3.3, “Statements That Cause an Implicit Commit”).If 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.
When the destination table exists and IF NOT
EXISTS
is given, MySQL handles the statement in a
version-dependent way.
In MySQL 5.1 before 5.1.51 and in MySQL 5.5 before 5.5.6 (this is the original behavior):
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.
In MySQL 5.1 as of 5.1.51:
STATEMENT
orMIXED
format: The statement is logged as the equivalent pair ofCREATE TABLE
andINSERT INTO ... SELECT
statements.ROW
format: The statement is logged as aCREATE TABLE
statement followed by a series of insert-row events.
In MySQL 5.5 as of 5.5.6:
Nothing is inserted or logged.
These version dependencies arise due to a change in MySQL 5.5.6
in handling of
CREATE
TABLE ... SELECT
not to insert rows if the destination
table already exists, and a change made in MySQL 5.1.51 to
preserve forward compatibility in replication of such statements
from a 5.1 master to a 5.5 slave. For details, see
Section 12.1.14.1, “CREATE TABLE ...
SELECT
Syntax”.