Corresponding columns on the master's and the slave's copies of the same table ideally should have the same data type. However, beginning with MySQL 5.1.21, this is not always strictly enforced, as long as certain conditions are met.
All other things being equal, it is always possible to
replicate from a column of a given data type to another column
of the same type and same size or width, where applicable, or
larger. For example, you can replicate from a
CHAR(10) column to another
CHAR(10), or from a
CHAR(10) column to a
CHAR(25) column without any problems. In
certain cases, it also possible to replicate from a column
having one data type (on the master) to a column having a
different data type (on the slave); when the data type of the
master's version of the column is promoted to a type that
is the same size or larger on the slave, this is known as
Attribute promotion can be used with both statement-based and row-based replication, and is not dependent on the storage engine used by either the master or the slave. However, the choice of logging format does have an effect on the type conversions that are permitted; the particulars are discussed later in this section.
Whether you use statement-based or row-based replication, the slave's copy of the table cannot contain more columns than the master's copy if you wish to employ attribute promotion.
When using statement-based replication, a simple rule of
thumb to follow is, “If the statement run on the
master would also execute successfully on the slave, it
should also replicate successfully”. In other words,
if the statement uses a value that is compatible with the
type of a given column on the slave, the statement can be
replicated. For example, you can insert any value that fits
TINYINT column into a
BIGINT column as well; it follows that,
even if you change the type of a
column in the slave's copy of a table to
BIGINT, any insert into that column on
the master that succeeds should also succeed on the slave,
since it is impossible to have a legal
TINYINT value that is large enough to
Prior to MySQL 5.5.30, when using statement-based replication,
AUTO_INCREMENT columns were required to be
the same on both the master and the slave; otherwise, updates
could be applied to the wrong table on the slave. (Bug
Row-based replication: attribute promotion and demotion.
Formerly, due to the fact that in row-based replication
changes rather than statements are replicated, and that
these changes are transmitted using formats that do not
always map directly to MySQL server column data types, you
could not replicate between different subtypes of the same
general type (for example, from
subtypes). However, beginning with MySQL 5.5.3, MySQL
Replication supports attribute promotion and demotion
between smaller data types and larger types. It is also
possible to specify whether or not to permit lossy
(truncated) or non-lossy conversions of demoted column
values, as explained later in this section.
Lossy and non-lossy conversions. In the event that the target type cannot represent the value being inserted, a decision must be made on how to handle the conversion. If we permit the conversion but truncate (or otherwise modify) the source value to achieve a “fit” in the target column, we make what is known as a lossy conversion. A conversion which does not require truncation or similar modifications to fit the source column value in the target column is a non-lossy conversion.
Type conversion modes (slave_type_conversions variable).
The setting of the
global server variable controls the type conversion mode
used on the slave. This variable takes a set of values from
the following table, which shows the effects of each mode on
the slave's type-conversion behavior:
In this mode, type conversions that would mean loss of information are permitted.
This does not imply that non-lossy conversions are
permitted, merely that only cases requiring either
lossy conversions or no conversion at all are
permitted; for example, enabling
only this mode permits an
This mode permits conversions that do not require truncation or other special handling of the source value; that is, it permits conversions where the target type has a wider range than the source type.
Setting this mode has no bearing on whether lossy
conversions are permitted; this is controlled with the
When this mode is set, all supported type conversions are permitted, whether or not they are lossy conversions.
This mode is the default.
Changing the type conversion mode requires restarting the
slave with the new
Supported conversions. Supported conversions between different but similar data types are shown in the following list:
This includes conversions between the signed and unsigned versions of these types.
Lossy conversions are made by truncating the source value to the maximum (or minimum) permitted by the target column. For insuring non-lossy conversions when going from unsigned to signed types, the target column must be large enough to accommodate the range of values in the source column. For example, you can demote
TINYINT UNSIGNEDnon-lossily to
SMALLINT, but not to
DOUBLEis a non-lossy conversion;
FLOATcan only be handled lossily. A conversion from
D') >= (
D) are non-lossy; for any case where
, or both, only a lossy conversion can be made.
For any of the decimal types, if a value to be stored cannot be fit in the target type, the value is rounded down according to the rounding rules defined for the server elsewhere in the documentation. See Rounding Behavior, for information about how this is done for decimal types.
Conversion of a
TEXTcolumn the same size or larger is never lossy. Lossy conversion is handled by inserting only the first
Ncharacters of the string on the slave, where
Nis the width of the target column.Important
Replication between columns using different character sets is not supported.
Conversion of a
BLOBcolumn the same size or larger is never lossy. Lossy conversion is handled by inserting only the first
Nbytes of the string on the slave, where
Nis the width of the target column.
Between any 2
BITcolumns of any 2 sizes.
When inserting a value from a
BIT(column into a
, the most significant bits of the
BIT(columns are cleared (set to zero) and the
Mbits of the
BIT(value are set as the least significant bits of the
When inserting a value from a source
BIT(column into a target
, the maximum possible value for the
BIT(column is assigned; in other words, an “all-set” value is assigned to the target column.
Conversions between types not in the previous list are not permitted.
Replication type conversions in MySQL 5.5.3 and earlier.
Prior to MySQL 5.5.3, with row-based binary logging, you
could not replicate between different
subtypes, such as from
BIGINT, because changes to columns of
these types were represented differently from one another in
the binary log when using row-based logging. (However, you
could replicate from
TEXT using row-based replication because
TEXT columns were represented using the
same format in the binary log.)
Supported conversions for attribute promotion when using row-based replication prior to MySQL 5.5.3 are shown in the following table:
|From (Master)||To (Slave)|
In all cases, the size or width of the column on the slave
must be equal to or greater than that of the column on the
master. For example, you could replicate from a
CHAR(10) column on the master to a column
BINARY(25) on the slave, but you could
not replicate from a
CHAR(10) column on
the master to
BINARY(5) column on the
Any unique index (including primary keys) having a prefix must use a prefix of the same length on both master and slave; in such cases, differing prefix lengths are disallowed. It is possible to use a nonunique index whose prefix length differs between master and slave, but this can cause serious performance issues, particularly when the prefix used on the master is longer. This is due to the fact that 2 unique prefixes of a given length may no longer be unique at a shorter length; for example, the words catalogue and catamount have the 5-character prefixes catal and catam, respectively, but share the same 4-character prefix (cata). This can lead to queries that use such indexes executing less efficiently on the slave, when a shorter prefix is employed in the slave' definition of the same index than on the master.
NUMERIC columns, both the
mantissa (M) and the number of decimals
(D) must be the same size or larger on
the slave as compared with the master. For example,
replication from a
NUMERIC(5,4) to a
DECIMAL(6,4) worked, but not from a
NUMERIC(5,4) to a
Prior to MySQL 5.5.3, MySQL replication did not support attribute promotion of any of the following data types to or from any other data type when using row-based replication: