MySQL 5.6 upgrades are in full swing these days and knowing how to safely upgrade from MySQL 5.5 to 5.6 is important. When upgrading a replication environment, it’s important that you can build a migration plan that safely allows for your upgrade with minimal risk — rollback is often a very important component to this.
For many people this means upgrading slaves first and then the master. The strategy of an older master replicating to a newer slave is well known and has been supported in MySQL replication for a very long time. To be specific: you can have a MySQL 5.6 slave of a 5.5 master and this should work fine until you upgrade your master and/or promote one of the slaves to be the master.
However, there are those of us who like to live on the edge and do unsupported things. Suppose that when you cut over to that MySQL 5.6 master your application completely breaks. What would your rollback plan be? In such a case, leaving a 5.5 slave of the new 5.6 master (or perhaps a dual-master setup with 5.5 and 5.6) would be useful to allow you to rollback to but still have the data written on the 5.6 master.
With Statement-based replication (SBR), you are generally ok with this type of setup, provided you aren’t doing any MySQL 5.6 syntax-specific things until you don’t have any more 5.5 slaves. However, with Row-based replication (RBR), things are a bit trickier, particularly when column formats change.
Now, one nice new feature of MySQL 5.6 is the improvement of the storage requirements for DATETIME fields as well as the addition of fractional second support for TIME, DATETIME, and TIMESTAMP. This is great, but unfortunately this is a new column format that 5.5 clearly would not understand. Does this put our 5.6 to 5.5 replication in jeopardy? The answer is, if we’re careful, NO.
Quite simply, MySQL 5.6 supports both old and new types and mysql_upgrade does not make such a conversion on existing tables. Only NEW tables or REBUILT tables in 5.6 will use the new format. Any tables from 5.5 with a simple mysql_upgrade to 5.6 will still be using the old types. For more information on how to find columns in 5.6 that are using the old format, see Ike Walker’s excellent blog post on the topic. (Thanks Ike!)
To test this out, I created a simple experiment. I have a master and slave using RBR, both on 5.5, and I setup pt-heartbeat to update the master. I realized that pt-heartbeat actually uses a varchar for the timestamp field — I suspect this makes multiple database support easier. However, since pt-heartbeat’s update uses a NOW() to populate that field, I can convert it to a DATETIME:
|
1 |
[root@master ~]# pt-heartbeat --update --database percona --create-table<br>CREATE TABLE `heartbeat` (<br> `ts` varchar(26) NOT NULL,<br> `server_id` int(10) unsigned NOT NULL,<br> `file` varchar(255) DEFAULT NULL,<br> `position` bigint(20) unsigned DEFAULT NULL,<br> `relay_master_log_file` varchar(255) DEFAULT NULL,<br> `exec_master_log_pos` bigint(20) unsigned DEFAULT NULL,<br> PRIMARY KEY (`server_id`)<br>) ENGINE=InnoDB DEFAULT CHARSET=latin1<br><br>master mysql> alter table heartbeat drop column ts, add column ts DATETIME;<br><br>slave mysql> select * from heartbeatG<br> *************************** 1. row ***************************<br> server_id: 1<br> file: master-bin.000002<br> position: 5107583<br> relay_master_log_file: NULL<br> exec_master_log_pos: NULL<br> ts: 2014-05-02 17:03:59<br> 1 row in set (0.00 sec)<br><br> CREATE TABLE `heartbeat` (<br> `server_id` int(10) unsigned NOT NULL,<br> `file` varchar(255) DEFAULT NULL,<br> `position` bigint(20) unsigned DEFAULT NULL,<br> `relay_master_log_file` varchar(255) DEFAULT NULL,<br> `exec_master_log_pos` bigint(20) unsigned DEFAULT NULL,<br> `ts` datetime DEFAULT NULL,<br> PRIMARY KEY (`server_id`)<br> ) ENGINE=InnoDB DEFAULT CHARSET=latin1 <br> |
So my heartbeat table now has a 5.5 DATETIME, pt-heartbeat is working properly, and the heartbeat is replicating to the slave. Now I will upgrade my master to MySQL 5.6:
|
1 |
[root@master ~]# rpm -e Percona-Server-devel-55-5.5.36-rel34.2.el6.x86_64 Percona-Server-shared-55-5.5.36-rel34.2.el6.x86_64 Percona-Server-client-55-5.5.36-rel34.2.el6.x86_64 Percona-Server-server-55-5.5.36-rel34.2.el6.x86_64 --nodeps<br>[root@master ~]# yum install Percona-Server-server-56.x86_64<br>==============================================================================================================<br>Package Arch Version Repository Size<br>==============================================================================================================<br>Installing:<br>Percona-Server-server-56 x86_64 5.6.16-rel64.2.el6 Percona 19 M<br>Installing for dependencies:<br>Percona-Server-client-56 x86_64 5.6.16-rel64.2.el6 Percona 6.8 M<br>Percona-Server-shared-56 x86_64 5.6.16-rel64.2.el6 Percona 712 k<br><br>Transaction Summary<br>==============================================================================================================<br>Install 3 Package(s)<br>...<br><br>[root@master ~]# service mysql start<br>Starting MySQL (Percona Server)....... SUCCESS!<br>[root@master ~]# mysql<br>Welcome to the MySQL monitor. Commands end with ; or g.<br>Your MySQL connection id is 1<br>Server version: 5.6.16-64.2-56-log Percona Server (GPL), Release 64.2, Revision 569<br><br>[root@master ~]# mysql_upgrade<br>Looking for 'mysql' as: mysql<br>Looking for 'mysqlcheck' as: mysqlcheck<br>Running 'mysqlcheck with default connection arguments<br>Running 'mysqlcheck with default connection arguments<br>mysql.columns_priv OK<br>mysql.db OK<br>mysql.event OK<br>mysql.func OK<br>mysql.general_log OK<br>mysql.help_category OK<br>mysql.help_keyword OK<br>mysql.help_relation OK<br>mysql.help_topic OK<br>mysql.host OK<br>mysql.ndb_binlog_index OK<br>mysql.plugin OK<br>mysql.proc OK<br>mysql.procs_priv OK<br>mysql.proxies_priv OK<br>mysql.servers OK<br>mysql.slow_log OK<br>mysql.tables_priv OK<br>mysql.time_zone OK<br>mysql.time_zone_leap_second OK<br>mysql.time_zone_name OK<br>mysql.time_zone_transition OK<br>mysql.time_zone_transition_type OK<br>mysql.user OK<br>Running 'mysql_fix_privilege_tables'...<br>Running 'mysqlcheck with default connection arguments<br>Running 'mysqlcheck with default connection arguments<br>percona.heartbeat OK<br>OK<br> |
I can now verify that Ike’s INFORMATION_SCHEMA queries correctly detect the ‘heartbeat.ts’ column as the old format:
|
1 |
master mysql> select t.table_schema,t.engine,t.table_name,c.column_name,c.column_type<br>from information_schema.tables t <br> inner join information_schema.columns c on c.table_schema = t.table_schema and c.table_name = t.table_name<br> left outer join information_schema.innodb_sys_tables ist on ist.name = concat(t.table_schema,'/',t.table_name)<br> left outer join information_schema.innodb_sys_columns isc on isc.table_id = ist.table_id and isc.name = c.column_name <br>where c.column_type in ('time','timestamp','datetime')<br> and t.table_schema not in ('mysql','information_schema','performance_schema')<br> and t.table_type = 'base table'<br> and (t.engine != 'innodb' or (t.engine = 'innodb' and isc.mtype = 6))<br>order by t.table_schema,t.table_name,c.column_name;<br><br> +--------------+--------+------------+-------------+-------------+<br> | table_schema | engine | table_name | column_name | column_type |<br> +--------------+--------+------------+-------------+-------------+<br> | percona | InnoDB | heartbeat | ts | datetime |<br> +--------------+--------+------------+-------------+-------------+<br> 1 row in set (0.04 sec)<br> |
To make replication work from MySQL 5.6 to 5.5, I also had to add a few backwards compatibility options on the master:
|
1 |
log_bin_use_v1_row_events = ON<br>binlog_checksum = NONE<br> |
Once I fixed that up, I can verify my slave is still working after this and receiving heartbeats. Clearly the new formats are not a show-stopper for backwards replication compatibility.
|
1 |
slave mysql> show slave statusG<br>*************************** 1. row ***************************<br> Slave_IO_State: Waiting for master to send event<br> Master_Host: 192.168.70.2<br> Master_User: repl<br> Master_Port: 3306<br> Connect_Retry: 60<br> Master_Log_File: master-bin.000005<br> Read_Master_Log_Pos: 120<br> Relay_Log_File: slave-relay-bin.000002<br> Relay_Log_Pos: 267<br> Relay_Master_Log_File: master-bin.000005<br> Slave_IO_Running: Yes<br> Slave_SQL_Running: Yes<br><br>master mysql> select * from heartbeat;<br>+-----------+-------------------+----------+-----------------------+---------------------+---------------------+<br>| server_id | file | position | relay_master_log_file | exec_master_log_pos | ts |<br>+-----------+-------------------+----------+-----------------------+---------------------+---------------------+<br>| 1 | master-bin.000002 | 5115935 | NULL | NULL | 2014-05-02 17:04:23 |<br>+-----------+-------------------+----------+-----------------------+---------------------+---------------------+<br>1 row in set (0.01 sec)<br><br>slave mysql> select * from heartbeat;<br>+-----------+-------------------+----------+-----------------------+---------------------+---------------------+<br>| server_id | file | position | relay_master_log_file | exec_master_log_pos | ts |<br>+-----------+-------------------+----------+-----------------------+---------------------+---------------------+<br>| 1 | master-bin.000002 | 5115935 | NULL | NULL | 2014-05-02 17:04:23 |<br>+-----------+-------------------+----------+-----------------------+---------------------+---------------------+<br>1 row in set (0.00 sec)<br> |
But, if I’m not careful on MySQL 5.6, and rebuild the table, the new format does clearly bite me:
|
1 |
master mysql> set sql_log_bin=0;<br>Query OK, 0 rows affected (0.00 sec)<br><br>master mysql> alter table percona.heartbeat force;<br>Query OK, 1 row affected, 1 warning (0.18 sec)<br>Records: 1 Duplicates: 0 Warnings: 1<br><br>master mysql> show warnings;<br>+-------+------+-------------------------------------------------------------------------------------+<br>| Level | Code | Message |<br>+-------+------+-------------------------------------------------------------------------------------+<br>| Note | 1880 | TIME/TIMESTAMP/DATETIME columns of old format have been upgraded to the new format. |<br>+-------+------+-------------------------------------------------------------------------------------+<br>1 row in set (0.00 sec)<br><br>slave mysql> show slave statusG<br>*************************** 1. row ***************************<br>...<br> Slave_IO_Running: Yes<br> Slave_SQL_Running: No<br>...<br> Last_Errno: 1677<br> Last_Error: Column 5 of table 'percona.heartbeat' cannot be converted from type '' to type 'datetime'<br>...<br> Last_SQL_Errno: 1677<br> Last_SQL_Error: Column 5 of table 'percona.heartbeat' cannot be converted from type '' to type 'datetime'<br> Replicate_Ignore_Server_Ids:<br> Master_Server_Id: 1<br>1 row in set (0.00 sec)<br> |
What does all this teach us?
While the MySQL version is important, for RBR what matters most is the actual current format for each column. Your master and slave(s) MUST have the same column formats for RBR to work right.
So, the new temporal formats do not necessarily break RBR replication back to 5.5, provided:
However, I want to make it clear that MySQL 5.6 to 5.5 replication is technically unsupported. I have not exhausted all possibilities for problems with 5.6 to 5.5 RBR replication, just this specific one. If you choose to make an upgrade strategy that relies on backwards replication in this way, be prepared for it to not work and test it thoroughly in advance. The purpose of this post is to simply point out that data type formats, in and of themselves, do not necessarily break RBR backwards compatibility.
Resources
RELATED POSTS