summaryrefslogtreecommitdiffstats
path: root/mysql-test/suite/binlog_encryption
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 12:24:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 12:24:36 +0000
commit06eaf7232e9a920468c0f8d74dcf2fe8b555501c (patch)
treee2c7b5777f728320e5b5542b6213fd3591ba51e2 /mysql-test/suite/binlog_encryption
parentInitial commit. (diff)
downloadmariadb-06eaf7232e9a920468c0f8d74dcf2fe8b555501c.tar.xz
mariadb-06eaf7232e9a920468c0f8d74dcf2fe8b555501c.zip
Adding upstream version 1:10.11.6.upstream/1%10.11.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mysql-test/suite/binlog_encryption')
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_incident.combinations8
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_incident.result13
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_incident.test2
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_index.result190
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_index.test1
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_ioerr.result33
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_ioerr.test1
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_mdev_20574_old_binlog.result27
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_mdev_20574_old_binlog.test46
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_mysqlbinlog-cp932-master.opt1
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_mysqlbinlog-cp932.result19
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_mysqlbinlog-cp932.test2
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_row_annotate-master.opt1
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_row_annotate.combinations6
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_row_annotate.result720
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_row_annotate.test2
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_write_error.result113
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_write_error.test1
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_xa_recover.result229
-rw-r--r--mysql-test/suite/binlog_encryption/binlog_xa_recover.test1
-rw-r--r--mysql-test/suite/binlog_encryption/disabled.def2
-rw-r--r--mysql-test/suite/binlog_encryption/encrypted_master.result626
-rw-r--r--mysql-test/suite/binlog_encryption/encrypted_master.test188
-rw-r--r--mysql-test/suite/binlog_encryption/encrypted_master_lost_key.result111
-rw-r--r--mysql-test/suite/binlog_encryption/encrypted_master_lost_key.test206
-rw-r--r--mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_coords.cnf5
-rw-r--r--mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_coords.result92
-rw-r--r--mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_coords.test166
-rw-r--r--mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_gtid.cnf8
-rw-r--r--mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_gtid.result84
-rw-r--r--mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_gtid.test154
-rw-r--r--mysql-test/suite/binlog_encryption/encrypted_slave.cnf12
-rw-r--r--mysql-test/suite/binlog_encryption/encrypted_slave.result176
-rw-r--r--mysql-test/suite/binlog_encryption/encrypted_slave.test119
-rw-r--r--mysql-test/suite/binlog_encryption/encryption_algorithms.combinations5
-rw-r--r--mysql-test/suite/binlog_encryption/encryption_algorithms.inc2
-rw-r--r--mysql-test/suite/binlog_encryption/encryption_combo.cnf5
-rw-r--r--mysql-test/suite/binlog_encryption/encryption_combo.result78
-rw-r--r--mysql-test/suite/binlog_encryption/encryption_combo.test137
-rw-r--r--mysql-test/suite/binlog_encryption/multisource.cnf17
-rw-r--r--mysql-test/suite/binlog_encryption/multisource.result251
-rw-r--r--mysql-test/suite/binlog_encryption/multisource.test1
-rw-r--r--mysql-test/suite/binlog_encryption/my.cnf27
-rw-r--r--mysql-test/suite/binlog_encryption/mysqlbinlog.combinations6
-rw-r--r--mysql-test/suite/binlog_encryption/mysqlbinlog.result7
-rw-r--r--mysql-test/suite/binlog_encryption/mysqlbinlog.test24
-rw-r--r--mysql-test/suite/binlog_encryption/restart_server.inc35
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_binlog_errors.cnf7
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_binlog_errors.result286
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_binlog_errors.test2
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_cant_read_event_incident.result33
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_cant_read_event_incident.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_checksum.cnf10
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_checksum.result206
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_checksum.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_checksum_cache.result119
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_checksum_cache.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_corruption.cnf9
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_corruption.result67
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_corruption.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_gtid_basic.cnf24
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_gtid_basic.combinations6
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_gtid_basic.result646
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_gtid_basic.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_incident.cnf7
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_incident.result51
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_incident.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_init_slave_errors.result23
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_init_slave_errors.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_loaddata_local.result134
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_loaddata_local.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_loadfile.result254
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_loadfile.test12
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_mixed_binlog_max_cache_size.result217
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_mixed_binlog_max_cache_size.test7
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_packet.cnf10
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_packet.result83
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_packet.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_analyze_table_hang.result51
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_analyze_table_hang.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_deadlock_corrupt_binlog.result94
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_deadlock_corrupt_binlog.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_domain.result71
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_domain.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_domain_slave_single_grp.result101
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_domain_slave_single_grp.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_free_deferred_event.result44
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_free_deferred_event.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_gco_wait_kill.result263
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_gco_wait_kill.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_gtid_slave_pos_update_fail.result65
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_gtid_slave_pos_update_fail.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_ignore_error_on_rotate.result74
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_ignore_error_on_rotate.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_ignored_errors.result51
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_ignored_errors.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_incorrect_relay_pos.result75
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_incorrect_relay_pos.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_innodb_lock_conflict.result79
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_innodb_lock_conflict.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_missed_error_handling.result65
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_missed_error_handling.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_mode.result75
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_mode.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_partial_binlog_trans.result51
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_partial_binlog_trans.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_record_gtid_wakeup.result48
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_record_gtid_wakeup.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_retry_deadlock.result192
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_retry_deadlock.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_rollback_assert.result45
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_rollback_assert.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.cnf6
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.result13
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_single_grpcmt.result161
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_single_grpcmt.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_slave_bgc_kill.result333
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_slave_bgc_kill.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_stop_on_con_kill.result102
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_stop_on_con_kill.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_stop_slave.result91
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_stop_slave.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_wrong_binlog_order.result75
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_wrong_binlog_order.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_wrong_exec_master_pos.result34
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_parallel_wrong_exec_master_pos.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_relayrotate-slave.opt5
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_relayrotate.result20
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_relayrotate.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_semi_sync.result477
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_semi_sync.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_skip_replication.cnf6
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_skip_replication.result317
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_skip_replication.test2
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_special_charset.opt1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_special_charset.result10
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_special_charset.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_sporadic_master-master.opt1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_sporadic_master.result28
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_sporadic_master.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_ssl.result59
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_ssl.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space-slave.opt1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space.result6
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.result460
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_sync-master.opt2
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_sync-slave.opt2
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_sync.result53
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_sync.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.cnf6
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.result91
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.test1
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.cnf6
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.result95
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.test6
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.cnf6
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.result95
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.test4
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_typeconv.result768
-rw-r--r--mysql-test/suite/binlog_encryption/rpl_typeconv.test1
-rw-r--r--mysql-test/suite/binlog_encryption/suite.pm18
-rw-r--r--mysql-test/suite/binlog_encryption/testdata.inc208
165 files changed, 11228 insertions, 0 deletions
diff --git a/mysql-test/suite/binlog_encryption/binlog_incident.combinations b/mysql-test/suite/binlog_encryption/binlog_incident.combinations
new file mode 100644
index 00000000..2269ed4a
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_incident.combinations
@@ -0,0 +1,8 @@
+[stmt]
+binlog-format=statement
+
+[mix]
+binlog-format=mixed
+
+[row]
+binlog-format=row
diff --git a/mysql-test/suite/binlog_encryption/binlog_incident.result b/mysql-test/suite/binlog_encryption/binlog_incident.result
new file mode 100644
index 00000000..7a555743
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_incident.result
@@ -0,0 +1,13 @@
+RESET MASTER;
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+SELECT * FROM t1;
+a
+1
+2
+3
+REPLACE INTO t1 VALUES (4);
+DROP TABLE t1;
+FLUSH LOGS;
+Contain RELOAD DATABASE
+1
diff --git a/mysql-test/suite/binlog_encryption/binlog_incident.test b/mysql-test/suite/binlog_encryption/binlog_incident.test
new file mode 100644
index 00000000..6fc59959
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_incident.test
@@ -0,0 +1,2 @@
+--let $use_remote_mysqlbinlog= 1
+--source suite/binlog/include/binlog_incident.inc
diff --git a/mysql-test/suite/binlog_encryption/binlog_index.result b/mysql-test/suite/binlog_encryption/binlog_index.result
new file mode 100644
index 00000000..9dfda71f
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_index.result
@@ -0,0 +1,190 @@
+call mtr.add_suppression('Attempting backtrace');
+call mtr.add_suppression('MYSQL_BIN_LOG::purge_logs failed to process registered files that would be purged.');
+call mtr.add_suppression('MYSQL_BIN_LOG::open failed to sync the index file');
+call mtr.add_suppression('Turning logging off for the whole duration of the MariaDB server process.');
+call mtr.add_suppression('Could not use .*');
+call mtr.add_suppression('MYSQL_BIN_LOG::purge_logs failed to clean registers before purging logs.');
+flush tables;
+SET @saved_dbug = @@SESSION.debug_dbug;
+RESET MASTER;
+flush logs;
+flush logs;
+flush logs;
+show binary logs;
+Log_name File_size
+master-bin.000001 #
+master-bin.000002 #
+master-bin.000003 #
+master-bin.000004 #
+flush tables;
+purge binary logs TO 'master-bin.000004';
+Warnings:
+Warning 1612 Being purged log master-bin.000001 was not found
+*** must show a list starting from the 'TO' argument of PURGE ***
+show binary logs;
+Log_name File_size
+master-bin.000004 #
+reset master;
+flush logs;
+flush logs;
+flush logs;
+*** must be a warning master-bin.000001 was not found ***
+Warnings:
+Warning 1612 Being purged log master-bin.000001 was not found
+*** must show one record, of the active binlog, left in the index file after PURGE ***
+show binary logs;
+Log_name File_size
+master-bin.000004 #
+reset master;
+flush logs;
+flush logs;
+flush logs;
+purge binary logs TO 'master-bin.000002';
+ERROR HY000: Fatal error during log purge
+show warnings;
+Level Code Message
+Warning 1377 a problem with deleting master-bin.000001; consider examining correspondence of your binlog index file to the actual binlog files
+Error 1377 Fatal error during log purge
+reset master;
+# crash_purge_before_update_index
+flush logs;
+SET SESSION debug_dbug="+d,crash_purge_before_update_index";
+purge binary logs TO 'master-bin.000002';
+ERROR HY000: Lost connection to server during query
+SET @index=LOAD_FILE('MYSQLTEST_VARDIR/mysqld.1/data//master-bin.index');
+SELECT @index;
+@index
+master-bin.000001
+master-bin.000002
+master-bin.000003
+
+# crash_purge_non_critical_after_update_index
+flush logs;
+SET SESSION debug_dbug="+d,crash_purge_non_critical_after_update_index";
+purge binary logs TO 'master-bin.000004';
+ERROR HY000: Lost connection to server during query
+SET @index=LOAD_FILE('MYSQLTEST_VARDIR/mysqld.1/data//master-bin.index');
+SELECT @index;
+@index
+master-bin.000004
+master-bin.000005
+
+# crash_purge_critical_after_update_index
+flush logs;
+SET SESSION debug_dbug="+d,crash_purge_critical_after_update_index";
+purge binary logs TO 'master-bin.000006';
+ERROR HY000: Lost connection to server during query
+SET @index=LOAD_FILE('MYSQLTEST_VARDIR/mysqld.1/data//master-bin.index');
+SELECT @index;
+@index
+master-bin.000006
+master-bin.000007
+
+# crash_create_non_critical_before_update_index
+SET SESSION debug_dbug="+d,crash_create_non_critical_before_update_index";
+flush logs;
+ERROR HY000: Lost connection to server during query
+SET @index=LOAD_FILE('MYSQLTEST_VARDIR/mysqld.1/data//master-bin.index');
+SELECT @index;
+@index
+master-bin.000006
+master-bin.000007
+master-bin.000008
+
+# crash_create_critical_before_update_index
+SET SESSION debug_dbug="+d,crash_create_critical_before_update_index";
+flush logs;
+ERROR HY000: Lost connection to server during query
+SET @index=LOAD_FILE('MYSQLTEST_VARDIR/mysqld.1/data//master-bin.index');
+SELECT @index;
+@index
+master-bin.000006
+master-bin.000007
+master-bin.000008
+master-bin.000009
+
+# crash_create_after_update_index
+SET SESSION debug_dbug="+d,crash_create_after_update_index";
+flush logs;
+ERROR HY000: Lost connection to server during query
+SET @index=LOAD_FILE('MYSQLTEST_VARDIR/mysqld.1/data//master-bin.index');
+SELECT @index;
+@index
+master-bin.000006
+master-bin.000007
+master-bin.000008
+master-bin.000009
+master-bin.000010
+master-bin.000011
+
+#
+# This should put the server in unsafe state and stop
+# accepting any command. If we inject a fault at this
+# point and continue the execution the server crashes.
+#
+SET @index=LOAD_FILE('MYSQLTEST_VARDIR/mysqld.1/data//master-bin.index');
+SELECT @index;
+@index
+master-bin.000006
+master-bin.000007
+master-bin.000008
+master-bin.000009
+master-bin.000010
+master-bin.000011
+
+# fault_injection_registering_index
+SET SESSION debug_dbug="+d,fault_injection_registering_index";
+flush logs;
+ERROR HY000: Can't open file: 'master-bin.000012' (errno: 1 "Operation not permitted")
+SET @index=LOAD_FILE('MYSQLTEST_VARDIR/mysqld.1/data//master-bin.index');
+SELECT @index;
+@index
+master-bin.000006
+master-bin.000007
+master-bin.000008
+master-bin.000009
+master-bin.000010
+master-bin.000011
+
+# restart
+SET @index=LOAD_FILE('MYSQLTEST_VARDIR/mysqld.1/data//master-bin.index');
+SELECT @index;
+@index
+master-bin.000006
+master-bin.000007
+master-bin.000008
+master-bin.000009
+master-bin.000010
+master-bin.000011
+master-bin.000012
+
+# fault_injection_updating_index
+SET SESSION debug_dbug="+d,fault_injection_updating_index";
+flush logs;
+ERROR HY000: Can't open file: 'master-bin.000013' (errno: 1 "Operation not permitted")
+SET @index=LOAD_FILE('MYSQLTEST_VARDIR/mysqld.1/data//master-bin.index');
+SELECT @index;
+@index
+master-bin.000006
+master-bin.000007
+master-bin.000008
+master-bin.000009
+master-bin.000010
+master-bin.000011
+master-bin.000012
+
+# restart
+SET @index=LOAD_FILE('MYSQLTEST_VARDIR/mysqld.1/data//master-bin.index');
+SELECT @index;
+@index
+master-bin.000006
+master-bin.000007
+master-bin.000008
+master-bin.000009
+master-bin.000010
+master-bin.000011
+master-bin.000012
+master-bin.000013
+
+SET @@SESSION.debug_dbug = @saved_dbug;
+End of tests
diff --git a/mysql-test/suite/binlog_encryption/binlog_index.test b/mysql-test/suite/binlog_encryption/binlog_index.test
new file mode 100644
index 00000000..cd48a313
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_index.test
@@ -0,0 +1 @@
+--source suite/binlog/include/binlog_index.inc
diff --git a/mysql-test/suite/binlog_encryption/binlog_ioerr.result b/mysql-test/suite/binlog_encryption/binlog_ioerr.result
new file mode 100644
index 00000000..2823b705
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_ioerr.result
@@ -0,0 +1,33 @@
+CALL mtr.add_suppression("Error writing file 'master-bin'");
+RESET MASTER;
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=innodb;
+INSERT INTO t1 VALUES(0);
+SET @saved_dbug = @@SESSION.debug_dbug;
+SET SESSION debug_dbug='+d,fail_binlog_write_1';
+INSERT INTO t1 VALUES(1);
+ERROR HY000: Error writing file 'master-bin' (errno: 28 "No space left on device")
+INSERT INTO t1 VALUES(2);
+ERROR HY000: Error writing file 'master-bin' (errno: 28 "No space left on device")
+SET SESSION debug_dbug=@saved_dbug;
+INSERT INTO t1 VALUES(3);
+SELECT * FROM t1;
+a
+0
+3
+SHOW BINLOG EVENTS;
+Log_name Pos Event_type Server_id End_log_pos Info
+BINLOG POS Format_desc 1 ENDPOS Server ver: #, Binlog ver: #
+BINLOG POS Start_encryption 1 ENDPOS
+BINLOG POS Gtid_list 1 ENDPOS []
+BINLOG POS Binlog_checkpoint 1 ENDPOS master-bin.000001
+BINLOG POS Gtid 1 ENDPOS GTID 0-1-1
+BINLOG POS Query 1 ENDPOS use `test`; CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=innodb
+BINLOG POS Gtid 1 ENDPOS BEGIN GTID 0-1-2
+BINLOG POS Query 1 ENDPOS use `test`; INSERT INTO t1 VALUES(0)
+BINLOG POS Xid 1 ENDPOS COMMIT /* XID */
+BINLOG POS Gtid 1 ENDPOS BEGIN GTID 0-1-3
+BINLOG POS Gtid 1 ENDPOS BEGIN GTID 0-1-4
+BINLOG POS Gtid 1 ENDPOS BEGIN GTID 0-1-5
+BINLOG POS Query 1 ENDPOS use `test`; INSERT INTO t1 VALUES(3)
+BINLOG POS Xid 1 ENDPOS COMMIT /* XID */
+DROP TABLE t1;
diff --git a/mysql-test/suite/binlog_encryption/binlog_ioerr.test b/mysql-test/suite/binlog_encryption/binlog_ioerr.test
new file mode 100644
index 00000000..e77ecd6d
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_ioerr.test
@@ -0,0 +1 @@
+--source suite/binlog/include/binlog_ioerr.inc
diff --git a/mysql-test/suite/binlog_encryption/binlog_mdev_20574_old_binlog.result b/mysql-test/suite/binlog_encryption/binlog_mdev_20574_old_binlog.result
new file mode 100644
index 00000000..a8d96642
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_mdev_20574_old_binlog.result
@@ -0,0 +1,27 @@
+include/master-slave.inc
+[connection master]
+connection slave;
+include/stop_slave.inc
+connection master;
+include/rpl_stop_server.inc [server_number=1]
+# Data in binlog
+# CREATE TABLE t1 (a INT);
+# INSERT INTO t1 VALUES (1),(2),(3);
+# REPLACE INTO t1 VALUES (4);
+include/rpl_start_server.inc [server_number=1]
+connection slave;
+RESET SLAVE;
+RESET MASTER;
+CHANGE MASTER TO master_host='127.0.0.1', master_port=SERVER_MYPORT_1, master_user='root', master_log_file='master-bin.000001', master_log_pos=4, master_use_gtid=no;
+include/start_slave.inc
+DESC t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+SELECT * FROM t1 ORDER BY a;
+a
+1
+2
+3
+4
+DROP TABLE t1;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/binlog_mdev_20574_old_binlog.test b/mysql-test/suite/binlog_encryption/binlog_mdev_20574_old_binlog.test
new file mode 100644
index 00000000..3f822063
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_mdev_20574_old_binlog.test
@@ -0,0 +1,46 @@
+# MDEV-20574 Position of events reported by mysqlbinlog is wrong with encrypted binlogs, SHOW BINLOG EVENTS reports the correct one.
+# Test replicating off old master.
+# Test case Desc:- When new server reads the data from old server binlog which
+# does not send START_ENCRYPTION_EVENT to slave.
+# We simulate old master by copying in pre-generated binlog files from earlier
+# server versions with encrypted binlog.
+--source include/have_binlog_format_row.inc
+--source include/master-slave.inc
+--source include/have_innodb.inc
+
+--connection slave
+--source include/stop_slave.inc
+
+--connection master
+--let $datadir= `SELECT @@datadir`
+
+--let $rpl_server_number= 1
+--source include/rpl_stop_server.inc
+
+--remove_file $datadir/master-bin.000001
+--remove_file $datadir/master-bin.state
+--echo # Data in binlog
+--echo # CREATE TABLE t1 (a INT);
+--echo # INSERT INTO t1 VALUES (1),(2),(3);
+--echo # REPLACE INTO t1 VALUES (4);
+
+--copy_file $MYSQL_TEST_DIR/std_data/binlog_before_20574.bin $datadir/master-bin.000001
+
+--let $rpl_server_number= 1
+--source include/rpl_start_server.inc
+
+--source include/wait_until_connected_again.inc
+--save_master_pos
+
+--connection slave
+RESET SLAVE;
+RESET MASTER;
+--replace_result $SERVER_MYPORT_1 SERVER_MYPORT_1
+eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$SERVER_MYPORT_1, master_user='root', master_log_file='master-bin.000001', master_log_pos=4, master_use_gtid=no;
+--source include/start_slave.inc
+--sync_with_master
+DESC t1;
+SELECT * FROM t1 ORDER BY a;
+
+DROP TABLE t1;
+--source include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/binlog_mysqlbinlog-cp932-master.opt b/mysql-test/suite/binlog_encryption/binlog_mysqlbinlog-cp932-master.opt
new file mode 100644
index 00000000..bb0cda45
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_mysqlbinlog-cp932-master.opt
@@ -0,0 +1 @@
+--max-binlog-size=8192
diff --git a/mysql-test/suite/binlog_encryption/binlog_mysqlbinlog-cp932.result b/mysql-test/suite/binlog_encryption/binlog_mysqlbinlog-cp932.result
new file mode 100644
index 00000000..cbf61595
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_mysqlbinlog-cp932.result
@@ -0,0 +1,19 @@
+RESET MASTER;
+create table t3 (f text character set utf8);
+create table t4 (f text character set cp932);
+flush logs;
+rename table t3 to t03, t4 to t04;
+select HEX(f) from t03;
+HEX(f)
+E382BD
+select HEX(f) from t3;
+HEX(f)
+E382BD
+select HEX(f) from t04;
+HEX(f)
+835C
+select HEX(f) from t4;
+HEX(f)
+835C
+drop table t3, t4, t03, t04;
+End of 5.0 tests
diff --git a/mysql-test/suite/binlog_encryption/binlog_mysqlbinlog-cp932.test b/mysql-test/suite/binlog_encryption/binlog_mysqlbinlog-cp932.test
new file mode 100644
index 00000000..6232720b
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_mysqlbinlog-cp932.test
@@ -0,0 +1,2 @@
+--let $use_remote_mysqlbinlog= 1
+--source suite/binlog/include/binlog_mysqlbinlog-cp932.inc
diff --git a/mysql-test/suite/binlog_encryption/binlog_row_annotate-master.opt b/mysql-test/suite/binlog_encryption/binlog_row_annotate-master.opt
new file mode 100644
index 00000000..344a4ffc
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_row_annotate-master.opt
@@ -0,0 +1 @@
+--timezone=GMT-3 --binlog-do-db=test1 --binlog-do-db=test2 --binlog-do-db=test3 --binlog-checksum=NONE
diff --git a/mysql-test/suite/binlog_encryption/binlog_row_annotate.combinations b/mysql-test/suite/binlog_encryption/binlog_row_annotate.combinations
new file mode 100644
index 00000000..710c53d0
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_row_annotate.combinations
@@ -0,0 +1,6 @@
+[cmpr]
+log-bin-compress=1
+log-bin-compress-min-len=10
+
+[ncmpr]
+log-bin-compress=0
diff --git a/mysql-test/suite/binlog_encryption/binlog_row_annotate.result b/mysql-test/suite/binlog_encryption/binlog_row_annotate.result
new file mode 100644
index 00000000..583d9a30
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_row_annotate.result
@@ -0,0 +1,720 @@
+set @old_binlog_checksum=@@binlog_checksum;
+set global binlog_checksum=NONE;
+set sql_mode="";
+SET timestamp=1000000000;
+RESET MASTER;
+CREATE DATABASE test1;
+CREATE TABLE test1.t1(a int);
+CREATE DATABASE test2;
+CREATE TABLE test2.t2(a int);
+CREATE VIEW test2.v2 AS SELECT * FROM test2.t2;
+CREATE DATABASE test3;
+CREATE TABLE test3.t3(a int);
+CREATE DATABASE xtest1;
+CREATE TABLE xtest1.xt1(a int);
+CREATE DATABASE xtest2;
+CREATE TABLE xtest2.xt2(a int);
+INSERT INTO test1.t1 VALUES (1), (2), (3);
+SET SESSION binlog_annotate_row_events = ON;
+INSERT INTO test2.t2 VALUES (1), (2), (3);
+INSERT INTO test3.t3 VALUES (1), (2), (3);
+DELETE test1.t1, test2.t2
+FROM test1.t1 INNER JOIN test2.t2 INNER JOIN test3.t3
+WHERE test1.t1.a=test2.t2.a AND test2.t2.a=test3.t3.a;
+INSERT INTO xtest1.xt1 VALUES (1), (2), (3);
+INSERT INTO test2.v2 VALUES (1), (2), (3);
+DELETE xtest1.xt1, test2.t2
+FROM xtest1.xt1 INNER JOIN test2.t2 INNER JOIN test3.t3
+WHERE xtest1.xt1.a=test2.t2.a AND test2.t2.a=test3.t3.a;
+INSERT INTO xtest1.xt1 VALUES (1), (2), (3);
+INSERT INTO xtest2.xt2 VALUES (1), (2), (3);
+DELETE xtest1.xt1, xtest2.xt2
+FROM xtest1.xt1 INNER JOIN xtest2.xt2 INNER JOIN test3.t3
+WHERE xtest1.xt1.a=xtest2.xt2.a AND xtest2.xt2.a=test3.t3.a;
+FLUSH LOGS;
+#####################################################################################
+# The following Annotate_rows events should appear below:
+# - INSERT INTO test2.t2 VALUES (1), (2), (3)
+# - INSERT INTO test3.t3 VALUES (1), (2), (3)
+# - DELETE test1.t1, test2.t2 FROM <...>
+# - INSERT INTO test2.t2 VALUES (1), (2), (3)
+# - DELETE xtest1.xt1, test2.t2 FROM <...>
+#####################################################################################
+include/show_binlog_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000001 # Binlog_checkpoint # # master-bin.000001
+master-bin.000001 # Gtid # # GTID #-#-#
+master-bin.000001 # Query # # CREATE DATABASE test1
+master-bin.000001 # Gtid # # GTID #-#-#
+master-bin.000001 # Query # # CREATE DATABASE test2
+master-bin.000001 # Gtid # # GTID #-#-#
+master-bin.000001 # Query # # CREATE DATABASE test3
+master-bin.000001 # Gtid # # BEGIN GTID #-#-#
+master-bin.000001 # Annotate_rows # # INSERT INTO test1.t1 VALUES (1), (2), (3)
+master-bin.000001 # Table_map # # table_id: # (test1.t1)
+master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
+master-bin.000001 # Query # # COMMIT
+master-bin.000001 # Gtid # # BEGIN GTID #-#-#
+master-bin.000001 # Annotate_rows # # INSERT INTO test2.t2 VALUES (1), (2), (3)
+master-bin.000001 # Table_map # # table_id: # (test2.t2)
+master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
+master-bin.000001 # Query # # COMMIT
+master-bin.000001 # Gtid # # BEGIN GTID #-#-#
+master-bin.000001 # Annotate_rows # # INSERT INTO test3.t3 VALUES (1), (2), (3)
+master-bin.000001 # Table_map # # table_id: # (test3.t3)
+master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
+master-bin.000001 # Query # # COMMIT
+master-bin.000001 # Gtid # # BEGIN GTID #-#-#
+master-bin.000001 # Annotate_rows # # DELETE test1.t1, test2.t2
+FROM test1.t1 INNER JOIN test2.t2 INNER JOIN test3.t3
+WHERE test1.t1.a=test2.t2.a AND test2.t2.a=test3.t3.a
+master-bin.000001 # Table_map # # table_id: # (test1.t1)
+master-bin.000001 # Table_map # # table_id: # (test2.t2)
+master-bin.000001 # Delete_rows_v1 # # table_id: #
+master-bin.000001 # Delete_rows_v1 # # table_id: # flags: STMT_END_F
+master-bin.000001 # Query # # COMMIT
+master-bin.000001 # Gtid # # BEGIN GTID #-#-#
+master-bin.000001 # Annotate_rows # # INSERT INTO test2.v2 VALUES (1), (2), (3)
+master-bin.000001 # Table_map # # table_id: # (test2.t2)
+master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
+master-bin.000001 # Query # # COMMIT
+master-bin.000001 # Gtid # # BEGIN GTID #-#-#
+master-bin.000001 # Annotate_rows # # DELETE xtest1.xt1, test2.t2
+FROM xtest1.xt1 INNER JOIN test2.t2 INNER JOIN test3.t3
+WHERE xtest1.xt1.a=test2.t2.a AND test2.t2.a=test3.t3.a
+master-bin.000001 # Table_map # # table_id: # (test2.t2)
+master-bin.000001 # Delete_rows_v1 # # table_id: # flags: STMT_END_F
+master-bin.000001 # Query # # COMMIT
+master-bin.000001 # Rotate # # master-bin.000002;pos=POS
+#
+#####################################################################################
+# mysqlbinlog --read-from-remote-server
+# The following Annotates should appear in this output:
+# - INSERT INTO test2.t2 VALUES (1), (2), (3)
+# - INSERT INTO test3.t3 VALUES (1), (2), (3)
+# - DELETE test1.t1, test2.t2 FROM <...> (with two subsequent Table maps)
+# - INSERT INTO test2.t2 VALUES (1), (2), (3)
+# - DELETE xtest1.xt1, test2.t2 FROM <...> (with one subsequent Table map)
+#####################################################################################
+/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
+/*!40019 SET @@session.max_delayed_threads=0*/;
+/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
+DELIMITER /*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Start: binlog v 4, server v #.##.## created 010909 4:46:40 at startup
+ROLLBACK/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Ignorable
+# Ignorable event type 164 (Start_encryption)
+# at #
+#010909 4:46:40 server id # end_log_pos # Gtid list []
+# at #
+#010909 4:46:40 server id # end_log_pos # Binlog checkpoint master-bin.000001
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-1 ddl
+/*!100101 SET @@session.skip_parallel_replication=0*//*!*/;
+/*!100001 SET @@session.gtid_domain_id=0*//*!*/;
+/*!100001 SET @@session.server_id=1*//*!*/;
+/*!100001 SET @@session.gtid_seq_no=1*//*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+SET @@session.pseudo_thread_id=#/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1, @@session.check_constraint_checks=1, @@session.sql_if_exists=0, @@session.explicit_defaults_for_timestamp=1, @@session.system_versioning_insert_history=0/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=X,@@session.collation_connection=X,@@session.collation_server=X/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
+CREATE DATABASE test1
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-2 ddl
+/*!100001 SET @@session.gtid_seq_no=2*//*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+CREATE DATABASE test2
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-3 ddl
+/*!100001 SET @@session.gtid_seq_no=3*//*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+CREATE DATABASE test3
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-4
+/*!100001 SET @@session.gtid_seq_no=4*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # Annotate_rows:
+#Q> INSERT INTO test1.t1 VALUES (1), (2), (3)
+#010909 4:46:40 server id # end_log_pos # Table_map: `test1`.`t1` mapped to number #
+# at #
+#010909 4:46:40 server id # end_log_pos # Write_rows: table id # flags: STMT_END_F
+### INSERT INTO `test1`.`t1`
+### SET
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test1`.`t1`
+### SET
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test1`.`t1`
+### SET
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+# Number of rows: 3
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-5
+/*!100001 SET @@session.gtid_seq_no=5*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # Annotate_rows:
+#Q> INSERT INTO test2.t2 VALUES (1), (2), (3)
+#010909 4:46:40 server id # end_log_pos # Table_map: `test2`.`t2` mapped to number #
+# at #
+#010909 4:46:40 server id # end_log_pos # Write_rows: table id # flags: STMT_END_F
+### INSERT INTO `test2`.`t2`
+### SET
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test2`.`t2`
+### SET
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test2`.`t2`
+### SET
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+# Number of rows: 3
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-6
+/*!100001 SET @@session.gtid_seq_no=6*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # Annotate_rows:
+#Q> INSERT INTO test3.t3 VALUES (1), (2), (3)
+#010909 4:46:40 server id # end_log_pos # Table_map: `test3`.`t3` mapped to number #
+# at #
+#010909 4:46:40 server id # end_log_pos # Write_rows: table id # flags: STMT_END_F
+### INSERT INTO `test3`.`t3`
+### SET
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test3`.`t3`
+### SET
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test3`.`t3`
+### SET
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+# Number of rows: 3
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-7
+/*!100001 SET @@session.gtid_seq_no=7*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # Annotate_rows:
+#Q> DELETE test1.t1, test2.t2
+#Q> FROM test1.t1 INNER JOIN test2.t2 INNER JOIN test3.t3
+#Q> WHERE test1.t1.a=test2.t2.a AND test2.t2.a=test3.t3
+#010909 4:46:40 server id # end_log_pos # Table_map: `test1`.`t1` mapped to number #
+# at #
+#010909 4:46:40 server id # end_log_pos # Table_map: `test2`.`t2` mapped to number #
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # Delete_rows: table id #
+#010909 4:46:40 server id # end_log_pos # Delete_rows: table id # flags: STMT_END_F
+### DELETE FROM `test1`.`t1`
+### WHERE
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test1`.`t1`
+### WHERE
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test1`.`t1`
+### WHERE
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test2`.`t2`
+### WHERE
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test2`.`t2`
+### WHERE
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test2`.`t2`
+### WHERE
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+# Number of rows: 6
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-8
+/*!100001 SET @@session.gtid_seq_no=8*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # Annotate_rows:
+#Q> INSERT INTO test2.v2 VALUES (1), (2), (3)
+#010909 4:46:40 server id # end_log_pos # Table_map: `test2`.`t2` mapped to number #
+# at #
+#010909 4:46:40 server id # end_log_pos # Write_rows: table id # flags: STMT_END_F
+### INSERT INTO `test2`.`t2`
+### SET
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test2`.`t2`
+### SET
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test2`.`t2`
+### SET
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+# Number of rows: 3
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-9
+/*!100001 SET @@session.gtid_seq_no=9*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # Annotate_rows:
+#Q> DELETE xtest1.xt1, test2.t2
+#Q> FROM xtest1.xt1 INNER JOIN test2.t2 INNER JOIN test3.t3
+#Q> WHERE xtest1.xt1.a=test2.t2.a AND test2.t2.a=test3.t3
+#010909 4:46:40 server id # end_log_pos # Table_map: `test2`.`t2` mapped to number #
+# at #
+#010909 4:46:40 server id # end_log_pos # Delete_rows: table id # flags: STMT_END_F
+### DELETE FROM `test2`.`t2`
+### WHERE
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test2`.`t2`
+### WHERE
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test2`.`t2`
+### WHERE
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+# Number of rows: 3
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Rotate to master-bin.000002 pos: 4
+DELIMITER ;
+# End of log file
+ROLLBACK /* added by mysqlbinlog */;
+/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
+/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
+#
+#####################################################################################
+# mysqlbinlog --read-from-remote-server --database=test1
+# The following Annotate should appear in this output:
+# - DELETE test1.t1, test2.t2 FROM <...>
+#####################################################################################
+/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
+/*!40019 SET @@session.max_delayed_threads=0*/;
+/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
+DELIMITER /*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Start: binlog v 4, server v #.##.## created 010909 4:46:40 at startup
+ROLLBACK/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Ignorable
+# Ignorable event type 164 (Start_encryption)
+# at #
+#010909 4:46:40 server id # end_log_pos # Gtid list []
+# at #
+#010909 4:46:40 server id # end_log_pos # Binlog checkpoint master-bin.000001
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-1 ddl
+/*!100101 SET @@session.skip_parallel_replication=0*//*!*/;
+/*!100001 SET @@session.gtid_domain_id=0*//*!*/;
+/*!100001 SET @@session.server_id=1*//*!*/;
+/*!100001 SET @@session.gtid_seq_no=1*//*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+SET @@session.pseudo_thread_id=#/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1, @@session.check_constraint_checks=1, @@session.sql_if_exists=0, @@session.explicit_defaults_for_timestamp=1, @@session.system_versioning_insert_history=0/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=X,@@session.collation_connection=X,@@session.collation_server=X/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
+CREATE DATABASE test1
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-2 ddl
+/*!100001 SET @@session.gtid_seq_no=2*//*!*/;
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-3 ddl
+/*!100001 SET @@session.gtid_seq_no=3*//*!*/;
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-4
+/*!100001 SET @@session.gtid_seq_no=4*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # Annotate_rows:
+#Q> INSERT INTO test1.t1 VALUES (1), (2), (3)
+#010909 4:46:40 server id # end_log_pos # Table_map: `test1`.`t1` mapped to number #
+# at #
+#010909 4:46:40 server id # end_log_pos # Write_rows: table id # flags: STMT_END_F
+### INSERT INTO `test1`.`t1`
+### SET
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test1`.`t1`
+### SET
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test1`.`t1`
+### SET
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+# Number of rows: 3
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-5
+/*!100001 SET @@session.gtid_seq_no=5*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+# at #
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-6
+/*!100001 SET @@session.gtid_seq_no=6*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+# at #
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-7
+/*!100001 SET @@session.gtid_seq_no=7*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # Annotate_rows:
+#Q> DELETE test1.t1, test2.t2
+#Q> FROM test1.t1 INNER JOIN test2.t2 INNER JOIN test3.t3
+#Q> WHERE test1.t1.a=test2.t2.a AND test2.t2.a=test3.t3
+#010909 4:46:40 server id # end_log_pos # Table_map: `test1`.`t1` mapped to number #
+# at #
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # Delete_rows: table id #
+### DELETE FROM `test1`.`t1`
+### WHERE
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test1`.`t1`
+### WHERE
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test1`.`t1`
+### WHERE
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-8
+/*!100001 SET @@session.gtid_seq_no=8*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+# at #
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-9
+/*!100001 SET @@session.gtid_seq_no=9*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+# at #
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Rotate to master-bin.000002 pos: 4
+DELIMITER ;
+# End of log file
+ROLLBACK /* added by mysqlbinlog */;
+/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
+/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
+#
+#####################################################################################
+# mysqlbinlog --read-from-remote-server --skip-annotate-row-events
+# No Annotates should appear in this output
+#####################################################################################
+/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
+/*!40019 SET @@session.max_delayed_threads=0*/;
+/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
+DELIMITER /*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Start: binlog v 4, server v #.##.## created 010909 4:46:40 at startup
+ROLLBACK/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Ignorable
+# Ignorable event type 164 (Start_encryption)
+# at #
+#010909 4:46:40 server id # end_log_pos # Gtid list []
+# at #
+#010909 4:46:40 server id # end_log_pos # Binlog checkpoint master-bin.000001
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-1 ddl
+/*!100101 SET @@session.skip_parallel_replication=0*//*!*/;
+/*!100001 SET @@session.gtid_domain_id=0*//*!*/;
+/*!100001 SET @@session.server_id=1*//*!*/;
+/*!100001 SET @@session.gtid_seq_no=1*//*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+SET @@session.pseudo_thread_id=#/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1, @@session.check_constraint_checks=1, @@session.sql_if_exists=0, @@session.explicit_defaults_for_timestamp=1, @@session.system_versioning_insert_history=0/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=X,@@session.collation_connection=X,@@session.collation_server=X/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
+CREATE DATABASE test1
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-2 ddl
+/*!100001 SET @@session.gtid_seq_no=2*//*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+CREATE DATABASE test2
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-3 ddl
+/*!100001 SET @@session.gtid_seq_no=3*//*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+CREATE DATABASE test3
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-4
+/*!100001 SET @@session.gtid_seq_no=4*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Table_map: `test1`.`t1` mapped to number #
+# at #
+#010909 4:46:40 server id # end_log_pos # Write_rows: table id # flags: STMT_END_F
+### INSERT INTO `test1`.`t1`
+### SET
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test1`.`t1`
+### SET
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test1`.`t1`
+### SET
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+# Number of rows: 3
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-5
+/*!100001 SET @@session.gtid_seq_no=5*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Table_map: `test2`.`t2` mapped to number #
+# at #
+#010909 4:46:40 server id # end_log_pos # Write_rows: table id # flags: STMT_END_F
+### INSERT INTO `test2`.`t2`
+### SET
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test2`.`t2`
+### SET
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test2`.`t2`
+### SET
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+# Number of rows: 3
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-6
+/*!100001 SET @@session.gtid_seq_no=6*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Table_map: `test3`.`t3` mapped to number #
+# at #
+#010909 4:46:40 server id # end_log_pos # Write_rows: table id # flags: STMT_END_F
+### INSERT INTO `test3`.`t3`
+### SET
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test3`.`t3`
+### SET
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test3`.`t3`
+### SET
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+# Number of rows: 3
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-7
+/*!100001 SET @@session.gtid_seq_no=7*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Table_map: `test1`.`t1` mapped to number #
+# at #
+#010909 4:46:40 server id # end_log_pos # Table_map: `test2`.`t2` mapped to number #
+# at #
+# at #
+#010909 4:46:40 server id # end_log_pos # Delete_rows: table id #
+#010909 4:46:40 server id # end_log_pos # Delete_rows: table id # flags: STMT_END_F
+### DELETE FROM `test1`.`t1`
+### WHERE
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test1`.`t1`
+### WHERE
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test1`.`t1`
+### WHERE
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test2`.`t2`
+### WHERE
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test2`.`t2`
+### WHERE
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test2`.`t2`
+### WHERE
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+# Number of rows: 6
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-8
+/*!100001 SET @@session.gtid_seq_no=8*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Table_map: `test2`.`t2` mapped to number #
+# at #
+#010909 4:46:40 server id # end_log_pos # Write_rows: table id # flags: STMT_END_F
+### INSERT INTO `test2`.`t2`
+### SET
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test2`.`t2`
+### SET
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### INSERT INTO `test2`.`t2`
+### SET
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+# Number of rows: 3
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # GTID 0-1-9
+/*!100001 SET @@session.gtid_seq_no=9*//*!*/;
+START TRANSACTION
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Table_map: `test2`.`t2` mapped to number #
+# at #
+#010909 4:46:40 server id # end_log_pos # Delete_rows: table id # flags: STMT_END_F
+### DELETE FROM `test2`.`t2`
+### WHERE
+### @1=3 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test2`.`t2`
+### WHERE
+### @1=2 /* INT meta=0 nullable=1 is_null=0 */
+### DELETE FROM `test2`.`t2`
+### WHERE
+### @1=1 /* INT meta=0 nullable=1 is_null=0 */
+# Number of rows: 3
+# at #
+#010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 xid=<xid>
+SET TIMESTAMP=1000000000/*!*/;
+COMMIT
+/*!*/;
+# at #
+#010909 4:46:40 server id # end_log_pos # Rotate to master-bin.000002 pos: 4
+DELIMITER ;
+# End of log file
+ROLLBACK /* added by mysqlbinlog */;
+/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
+/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
+set global binlog_checksum=@old_binlog_checksum;
+DROP DATABASE test1;
+DROP DATABASE test2;
+DROP DATABASE test3;
+DROP DATABASE xtest1;
+DROP DATABASE xtest2;
diff --git a/mysql-test/suite/binlog_encryption/binlog_row_annotate.test b/mysql-test/suite/binlog_encryption/binlog_row_annotate.test
new file mode 100644
index 00000000..b5c3bb2e
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_row_annotate.test
@@ -0,0 +1,2 @@
+--let $use_remote_mysqlbinlog= 1
+--source suite/binlog/include/binlog_row_annotate.inc
diff --git a/mysql-test/suite/binlog_encryption/binlog_write_error.result b/mysql-test/suite/binlog_encryption/binlog_write_error.result
new file mode 100644
index 00000000..46a23371
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_write_error.result
@@ -0,0 +1,113 @@
+call mtr.add_suppression("Write to binary log failed: Error writing file*");
+#
+# Test injecting binlog write error when executing queries
+#
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+CREATE TABLE t1 (a INT);
+CREATE TABLE t1 (a INT);
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+INSERT INTO t1 VALUES (1),(2),(3);
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+INSERT INTO t1 VALUES (4),(5),(6);
+INSERT INTO t1 VALUES (4),(5),(6);
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+UPDATE t1 set a=a+1;
+UPDATE t1 set a=a+1;
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+DELETE FROM t1;
+DELETE FROM t1;
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+CREATE TRIGGER tr1 AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t1 VALUES (new.a + 100);
+CREATE TRIGGER tr1 AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t1 VALUES (new.a + 100);
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+DROP TRIGGER tr1;
+DROP TRIGGER tr1;
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+ALTER TABLE t1 ADD (b INT);
+ALTER TABLE t1 ADD (b INT);
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+CREATE VIEW v1 AS SELECT a FROM t1;
+CREATE VIEW v1 AS SELECT a FROM t1;
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+DROP VIEW v1;
+DROP VIEW v1;
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+CREATE PROCEDURE p1(OUT rows_cnt INT) SELECT count(*) INTO rows_cnt FROM t1;
+CREATE PROCEDURE p1(OUT rows_cnt INT) SELECT count(*) INTO rows_cnt FROM t1;
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+DROP PROCEDURE p1;
+DROP PROCEDURE p1;
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+DROP TABLE t1;
+DROP TABLE t1;
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+CREATE FUNCTION f1() RETURNS INT return 1;
+CREATE FUNCTION f1() RETURNS INT return 1;
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+DROP FUNCTION f1;
+DROP FUNCTION f1;
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+CREATE USER user1;
+CREATE USER user1;
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM user1;
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM user1;
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+SET PASSWORD FOR user1=PASSWORD('foobar');
+SET PASSWORD FOR user1=PASSWORD('foobar');
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug='d,injecting_fault_writing';
+DROP USER user1;
+DROP USER user1;
+ERROR HY000: Error writing file 'master-bin' ((errno: #)
+set @@global.debug_dbug = @saved_dbug;
diff --git a/mysql-test/suite/binlog_encryption/binlog_write_error.test b/mysql-test/suite/binlog_encryption/binlog_write_error.test
new file mode 100644
index 00000000..8add24da
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_write_error.test
@@ -0,0 +1 @@
+--source suite/binlog/t/binlog_write_error.test
diff --git a/mysql-test/suite/binlog_encryption/binlog_xa_recover.result b/mysql-test/suite/binlog_encryption/binlog_xa_recover.result
new file mode 100644
index 00000000..3e4ed42c
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_xa_recover.result
@@ -0,0 +1,229 @@
+SET GLOBAL max_binlog_size= 4096;
+SET GLOBAL innodb_flush_log_at_trx_commit= 1;
+RESET MASTER;
+CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb;
+INSERT INTO t1 VALUES (100, REPEAT("x", 4100));
+INSERT INTO t1 VALUES (101, REPEAT("x", 4100));
+INSERT INTO t1 VALUES (102, REPEAT("x", 4100));
+connect con1,localhost,root,,;
+SET DEBUG_SYNC= "ha_commit_trans_before_log_and_order SIGNAL con1_wait WAIT_FOR con1_cont";
+SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con1_ready WAIT_FOR _ever";
+INSERT INTO t1 VALUES (1, REPEAT("x", 4100));
+connection default;
+SET DEBUG_SYNC= "now WAIT_FOR con1_wait";
+connect con2,localhost,root,,;
+SET DEBUG_SYNC= "ha_commit_trans_before_log_and_order SIGNAL con2_wait WAIT_FOR con2_cont";
+SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con2_ready WAIT_FOR _ever";
+INSERT INTO t1 VALUES (2, NULL);
+connection default;
+SET DEBUG_SYNC= "now WAIT_FOR con2_wait";
+connect con3,localhost,root,,;
+SET DEBUG_SYNC= "ha_commit_trans_before_log_and_order SIGNAL con3_wait WAIT_FOR con3_cont";
+SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con3_ready WAIT_FOR _ever";
+INSERT INTO t1 VALUES (3, REPEAT("x", 4100));
+connection default;
+SET DEBUG_SYNC= "now WAIT_FOR con3_wait";
+connect con4,localhost,root,,;
+SET DEBUG_SYNC= "ha_commit_trans_before_log_and_order SIGNAL con4_wait WAIT_FOR con4_cont";
+SET SESSION debug_dbug="+d,crash_commit_after_log";
+INSERT INTO t1 VALUES (4, NULL);
+connection default;
+SET DEBUG_SYNC= "now WAIT_FOR con4_wait";
+SET DEBUG_SYNC= "now SIGNAL con1_cont";
+SET DEBUG_SYNC= "now WAIT_FOR con1_ready";
+SET DEBUG_SYNC= "now SIGNAL con2_cont";
+SET DEBUG_SYNC= "now WAIT_FOR con2_ready";
+SET DEBUG_SYNC= "now SIGNAL con3_cont";
+SET DEBUG_SYNC= "now WAIT_FOR con3_ready";
+show binary logs;
+Log_name File_size
+master-bin.000001 #
+master-bin.000002 #
+master-bin.000003 #
+master-bin.000004 #
+master-bin.000005 #
+master-bin.000006 #
+include/show_binlog_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000003 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
+master-bin.000003 # Start_encryption # #
+master-bin.000003 # Gtid_list # # [#-#-#]
+master-bin.000003 # Binlog_checkpoint # # master-bin.000002
+master-bin.000003 # Binlog_checkpoint # # master-bin.000003
+master-bin.000003 # Gtid # # BEGIN GTID #-#-#
+master-bin.000003 # Annotate_rows # # INSERT INTO t1 VALUES (102, REPEAT("x", 4100))
+master-bin.000003 # Table_map # # table_id: # (test.t1)
+master-bin.000003 # Write_rows_v1 # # table_id: # flags: STMT_END_F
+master-bin.000003 # Xid # # COMMIT /* XID */
+master-bin.000003 # Rotate # # master-bin.000004;pos=POS
+include/show_binlog_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000004 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
+master-bin.000004 # Start_encryption # #
+master-bin.000004 # Gtid_list # # [#-#-#]
+master-bin.000004 # Binlog_checkpoint # # master-bin.000003
+master-bin.000004 # Binlog_checkpoint # # master-bin.000004
+master-bin.000004 # Gtid # # BEGIN GTID #-#-#
+master-bin.000004 # Annotate_rows # # INSERT INTO t1 VALUES (1, REPEAT("x", 4100))
+master-bin.000004 # Table_map # # table_id: # (test.t1)
+master-bin.000004 # Write_rows_v1 # # table_id: # flags: STMT_END_F
+master-bin.000004 # Xid # # COMMIT /* XID */
+master-bin.000004 # Rotate # # master-bin.000005;pos=POS
+include/show_binlog_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000005 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
+master-bin.000005 # Start_encryption # #
+master-bin.000005 # Gtid_list # # [#-#-#]
+master-bin.000005 # Binlog_checkpoint # # master-bin.000004
+master-bin.000005 # Gtid # # BEGIN GTID #-#-#
+master-bin.000005 # Annotate_rows # # INSERT INTO t1 VALUES (2, NULL)
+master-bin.000005 # Table_map # # table_id: # (test.t1)
+master-bin.000005 # Write_rows_v1 # # table_id: # flags: STMT_END_F
+master-bin.000005 # Xid # # COMMIT /* XID */
+master-bin.000005 # Gtid # # BEGIN GTID #-#-#
+master-bin.000005 # Annotate_rows # # INSERT INTO t1 VALUES (3, REPEAT("x", 4100))
+master-bin.000005 # Table_map # # table_id: # (test.t1)
+master-bin.000005 # Write_rows_v1 # # table_id: # flags: STMT_END_F
+master-bin.000005 # Xid # # COMMIT /* XID */
+master-bin.000005 # Rotate # # master-bin.000006;pos=POS
+include/show_binlog_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000006 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
+master-bin.000006 # Start_encryption # #
+master-bin.000006 # Gtid_list # # [#-#-#]
+master-bin.000006 # Binlog_checkpoint # # master-bin.000004
+PURGE BINARY LOGS TO "master-bin.000006";
+show binary logs;
+Log_name File_size
+master-bin.000004 #
+master-bin.000005 #
+master-bin.000006 #
+SET DEBUG_SYNC= "now SIGNAL con4_cont";
+connection con4;
+Got one of the listed errors
+connection default;
+SELECT a FROM t1 ORDER BY a;
+a
+1
+2
+3
+4
+100
+101
+102
+Test that with multiple binlog checkpoints, recovery starts from the last one.
+SET GLOBAL max_binlog_size= 4096;
+SET GLOBAL innodb_flush_log_at_trx_commit= 1;
+RESET MASTER;
+connect con10,localhost,root,,;
+SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con10_ready WAIT_FOR con10_cont";
+INSERT INTO t1 VALUES (10, REPEAT("x", 4100));
+connection default;
+SET DEBUG_SYNC= "now WAIT_FOR con10_ready";
+connect con11,localhost,root,,;
+SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con11_ready WAIT_FOR con11_cont";
+INSERT INTO t1 VALUES (11, REPEAT("x", 4100));
+connection default;
+SET DEBUG_SYNC= "now WAIT_FOR con11_ready";
+connect con12,localhost,root,,;
+SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con12_ready WAIT_FOR con12_cont";
+INSERT INTO t1 VALUES (12, REPEAT("x", 4100));
+connection default;
+SET DEBUG_SYNC= "now WAIT_FOR con12_ready";
+INSERT INTO t1 VALUES (13, NULL);
+show binary logs;
+Log_name File_size
+master-bin.000001 #
+master-bin.000002 #
+master-bin.000003 #
+master-bin.000004 #
+include/show_binlog_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000004 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
+master-bin.000004 # Start_encryption # #
+master-bin.000004 # Gtid_list # # [#-#-#]
+master-bin.000004 # Binlog_checkpoint # # master-bin.000001
+master-bin.000004 # Gtid # # BEGIN GTID #-#-#
+master-bin.000004 # Annotate_rows # # INSERT INTO t1 VALUES (13, NULL)
+master-bin.000004 # Table_map # # table_id: # (test.t1)
+master-bin.000004 # Write_rows_v1 # # table_id: # flags: STMT_END_F
+master-bin.000004 # Xid # # COMMIT /* XID */
+SET DEBUG_SYNC= "now SIGNAL con10_cont";
+connection con10;
+connection default;
+SET DEBUG_SYNC= "now SIGNAL con12_cont";
+connection con12;
+connection default;
+SET DEBUG_SYNC= "now SIGNAL con11_cont";
+connection con11;
+connection default;
+Now crash the server
+SET SESSION debug_dbug="+d,crash_commit_after_log";
+INSERT INTO t1 VALUES (14, NULL);
+Got one of the listed errors
+connection default;
+SELECT a FROM t1 ORDER BY a;
+a
+1
+2
+3
+4
+10
+11
+12
+13
+14
+100
+101
+102
+*** Check that recovery works if we crashed early during rotate, before
+*** binlog checkpoint event could be written.
+SET GLOBAL max_binlog_size= 4096;
+SET GLOBAL innodb_flush_log_at_trx_commit= 1;
+RESET MASTER;
+INSERT INTO t1 VALUES (21, REPEAT("x", 4100));
+INSERT INTO t1 VALUES (22, REPEAT("x", 4100));
+INSERT INTO t1 VALUES (23, REPEAT("x", 4100));
+SET SESSION debug_dbug="+d,crash_before_write_checkpoint_event";
+INSERT INTO t1 VALUES (24, REPEAT("x", 4100));
+Got one of the listed errors
+SELECT a FROM t1 ORDER BY a;
+a
+1
+2
+3
+4
+10
+11
+12
+13
+14
+21
+22
+23
+24
+100
+101
+102
+show binary logs;
+Log_name File_size
+master-bin.000001 #
+master-bin.000002 #
+master-bin.000003 #
+master-bin.000004 #
+master-bin.000005 #
+include/show_binlog_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000004 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
+master-bin.000004 # Start_encryption # #
+master-bin.000004 # Gtid_list # # [#-#-#]
+master-bin.000004 # Binlog_checkpoint # # master-bin.000003
+master-bin.000004 # Binlog_checkpoint # # master-bin.000004
+master-bin.000004 # Gtid # # BEGIN GTID #-#-#
+master-bin.000004 # Annotate_rows # # INSERT INTO t1 VALUES (24, REPEAT("x", 4100))
+master-bin.000004 # Table_map # # table_id: # (test.t1)
+master-bin.000004 # Write_rows_v1 # # table_id: # flags: STMT_END_F
+master-bin.000004 # Xid # # COMMIT /* XID */
+master-bin.000004 # Rotate # # master-bin.000005;pos=POS
+connection default;
+DROP TABLE t1;
diff --git a/mysql-test/suite/binlog_encryption/binlog_xa_recover.test b/mysql-test/suite/binlog_encryption/binlog_xa_recover.test
new file mode 100644
index 00000000..c03adb6a
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/binlog_xa_recover.test
@@ -0,0 +1 @@
+--source suite/binlog/t/binlog_xa_recover.test
diff --git a/mysql-test/suite/binlog_encryption/disabled.def b/mysql-test/suite/binlog_encryption/disabled.def
new file mode 100644
index 00000000..b7a26a83
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/disabled.def
@@ -0,0 +1,2 @@
+encrypted_master_lost_key : MDEV-11323 - unspecified behavior for IO thread
+rpl_checksum_cache : MDEV-11486 - sporadic failure in IO thread
diff --git a/mysql-test/suite/binlog_encryption/encrypted_master.result b/mysql-test/suite/binlog_encryption/encrypted_master.result
new file mode 100644
index 00000000..8a379873
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encrypted_master.result
@@ -0,0 +1,626 @@
+#################
+# Initialization
+#################
+include/rpl_init.inc [topology=1->2]
+connection server_2;
+include/stop_slave_sql.inc
+connection server_1;
+SET @binlog_annotate_row_events.save= @@global.binlog_annotate_row_events;
+SET @binlog_checksum.save= @@global.binlog_checksum;
+SET @master_verify_checksum.save= @@global.master_verify_checksum;
+SET @binlog_row_image.save= @@global.binlog_row_image;
+####################################################
+# Test 1: simple binlog, no checksum, no annotation
+####################################################
+connection server_1;
+SET binlog_annotate_row_events= 0;
+SET GLOBAL binlog_annotate_row_events= 0;
+SET GLOBAL binlog_checksum= NONE;
+SET GLOBAL master_verify_checksum= 0;
+call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
+CREATE DATABASE database_name_to_encrypt;
+USE database_name_to_encrypt;
+CREATE USER user_name_to_encrypt;
+GRANT ALL ON database_name_to_encrypt.* TO user_name_to_encrypt;
+SET PASSWORD FOR user_name_to_encrypt = PASSWORD('password_to_encrypt');
+CREATE TABLE innodb_table_name_to_encrypt (
+int_column_name_to_encrypt INT PRIMARY KEY,
+timestamp_column_name_to_encrypt TIMESTAMP(6) NULL,
+blob_column_name_to_encrypt BLOB,
+virt_column_name_to_encrypt INT AS (int_column_name_to_encrypt % 10) VIRTUAL,
+pers_column_name_to_encrypt INT AS (int_column_name_to_encrypt) PERSISTENT,
+INDEX `index_name_to_encrypt`(`timestamp_column_name_to_encrypt`)
+) ENGINE=InnoDB
+PARTITION BY RANGE (int_column_name_to_encrypt)
+SUBPARTITION BY KEY (int_column_name_to_encrypt)
+SUBPARTITIONS 2 (
+PARTITION partition0_name_to_encrypt VALUES LESS THAN (100),
+PARTITION partition1_name_to_encrypt VALUES LESS THAN (MAXVALUE)
+)
+;
+CREATE TABLE myisam_table_name_to_encrypt (
+int_column_name_to_encrypt INT AUTO_INCREMENT PRIMARY KEY,
+char_column_name_to_encrypt VARCHAR(255),
+datetime_column_name_to_encrypt DATETIME,
+text_column_name_to_encrypt TEXT
+) ENGINE=MyISAM;
+CREATE TABLE aria_table_name_to_encrypt (
+int_column_name_to_encrypt INT AUTO_INCREMENT PRIMARY KEY,
+varchar_column_name_to_encrypt VARCHAR(1024),
+enum_column_name_to_encrypt ENUM(
+'enum_value1_to_encrypt',
+'enum_value2_to_encrypt'
+ ),
+timestamp_column_name_to_encrypt TIMESTAMP(6) NULL,
+blob_column_name_to_encrypt BLOB
+) ENGINE=Aria;
+CREATE TRIGGER trigger_name_to_encrypt
+AFTER INSERT ON myisam_table_name_to_encrypt FOR EACH ROW
+INSERT INTO aria_table_name_to_encrypt (varchar_column_name_to_encrypt)
+VALUES (NEW.char_column_name_to_encrypt);
+CREATE DEFINER=user_name_to_encrypt VIEW view_name_to_encrypt
+AS SELECT * FROM innodb_table_name_to_encrypt;
+CREATE FUNCTION func_name_to_encrypt (func_parameter_to_encrypt INT)
+RETURNS VARCHAR(64)
+RETURN 'func_result_to_encrypt';
+CREATE PROCEDURE proc_name_to_encrypt (
+IN proc_in_parameter_to_encrypt CHAR(32),
+OUT proc_out_parameter_to_encrypt INT
+)
+BEGIN
+DECLARE procvar_name_to_encrypt CHAR(64) DEFAULT 'procvar_val_to_encrypt';
+DECLARE cursor_name_to_encrypt CURSOR FOR
+SELECT virt_column_name_to_encrypt FROM innodb_table_name_to_encrypt;
+DECLARE EXIT HANDLER FOR NOT FOUND
+BEGIN
+SET @stmt_var_to_encrypt = CONCAT(
+"SELECT
+ IF (RAND()>0.5,'enum_value2_to_encrypt','enum_value1_to_encrypt')
+ FROM innodb_table_name_to_encrypt
+ INTO OUTFILE '", proc_in_parameter_to_encrypt, "'");
+PREPARE stmt_to_encrypt FROM @stmt_var_to_encrypt;
+EXECUTE stmt_to_encrypt;
+DEALLOCATE PREPARE stmt_to_encrypt;
+END;
+OPEN cursor_name_to_encrypt;
+proc_label_to_encrypt: LOOP
+FETCH cursor_name_to_encrypt INTO procvar_name_to_encrypt;
+END LOOP;
+CLOSE cursor_name_to_encrypt;
+END $$
+CREATE SERVER server_name_to_encrypt
+FOREIGN DATA WRAPPER mysql
+OPTIONS (HOST 'host_name_to_encrypt');
+connect con1,localhost,user_name_to_encrypt,password_to_encrypt,database_name_to_encrypt;
+CREATE TEMPORARY TABLE tmp_table_name_to_encrypt (
+float_column_name_to_encrypt FLOAT,
+binary_column_name_to_encrypt BINARY(64)
+);
+disconnect con1;
+connection server_1;
+CREATE INDEX index_name_to_encrypt
+ON myisam_table_name_to_encrypt (datetime_column_name_to_encrypt);
+ALTER DATABASE database_name_to_encrypt CHARACTER SET utf8;
+ALTER TABLE innodb_table_name_to_encrypt
+MODIFY timestamp_column_name_to_encrypt TIMESTAMP NOT NULL
+DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
+;
+ALTER ALGORITHM=MERGE VIEW view_name_to_encrypt
+AS SELECT * FROM innodb_table_name_to_encrypt;
+RENAME TABLE innodb_table_name_to_encrypt TO new_table_name_to_encrypt;
+ALTER TABLE new_table_name_to_encrypt RENAME TO innodb_table_name_to_encrypt;
+set @user_var1_to_encrypt= 'dyncol1_val_to_encrypt';
+set @user_var2_to_encrypt= 'dyncol2_name_to_encrypt';
+INSERT INTO view_name_to_encrypt VALUES
+(1, NOW(6), COLUMN_CREATE('dyncol1_name_to_encrypt',@user_var1_to_encrypt), NULL, NULL),
+(2, NOW(6), COLUMN_CREATE(@user_var2_to_encrypt,'dyncol2_val_to_encrypt'), NULL, NULL)
+;
+BEGIN NOT ATOMIC
+DECLARE counter_name_to_encrypt INT DEFAULT 0;
+START TRANSACTION;
+WHILE counter_name_to_encrypt<12 DO
+SELECT COUNT(*) INTO @cnt FROM innodb_table_name_to_encrypt;
+INSERT INTO innodb_table_name_to_encrypt
+SELECT int_column_name_to_encrypt+@cnt, NOW(6), blob_column_name_to_encrypt, NULL, NULL
+FROM innodb_table_name_to_encrypt
+ORDER BY int_column_name_to_encrypt;
+SET counter_name_to_encrypt = counter_name_to_encrypt+1;
+END WHILE;
+COMMIT;
+END
+$$
+INSERT INTO myisam_table_name_to_encrypt
+SELECT NULL, 'char_literal_to_encrypt', NULL, 'text_to_encrypt';
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+CALL proc_name_to_encrypt('file_name_to_encrypt',@useless_var_to_encrypt);
+TRUNCATE TABLE aria_table_name_to_encrypt;
+LOAD DATA INFILE 'file_name_to_encrypt' INTO TABLE aria_table_name_to_encrypt
+(enum_column_name_to_encrypt);
+LOAD DATA LOCAL INFILE '<DATADIR>/database_name_to_encrypt/file_name_to_encrypt'
+INTO TABLE aria_table_name_to_encrypt (enum_column_name_to_encrypt);
+UPDATE view_name_to_encrypt SET blob_column_name_to_encrypt =
+COLUMN_CREATE('dyncol1_name_to_encrypt',func_name_to_encrypt(0))
+;
+DELETE FROM aria_table_name_to_encrypt ORDER BY int_column_name_to_encrypt LIMIT 10;
+ANALYZE TABLE myisam_table_name_to_encrypt;
+CHECK TABLE aria_table_name_to_encrypt;
+CHECKSUM TABLE innodb_table_name_to_encrypt, myisam_table_name_to_encrypt;
+RENAME USER user_name_to_encrypt to new_user_name_to_encrypt;
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM new_user_name_to_encrypt;
+DROP DATABASE database_name_to_encrypt;
+DROP USER new_user_name_to_encrypt;
+DROP SERVER server_name_to_encrypt;
+####################################################
+# Test 2: binlog with checksum, no annotated events
+####################################################
+connection server_1;
+SET binlog_annotate_row_events= 0;
+SET GLOBAL binlog_annotate_row_events= 0;
+SET GLOBAL binlog_checksum= CRC32;
+SET GLOBAL master_verify_checksum= 1;
+call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
+CREATE DATABASE database_name_to_encrypt;
+USE database_name_to_encrypt;
+CREATE USER user_name_to_encrypt;
+GRANT ALL ON database_name_to_encrypt.* TO user_name_to_encrypt;
+SET PASSWORD FOR user_name_to_encrypt = PASSWORD('password_to_encrypt');
+CREATE TABLE innodb_table_name_to_encrypt (
+int_column_name_to_encrypt INT PRIMARY KEY,
+timestamp_column_name_to_encrypt TIMESTAMP(6) NULL,
+blob_column_name_to_encrypt BLOB,
+virt_column_name_to_encrypt INT AS (int_column_name_to_encrypt % 10) VIRTUAL,
+pers_column_name_to_encrypt INT AS (int_column_name_to_encrypt) PERSISTENT,
+INDEX `index_name_to_encrypt`(`timestamp_column_name_to_encrypt`)
+) ENGINE=InnoDB
+PARTITION BY RANGE (int_column_name_to_encrypt)
+SUBPARTITION BY KEY (int_column_name_to_encrypt)
+SUBPARTITIONS 2 (
+PARTITION partition0_name_to_encrypt VALUES LESS THAN (100),
+PARTITION partition1_name_to_encrypt VALUES LESS THAN (MAXVALUE)
+)
+;
+CREATE TABLE myisam_table_name_to_encrypt (
+int_column_name_to_encrypt INT AUTO_INCREMENT PRIMARY KEY,
+char_column_name_to_encrypt VARCHAR(255),
+datetime_column_name_to_encrypt DATETIME,
+text_column_name_to_encrypt TEXT
+) ENGINE=MyISAM;
+CREATE TABLE aria_table_name_to_encrypt (
+int_column_name_to_encrypt INT AUTO_INCREMENT PRIMARY KEY,
+varchar_column_name_to_encrypt VARCHAR(1024),
+enum_column_name_to_encrypt ENUM(
+'enum_value1_to_encrypt',
+'enum_value2_to_encrypt'
+ ),
+timestamp_column_name_to_encrypt TIMESTAMP(6) NULL,
+blob_column_name_to_encrypt BLOB
+) ENGINE=Aria;
+CREATE TRIGGER trigger_name_to_encrypt
+AFTER INSERT ON myisam_table_name_to_encrypt FOR EACH ROW
+INSERT INTO aria_table_name_to_encrypt (varchar_column_name_to_encrypt)
+VALUES (NEW.char_column_name_to_encrypt);
+CREATE DEFINER=user_name_to_encrypt VIEW view_name_to_encrypt
+AS SELECT * FROM innodb_table_name_to_encrypt;
+CREATE FUNCTION func_name_to_encrypt (func_parameter_to_encrypt INT)
+RETURNS VARCHAR(64)
+RETURN 'func_result_to_encrypt';
+CREATE PROCEDURE proc_name_to_encrypt (
+IN proc_in_parameter_to_encrypt CHAR(32),
+OUT proc_out_parameter_to_encrypt INT
+)
+BEGIN
+DECLARE procvar_name_to_encrypt CHAR(64) DEFAULT 'procvar_val_to_encrypt';
+DECLARE cursor_name_to_encrypt CURSOR FOR
+SELECT virt_column_name_to_encrypt FROM innodb_table_name_to_encrypt;
+DECLARE EXIT HANDLER FOR NOT FOUND
+BEGIN
+SET @stmt_var_to_encrypt = CONCAT(
+"SELECT
+ IF (RAND()>0.5,'enum_value2_to_encrypt','enum_value1_to_encrypt')
+ FROM innodb_table_name_to_encrypt
+ INTO OUTFILE '", proc_in_parameter_to_encrypt, "'");
+PREPARE stmt_to_encrypt FROM @stmt_var_to_encrypt;
+EXECUTE stmt_to_encrypt;
+DEALLOCATE PREPARE stmt_to_encrypt;
+END;
+OPEN cursor_name_to_encrypt;
+proc_label_to_encrypt: LOOP
+FETCH cursor_name_to_encrypt INTO procvar_name_to_encrypt;
+END LOOP;
+CLOSE cursor_name_to_encrypt;
+END $$
+CREATE SERVER server_name_to_encrypt
+FOREIGN DATA WRAPPER mysql
+OPTIONS (HOST 'host_name_to_encrypt');
+connect con1,localhost,user_name_to_encrypt,password_to_encrypt,database_name_to_encrypt;
+CREATE TEMPORARY TABLE tmp_table_name_to_encrypt (
+float_column_name_to_encrypt FLOAT,
+binary_column_name_to_encrypt BINARY(64)
+);
+disconnect con1;
+connection server_1;
+CREATE INDEX index_name_to_encrypt
+ON myisam_table_name_to_encrypt (datetime_column_name_to_encrypt);
+ALTER DATABASE database_name_to_encrypt CHARACTER SET utf8;
+ALTER TABLE innodb_table_name_to_encrypt
+MODIFY timestamp_column_name_to_encrypt TIMESTAMP NOT NULL
+DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
+;
+ALTER ALGORITHM=MERGE VIEW view_name_to_encrypt
+AS SELECT * FROM innodb_table_name_to_encrypt;
+RENAME TABLE innodb_table_name_to_encrypt TO new_table_name_to_encrypt;
+ALTER TABLE new_table_name_to_encrypt RENAME TO innodb_table_name_to_encrypt;
+set @user_var1_to_encrypt= 'dyncol1_val_to_encrypt';
+set @user_var2_to_encrypt= 'dyncol2_name_to_encrypt';
+INSERT INTO view_name_to_encrypt VALUES
+(1, NOW(6), COLUMN_CREATE('dyncol1_name_to_encrypt',@user_var1_to_encrypt), NULL, NULL),
+(2, NOW(6), COLUMN_CREATE(@user_var2_to_encrypt,'dyncol2_val_to_encrypt'), NULL, NULL)
+;
+BEGIN NOT ATOMIC
+DECLARE counter_name_to_encrypt INT DEFAULT 0;
+START TRANSACTION;
+WHILE counter_name_to_encrypt<12 DO
+SELECT COUNT(*) INTO @cnt FROM innodb_table_name_to_encrypt;
+INSERT INTO innodb_table_name_to_encrypt
+SELECT int_column_name_to_encrypt+@cnt, NOW(6), blob_column_name_to_encrypt, NULL, NULL
+FROM innodb_table_name_to_encrypt
+ORDER BY int_column_name_to_encrypt;
+SET counter_name_to_encrypt = counter_name_to_encrypt+1;
+END WHILE;
+COMMIT;
+END
+$$
+INSERT INTO myisam_table_name_to_encrypt
+SELECT NULL, 'char_literal_to_encrypt', NULL, 'text_to_encrypt';
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+CALL proc_name_to_encrypt('file_name_to_encrypt',@useless_var_to_encrypt);
+TRUNCATE TABLE aria_table_name_to_encrypt;
+LOAD DATA INFILE 'file_name_to_encrypt' INTO TABLE aria_table_name_to_encrypt
+(enum_column_name_to_encrypt);
+LOAD DATA LOCAL INFILE '<DATADIR>/database_name_to_encrypt/file_name_to_encrypt'
+INTO TABLE aria_table_name_to_encrypt (enum_column_name_to_encrypt);
+UPDATE view_name_to_encrypt SET blob_column_name_to_encrypt =
+COLUMN_CREATE('dyncol1_name_to_encrypt',func_name_to_encrypt(0))
+;
+DELETE FROM aria_table_name_to_encrypt ORDER BY int_column_name_to_encrypt LIMIT 10;
+ANALYZE TABLE myisam_table_name_to_encrypt;
+CHECK TABLE aria_table_name_to_encrypt;
+CHECKSUM TABLE innodb_table_name_to_encrypt, myisam_table_name_to_encrypt;
+RENAME USER user_name_to_encrypt to new_user_name_to_encrypt;
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM new_user_name_to_encrypt;
+DROP DATABASE database_name_to_encrypt;
+DROP USER new_user_name_to_encrypt;
+DROP SERVER server_name_to_encrypt;
+####################################################
+# Test 3: binlog with checksum and annotated events
+####################################################
+connection server_1;
+SET binlog_annotate_row_events= 1;
+SET GLOBAL binlog_annotate_row_events= 1;
+SET GLOBAL binlog_checksum= CRC32;
+SET GLOBAL master_verify_checksum= 1;
+call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
+CREATE DATABASE database_name_to_encrypt;
+USE database_name_to_encrypt;
+CREATE USER user_name_to_encrypt;
+GRANT ALL ON database_name_to_encrypt.* TO user_name_to_encrypt;
+SET PASSWORD FOR user_name_to_encrypt = PASSWORD('password_to_encrypt');
+CREATE TABLE innodb_table_name_to_encrypt (
+int_column_name_to_encrypt INT PRIMARY KEY,
+timestamp_column_name_to_encrypt TIMESTAMP(6) NULL,
+blob_column_name_to_encrypt BLOB,
+virt_column_name_to_encrypt INT AS (int_column_name_to_encrypt % 10) VIRTUAL,
+pers_column_name_to_encrypt INT AS (int_column_name_to_encrypt) PERSISTENT,
+INDEX `index_name_to_encrypt`(`timestamp_column_name_to_encrypt`)
+) ENGINE=InnoDB
+PARTITION BY RANGE (int_column_name_to_encrypt)
+SUBPARTITION BY KEY (int_column_name_to_encrypt)
+SUBPARTITIONS 2 (
+PARTITION partition0_name_to_encrypt VALUES LESS THAN (100),
+PARTITION partition1_name_to_encrypt VALUES LESS THAN (MAXVALUE)
+)
+;
+CREATE TABLE myisam_table_name_to_encrypt (
+int_column_name_to_encrypt INT AUTO_INCREMENT PRIMARY KEY,
+char_column_name_to_encrypt VARCHAR(255),
+datetime_column_name_to_encrypt DATETIME,
+text_column_name_to_encrypt TEXT
+) ENGINE=MyISAM;
+CREATE TABLE aria_table_name_to_encrypt (
+int_column_name_to_encrypt INT AUTO_INCREMENT PRIMARY KEY,
+varchar_column_name_to_encrypt VARCHAR(1024),
+enum_column_name_to_encrypt ENUM(
+'enum_value1_to_encrypt',
+'enum_value2_to_encrypt'
+ ),
+timestamp_column_name_to_encrypt TIMESTAMP(6) NULL,
+blob_column_name_to_encrypt BLOB
+) ENGINE=Aria;
+CREATE TRIGGER trigger_name_to_encrypt
+AFTER INSERT ON myisam_table_name_to_encrypt FOR EACH ROW
+INSERT INTO aria_table_name_to_encrypt (varchar_column_name_to_encrypt)
+VALUES (NEW.char_column_name_to_encrypt);
+CREATE DEFINER=user_name_to_encrypt VIEW view_name_to_encrypt
+AS SELECT * FROM innodb_table_name_to_encrypt;
+CREATE FUNCTION func_name_to_encrypt (func_parameter_to_encrypt INT)
+RETURNS VARCHAR(64)
+RETURN 'func_result_to_encrypt';
+CREATE PROCEDURE proc_name_to_encrypt (
+IN proc_in_parameter_to_encrypt CHAR(32),
+OUT proc_out_parameter_to_encrypt INT
+)
+BEGIN
+DECLARE procvar_name_to_encrypt CHAR(64) DEFAULT 'procvar_val_to_encrypt';
+DECLARE cursor_name_to_encrypt CURSOR FOR
+SELECT virt_column_name_to_encrypt FROM innodb_table_name_to_encrypt;
+DECLARE EXIT HANDLER FOR NOT FOUND
+BEGIN
+SET @stmt_var_to_encrypt = CONCAT(
+"SELECT
+ IF (RAND()>0.5,'enum_value2_to_encrypt','enum_value1_to_encrypt')
+ FROM innodb_table_name_to_encrypt
+ INTO OUTFILE '", proc_in_parameter_to_encrypt, "'");
+PREPARE stmt_to_encrypt FROM @stmt_var_to_encrypt;
+EXECUTE stmt_to_encrypt;
+DEALLOCATE PREPARE stmt_to_encrypt;
+END;
+OPEN cursor_name_to_encrypt;
+proc_label_to_encrypt: LOOP
+FETCH cursor_name_to_encrypt INTO procvar_name_to_encrypt;
+END LOOP;
+CLOSE cursor_name_to_encrypt;
+END $$
+CREATE SERVER server_name_to_encrypt
+FOREIGN DATA WRAPPER mysql
+OPTIONS (HOST 'host_name_to_encrypt');
+connect con1,localhost,user_name_to_encrypt,password_to_encrypt,database_name_to_encrypt;
+CREATE TEMPORARY TABLE tmp_table_name_to_encrypt (
+float_column_name_to_encrypt FLOAT,
+binary_column_name_to_encrypt BINARY(64)
+);
+disconnect con1;
+connection server_1;
+CREATE INDEX index_name_to_encrypt
+ON myisam_table_name_to_encrypt (datetime_column_name_to_encrypt);
+ALTER DATABASE database_name_to_encrypt CHARACTER SET utf8;
+ALTER TABLE innodb_table_name_to_encrypt
+MODIFY timestamp_column_name_to_encrypt TIMESTAMP NOT NULL
+DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
+;
+ALTER ALGORITHM=MERGE VIEW view_name_to_encrypt
+AS SELECT * FROM innodb_table_name_to_encrypt;
+RENAME TABLE innodb_table_name_to_encrypt TO new_table_name_to_encrypt;
+ALTER TABLE new_table_name_to_encrypt RENAME TO innodb_table_name_to_encrypt;
+set @user_var1_to_encrypt= 'dyncol1_val_to_encrypt';
+set @user_var2_to_encrypt= 'dyncol2_name_to_encrypt';
+INSERT INTO view_name_to_encrypt VALUES
+(1, NOW(6), COLUMN_CREATE('dyncol1_name_to_encrypt',@user_var1_to_encrypt), NULL, NULL),
+(2, NOW(6), COLUMN_CREATE(@user_var2_to_encrypt,'dyncol2_val_to_encrypt'), NULL, NULL)
+;
+BEGIN NOT ATOMIC
+DECLARE counter_name_to_encrypt INT DEFAULT 0;
+START TRANSACTION;
+WHILE counter_name_to_encrypt<12 DO
+SELECT COUNT(*) INTO @cnt FROM innodb_table_name_to_encrypt;
+INSERT INTO innodb_table_name_to_encrypt
+SELECT int_column_name_to_encrypt+@cnt, NOW(6), blob_column_name_to_encrypt, NULL, NULL
+FROM innodb_table_name_to_encrypt
+ORDER BY int_column_name_to_encrypt;
+SET counter_name_to_encrypt = counter_name_to_encrypt+1;
+END WHILE;
+COMMIT;
+END
+$$
+INSERT INTO myisam_table_name_to_encrypt
+SELECT NULL, 'char_literal_to_encrypt', NULL, 'text_to_encrypt';
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+CALL proc_name_to_encrypt('file_name_to_encrypt',@useless_var_to_encrypt);
+TRUNCATE TABLE aria_table_name_to_encrypt;
+LOAD DATA INFILE 'file_name_to_encrypt' INTO TABLE aria_table_name_to_encrypt
+(enum_column_name_to_encrypt);
+LOAD DATA LOCAL INFILE '<DATADIR>/database_name_to_encrypt/file_name_to_encrypt'
+INTO TABLE aria_table_name_to_encrypt (enum_column_name_to_encrypt);
+UPDATE view_name_to_encrypt SET blob_column_name_to_encrypt =
+COLUMN_CREATE('dyncol1_name_to_encrypt',func_name_to_encrypt(0))
+;
+DELETE FROM aria_table_name_to_encrypt ORDER BY int_column_name_to_encrypt LIMIT 10;
+ANALYZE TABLE myisam_table_name_to_encrypt;
+CHECK TABLE aria_table_name_to_encrypt;
+CHECKSUM TABLE innodb_table_name_to_encrypt, myisam_table_name_to_encrypt;
+RENAME USER user_name_to_encrypt to new_user_name_to_encrypt;
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM new_user_name_to_encrypt;
+DROP DATABASE database_name_to_encrypt;
+DROP USER new_user_name_to_encrypt;
+DROP SERVER server_name_to_encrypt;
+####################################################
+# Test 4: binlog with annotated events and binlog_row_image=minimal
+####################################################
+connection server_1;
+SET binlog_annotate_row_events= 1;
+SET GLOBAL binlog_annotate_row_events= 1;
+SET GLOBAL binlog_checksum= NONE;
+SET GLOBAL master_verify_checksum= 0;
+SET GLOBAL binlog_row_image= MINIMAL;
+SET binlog_row_image= MINIMAL;
+call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
+CREATE DATABASE database_name_to_encrypt;
+USE database_name_to_encrypt;
+CREATE USER user_name_to_encrypt;
+GRANT ALL ON database_name_to_encrypt.* TO user_name_to_encrypt;
+SET PASSWORD FOR user_name_to_encrypt = PASSWORD('password_to_encrypt');
+CREATE TABLE innodb_table_name_to_encrypt (
+int_column_name_to_encrypt INT PRIMARY KEY,
+timestamp_column_name_to_encrypt TIMESTAMP(6) NULL,
+blob_column_name_to_encrypt BLOB,
+virt_column_name_to_encrypt INT AS (int_column_name_to_encrypt % 10) VIRTUAL,
+pers_column_name_to_encrypt INT AS (int_column_name_to_encrypt) PERSISTENT,
+INDEX `index_name_to_encrypt`(`timestamp_column_name_to_encrypt`)
+) ENGINE=InnoDB
+PARTITION BY RANGE (int_column_name_to_encrypt)
+SUBPARTITION BY KEY (int_column_name_to_encrypt)
+SUBPARTITIONS 2 (
+PARTITION partition0_name_to_encrypt VALUES LESS THAN (100),
+PARTITION partition1_name_to_encrypt VALUES LESS THAN (MAXVALUE)
+)
+;
+CREATE TABLE myisam_table_name_to_encrypt (
+int_column_name_to_encrypt INT AUTO_INCREMENT PRIMARY KEY,
+char_column_name_to_encrypt VARCHAR(255),
+datetime_column_name_to_encrypt DATETIME,
+text_column_name_to_encrypt TEXT
+) ENGINE=MyISAM;
+CREATE TABLE aria_table_name_to_encrypt (
+int_column_name_to_encrypt INT AUTO_INCREMENT PRIMARY KEY,
+varchar_column_name_to_encrypt VARCHAR(1024),
+enum_column_name_to_encrypt ENUM(
+'enum_value1_to_encrypt',
+'enum_value2_to_encrypt'
+ ),
+timestamp_column_name_to_encrypt TIMESTAMP(6) NULL,
+blob_column_name_to_encrypt BLOB
+) ENGINE=Aria;
+CREATE TRIGGER trigger_name_to_encrypt
+AFTER INSERT ON myisam_table_name_to_encrypt FOR EACH ROW
+INSERT INTO aria_table_name_to_encrypt (varchar_column_name_to_encrypt)
+VALUES (NEW.char_column_name_to_encrypt);
+CREATE DEFINER=user_name_to_encrypt VIEW view_name_to_encrypt
+AS SELECT * FROM innodb_table_name_to_encrypt;
+CREATE FUNCTION func_name_to_encrypt (func_parameter_to_encrypt INT)
+RETURNS VARCHAR(64)
+RETURN 'func_result_to_encrypt';
+CREATE PROCEDURE proc_name_to_encrypt (
+IN proc_in_parameter_to_encrypt CHAR(32),
+OUT proc_out_parameter_to_encrypt INT
+)
+BEGIN
+DECLARE procvar_name_to_encrypt CHAR(64) DEFAULT 'procvar_val_to_encrypt';
+DECLARE cursor_name_to_encrypt CURSOR FOR
+SELECT virt_column_name_to_encrypt FROM innodb_table_name_to_encrypt;
+DECLARE EXIT HANDLER FOR NOT FOUND
+BEGIN
+SET @stmt_var_to_encrypt = CONCAT(
+"SELECT
+ IF (RAND()>0.5,'enum_value2_to_encrypt','enum_value1_to_encrypt')
+ FROM innodb_table_name_to_encrypt
+ INTO OUTFILE '", proc_in_parameter_to_encrypt, "'");
+PREPARE stmt_to_encrypt FROM @stmt_var_to_encrypt;
+EXECUTE stmt_to_encrypt;
+DEALLOCATE PREPARE stmt_to_encrypt;
+END;
+OPEN cursor_name_to_encrypt;
+proc_label_to_encrypt: LOOP
+FETCH cursor_name_to_encrypt INTO procvar_name_to_encrypt;
+END LOOP;
+CLOSE cursor_name_to_encrypt;
+END $$
+CREATE SERVER server_name_to_encrypt
+FOREIGN DATA WRAPPER mysql
+OPTIONS (HOST 'host_name_to_encrypt');
+connect con1,localhost,user_name_to_encrypt,password_to_encrypt,database_name_to_encrypt;
+CREATE TEMPORARY TABLE tmp_table_name_to_encrypt (
+float_column_name_to_encrypt FLOAT,
+binary_column_name_to_encrypt BINARY(64)
+);
+disconnect con1;
+connection server_1;
+CREATE INDEX index_name_to_encrypt
+ON myisam_table_name_to_encrypt (datetime_column_name_to_encrypt);
+ALTER DATABASE database_name_to_encrypt CHARACTER SET utf8;
+ALTER TABLE innodb_table_name_to_encrypt
+MODIFY timestamp_column_name_to_encrypt TIMESTAMP NOT NULL
+DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
+;
+ALTER ALGORITHM=MERGE VIEW view_name_to_encrypt
+AS SELECT * FROM innodb_table_name_to_encrypt;
+RENAME TABLE innodb_table_name_to_encrypt TO new_table_name_to_encrypt;
+ALTER TABLE new_table_name_to_encrypt RENAME TO innodb_table_name_to_encrypt;
+set @user_var1_to_encrypt= 'dyncol1_val_to_encrypt';
+set @user_var2_to_encrypt= 'dyncol2_name_to_encrypt';
+INSERT INTO view_name_to_encrypt VALUES
+(1, NOW(6), COLUMN_CREATE('dyncol1_name_to_encrypt',@user_var1_to_encrypt), NULL, NULL),
+(2, NOW(6), COLUMN_CREATE(@user_var2_to_encrypt,'dyncol2_val_to_encrypt'), NULL, NULL)
+;
+BEGIN NOT ATOMIC
+DECLARE counter_name_to_encrypt INT DEFAULT 0;
+START TRANSACTION;
+WHILE counter_name_to_encrypt<12 DO
+SELECT COUNT(*) INTO @cnt FROM innodb_table_name_to_encrypt;
+INSERT INTO innodb_table_name_to_encrypt
+SELECT int_column_name_to_encrypt+@cnt, NOW(6), blob_column_name_to_encrypt, NULL, NULL
+FROM innodb_table_name_to_encrypt
+ORDER BY int_column_name_to_encrypt;
+SET counter_name_to_encrypt = counter_name_to_encrypt+1;
+END WHILE;
+COMMIT;
+END
+$$
+INSERT INTO myisam_table_name_to_encrypt
+SELECT NULL, 'char_literal_to_encrypt', NULL, 'text_to_encrypt';
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+CALL proc_name_to_encrypt('file_name_to_encrypt',@useless_var_to_encrypt);
+TRUNCATE TABLE aria_table_name_to_encrypt;
+LOAD DATA INFILE 'file_name_to_encrypt' INTO TABLE aria_table_name_to_encrypt
+(enum_column_name_to_encrypt);
+LOAD DATA LOCAL INFILE '<DATADIR>/database_name_to_encrypt/file_name_to_encrypt'
+INTO TABLE aria_table_name_to_encrypt (enum_column_name_to_encrypt);
+UPDATE view_name_to_encrypt SET blob_column_name_to_encrypt =
+COLUMN_CREATE('dyncol1_name_to_encrypt',func_name_to_encrypt(0))
+;
+DELETE FROM aria_table_name_to_encrypt ORDER BY int_column_name_to_encrypt LIMIT 10;
+ANALYZE TABLE myisam_table_name_to_encrypt;
+CHECK TABLE aria_table_name_to_encrypt;
+CHECKSUM TABLE innodb_table_name_to_encrypt, myisam_table_name_to_encrypt;
+RENAME USER user_name_to_encrypt to new_user_name_to_encrypt;
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM new_user_name_to_encrypt;
+DROP DATABASE database_name_to_encrypt;
+DROP USER new_user_name_to_encrypt;
+DROP SERVER server_name_to_encrypt;
+#############################
+# Final checks for the master
+#############################
+NOT FOUND /_to_encrypt.*/ in master-bin.0*
+NOT FOUND /COMMIT.*/ in master-bin.0*
+NOT FOUND /TIMESTAMP.*/ in master-bin.0*
+include/save_master_pos.inc
+#############################
+# Final checks for the slave
+#############################
+connection server_2;
+include/sync_io_with_master.inc
+FOUND 1 /_to_encrypt.*/ in slave-relay-bin.0*
+FOUND 1 /COMMIT.*/ in slave-relay-bin.0*
+FOUND 1 /TIMESTAMP.*/ in slave-relay-bin.0*
+include/start_slave.inc
+include/sync_slave_sql_with_io.inc
+FOUND 1 /_to_encrypt.*/ in slave-bin.0*
+FOUND 1 /COMMIT.*/ in slave-bin.0*
+FOUND 1 /TIMESTAMP.*/ in slave-bin.0*
+##########
+# Cleanup
+##########
+connection server_1;
+SET GLOBAL binlog_annotate_row_events= @binlog_annotate_row_events.save;
+SET GLOBAL binlog_checksum= @binlog_checksum.save;
+SET GLOBAL master_verify_checksum= @master_verify_checksum.save;
+SET GLOBAL binlog_row_image= @binlog_row_image.save;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/encrypted_master.test b/mysql-test/suite/binlog_encryption/encrypted_master.test
new file mode 100644
index 00000000..f6fc172c
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encrypted_master.test
@@ -0,0 +1,188 @@
+#
+# The test checks that basic DDL and DML events are encrypted
+# in the binary log on master.
+# The test is to be run with all binlog formats
+# (combinations for rpl_init.inc take care of that).
+#
+#
+# The test runs with the encrypted master and non-encrypted slave.
+# It generates a sequence of events on master, and checks that
+# - all events are encrypted on master;
+# - slave is able to replicate from the master;
+# - relay logs and binary logs are not encrypted on slave.
+#
+# The same exercise is repeated
+# - without annotated binlog events and without binlog checksums;
+# - with binlog checksums;
+# - with annotated events and binlog checksums;
+# - with annotated events, default checksums and minimal binlog row image
+#
+
+# The test can take very long time with valgrind
+--source include/not_valgrind.inc
+
+--source include/have_partition.inc
+--source encryption_algorithms.inc
+--source include/have_innodb.inc
+--enable_connect_log
+
+--echo #################
+--echo # Initialization
+--echo #################
+
+--disable_connect_log
+--let $rpl_topology= 1->2
+--source include/rpl_init.inc
+--enable_connect_log
+
+# We stop SQL thread because we want to have
+# all relay logs at the end of the test flow
+
+--connection server_2
+--disable_connect_log
+--source include/stop_slave_sql.inc
+--enable_connect_log
+
+--connection server_1
+
+SET @binlog_annotate_row_events.save= @@global.binlog_annotate_row_events;
+SET @binlog_checksum.save= @@global.binlog_checksum;
+SET @master_verify_checksum.save= @@global.master_verify_checksum;
+SET @binlog_row_image.save= @@global.binlog_row_image;
+
+--echo ####################################################
+--echo # Test 1: simple binlog, no checksum, no annotation
+--echo ####################################################
+
+--connection server_1
+
+SET binlog_annotate_row_events= 0;
+SET GLOBAL binlog_annotate_row_events= 0;
+SET GLOBAL binlog_checksum= NONE;
+SET GLOBAL master_verify_checksum= 0;
+
+--source testdata.inc
+
+--echo ####################################################
+--echo # Test 2: binlog with checksum, no annotated events
+--echo ####################################################
+
+--connection server_1
+
+SET binlog_annotate_row_events= 0;
+SET GLOBAL binlog_annotate_row_events= 0;
+SET GLOBAL binlog_checksum= CRC32;
+SET GLOBAL master_verify_checksum= 1;
+
+--source testdata.inc
+
+--echo ####################################################
+--echo # Test 3: binlog with checksum and annotated events
+--echo ####################################################
+
+--connection server_1
+
+SET binlog_annotate_row_events= 1;
+SET GLOBAL binlog_annotate_row_events= 1;
+SET GLOBAL binlog_checksum= CRC32;
+SET GLOBAL master_verify_checksum= 1;
+
+--source testdata.inc
+
+--echo ####################################################
+--echo # Test 4: binlog with annotated events and binlog_row_image=minimal
+--echo ####################################################
+
+--connection server_1
+
+SET binlog_annotate_row_events= 1;
+SET GLOBAL binlog_annotate_row_events= 1;
+SET GLOBAL binlog_checksum= NONE;
+SET GLOBAL master_verify_checksum= 0;
+SET GLOBAL binlog_row_image= MINIMAL;
+SET binlog_row_image= MINIMAL;
+
+--source testdata.inc
+
+--echo #############################
+--echo # Final checks for the master
+--echo #############################
+
+--let $master_datadir= `SELECT @@datadir`
+
+--let SEARCH_RANGE = 500000
+--let SEARCH_FILE= $master_datadir/master-bin.0*
+--let SEARCH_PATTERN= _to_encrypt.*
+--source include/search_pattern_in_file.inc
+
+--let SEARCH_FILE= $master_datadir/master-bin.0*
+--let SEARCH_PATTERN= COMMIT.*
+--source include/search_pattern_in_file.inc
+
+--let SEARCH_FILE= $master_datadir/master-bin.0*
+--let SEARCH_PATTERN= TIMESTAMP.*
+--source include/search_pattern_in_file.inc
+
+--disable_connect_log
+--source include/save_master_pos.inc
+--enable_connect_log
+
+--echo #############################
+--echo # Final checks for the slave
+--echo #############################
+
+# Wait for the IO thread to write everything to relay logs
+
+--connection server_2
+
+--let $slave_datadir= `SELECT @@datadir`
+
+--disable_connect_log
+--source include/sync_io_with_master.inc
+
+# Check that relay logs are unencrypted
+
+--let SEARCH_FILE= $slave_datadir/slave-relay-bin.0*
+--let SEARCH_PATTERN= _to_encrypt.*
+--source include/search_pattern_in_file.inc
+
+--let SEARCH_FILE= $slave_datadir/slave-relay-bin.0*
+--let SEARCH_PATTERN= COMMIT.*
+--source include/search_pattern_in_file.inc
+
+--let SEARCH_FILE= $slave_datadir/slave-relay-bin.0*
+--let SEARCH_PATTERN= TIMESTAMP.*
+--source include/search_pattern_in_file.inc
+
+
+# Re-enable SQL thread, let it catch up with IO thread
+# and check slave binary logs
+
+--source include/start_slave.inc
+--source include/sync_slave_sql_with_io.inc
+--enable_connect_log
+
+--let SEARCH_FILE= $slave_datadir/slave-bin.0*
+--let SEARCH_PATTERN= _to_encrypt.*
+--source include/search_pattern_in_file.inc
+
+--let SEARCH_FILE= $slave_datadir/slave-bin.0*
+--let SEARCH_PATTERN= COMMIT.*
+--source include/search_pattern_in_file.inc
+
+--let SEARCH_FILE= $slave_datadir/slave-bin.0*
+--let SEARCH_PATTERN= TIMESTAMP.*
+--source include/search_pattern_in_file.inc
+
+--echo ##########
+--echo # Cleanup
+--echo ##########
+
+--connection server_1
+SET GLOBAL binlog_annotate_row_events= @binlog_annotate_row_events.save;
+SET GLOBAL binlog_checksum= @binlog_checksum.save;
+SET GLOBAL master_verify_checksum= @master_verify_checksum.save;
+SET GLOBAL binlog_row_image= @binlog_row_image.save;
+
+--disable_connect_log
+--source include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/encrypted_master_lost_key.result b/mysql-test/suite/binlog_encryption/encrypted_master_lost_key.result
new file mode 100644
index 00000000..5c934af1
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encrypted_master_lost_key.result
@@ -0,0 +1,111 @@
+#################
+# Initialization
+#################
+include/rpl_init.inc [topology=1->2]
+connection server_2;
+include/stop_slave.inc
+#####################################################
+# Pre-test 1: Initial key value
+#####################################################
+connection server_1;
+CREATE TABLE table1_to_encrypt (
+pk INT AUTO_INCREMENT PRIMARY KEY,
+ts TIMESTAMP NULL,
+b BLOB
+) ENGINE=MyISAM;
+INSERT INTO table1_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt');
+INSERT INTO table1_to_encrypt SELECT NULL,NOW(),b FROM table1_to_encrypt;
+SET binlog_format=ROW;
+INSERT INTO table1_to_encrypt SELECT NULL,NOW(),b FROM table1_to_encrypt;
+INSERT INTO table1_to_encrypt SELECT NULL,NOW(),b FROM table1_to_encrypt;
+NOT FOUND /table1_to_encrypt/ in master-bin.0*
+#######################################################
+# Pre-test 2: restart master with a different key value
+#######################################################
+connection default;
+connection server_1;
+CREATE TABLE table2_to_encrypt (
+pk INT AUTO_INCREMENT PRIMARY KEY,
+ts TIMESTAMP NULL,
+b BLOB
+) ENGINE=MyISAM;
+INSERT INTO table2_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt');
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+SET binlog_format=ROW;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+NOT FOUND /table2_to_encrypt/ in master-bin.0*
+#####################################################
+# Pre-test 3: restart master again with the right key
+#####################################################
+connection default;
+connection server_1;
+CREATE TABLE table3_to_encrypt (
+pk INT AUTO_INCREMENT PRIMARY KEY,
+ts TIMESTAMP NULL,
+b BLOB
+) ENGINE=MyISAM;
+INSERT INTO table3_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt');
+INSERT INTO table3_to_encrypt SELECT NULL,NOW(),b FROM table3_to_encrypt;
+INSERT INTO table3_to_encrypt SELECT NULL,NOW(),b FROM table3_to_encrypt;
+FLUSH BINARY LOGS;
+INSERT INTO table3_to_encrypt SELECT NULL,NOW(),b FROM table3_to_encrypt;
+#####################################################
+# Test 1: Check that if master has an encrypted
+# binary log which it cannot decrypt, it
+# still feeds events to the slave, and SQL
+# thread produces an expected error upon
+# receiving these unreadable events .
+# This behavior is confirmed in MDEV-11323
+#####################################################
+connection server_2;
+START SLAVE IO_THREAD;
+include/wait_for_slave_io_to_start.inc
+START SLAVE SQL_THREAD;
+include/wait_for_slave_sql_error.inc [errno=1594]
+SHOW TABLES;
+Tables_in_test
+table1_to_encrypt
+SELECT COUNT(*) FROM table1_to_encrypt;
+COUNT(*)
+8
+#####################################################
+# Test 2: check that replication works if it starts
+# from a good binary log
+#####################################################
+connection server_2;
+include/stop_slave.inc
+RESET SLAVE ALL;
+DROP DATABASE test;
+CREATE DATABASE test;
+USE test;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=<MASTER_PORT>, MASTER_USER='root', MASTER_LOG_FILE='master-bin.000003';
+include/start_slave.inc
+SHOW TABLES;
+Tables_in_test
+table3_to_encrypt
+#####################################################
+# Test 3: check that replication works if we purge
+# master logs up to the good one
+#####################################################
+connection server_2;
+connection server_1;
+PURGE BINARY LOGS TO 'master-bin.000003';
+connection server_2;
+include/stop_slave.inc
+RESET SLAVE ALL;
+DROP DATABASE test;
+CREATE DATABASE test;
+USE test;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=<MASTER_PORT>, MASTER_USER='root';
+include/start_slave.inc
+SHOW TABLES;
+Tables_in_test
+table3_to_encrypt
+##########
+# Cleanup
+##########
+connection server_1;
+DROP TABLE table1_to_encrypt, table2_to_encrypt, table3_to_encrypt;
+connection server_2;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/encrypted_master_lost_key.test b/mysql-test/suite/binlog_encryption/encrypted_master_lost_key.test
new file mode 100644
index 00000000..c4cf337f
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encrypted_master_lost_key.test
@@ -0,0 +1,206 @@
+#
+# The test checks effects and workarounds for the situation when
+# the key used to encrypt previous binary logs on master has been lost,
+# and master runs with a different one.
+#
+# The test starts with encrypted binlogs on master.
+# It stops replication, generates a few statement and row events
+# on the master, then restarts the server with encrypted binlog,
+# but with a different value for key 1.
+#
+# Then it resumes replication and checks what happens when the master
+# feed the encrypted logs to the slave (slave SQL thread should
+# produce and error).
+#
+# Then the test resets the slave, configures it to start from a "good"
+# master binlog log, for which the master has a key, starts replication
+# and checks that it works.
+#
+# Then it resets the slave again, purges binary logs on master up
+# to the "good" one, starts replication and checks that it works.
+#
+
+--source include/have_binlog_format_mixed.inc
+
+--echo #################
+--echo # Initialization
+--echo #################
+
+--let $rpl_topology= 1->2
+--source include/rpl_init.inc
+
+--enable_connect_log
+
+# We stop replication because we want it to happen after the switch
+
+--connection server_2
+--disable_connect_log
+--source include/stop_slave.inc
+--enable_connect_log
+
+--echo #####################################################
+--echo # Pre-test 1: Initial key value
+--echo #####################################################
+
+--connection server_1
+
+CREATE TABLE table1_to_encrypt (
+ pk INT AUTO_INCREMENT PRIMARY KEY,
+ ts TIMESTAMP NULL,
+ b BLOB
+) ENGINE=MyISAM;
+
+INSERT INTO table1_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt');
+INSERT INTO table1_to_encrypt SELECT NULL,NOW(),b FROM table1_to_encrypt;
+SET binlog_format=ROW;
+INSERT INTO table1_to_encrypt SELECT NULL,NOW(),b FROM table1_to_encrypt;
+INSERT INTO table1_to_encrypt SELECT NULL,NOW(),b FROM table1_to_encrypt;
+
+# Make sure that binary logs are encrypted
+
+--let SEARCH_RANGE = 500000
+--let SEARCH_FILE= master-bin.0*
+--let SEARCH_PATTERN= table1_to_encrypt
+--source include/search_pattern_in_file.inc
+
+--echo #######################################################
+--echo # Pre-test 2: restart master with a different key value
+--echo #######################################################
+
+--write_file $MYSQL_TMP_DIR/master_lose_key.key
+1;00000AAAAAAAAAAAAAAAAAAAAAA00000
+EOF
+
+--let $rpl_server_parameters= --file-key-management-filename=$MYSQL_TMP_DIR/master_lose_key.key
+
+--let $rpl_server_number= 1
+--source restart_server.inc
+
+CREATE TABLE table2_to_encrypt (
+ pk INT AUTO_INCREMENT PRIMARY KEY,
+ ts TIMESTAMP NULL,
+ b BLOB
+) ENGINE=MyISAM;
+
+INSERT INTO table2_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt');
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+SET binlog_format=ROW;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+
+# Make sure that binary logs are encrypted
+
+--let SEARCH_FILE= master-bin.0*
+--let SEARCH_PATTERN= table2_to_encrypt
+--source include/search_pattern_in_file.inc
+
+--echo #####################################################
+--echo # Pre-test 3: restart master again with the right key
+--echo #####################################################
+
+--let $rpl_server_parameters=
+--let $rpl_server_number= 1
+--source restart_server.inc
+
+--let $good_master_binlog= query_get_value(SHOW MASTER STATUS,File,1)
+
+CREATE TABLE table3_to_encrypt (
+ pk INT AUTO_INCREMENT PRIMARY KEY,
+ ts TIMESTAMP NULL,
+ b BLOB
+) ENGINE=MyISAM;
+
+INSERT INTO table3_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt');
+INSERT INTO table3_to_encrypt SELECT NULL,NOW(),b FROM table3_to_encrypt;
+INSERT INTO table3_to_encrypt SELECT NULL,NOW(),b FROM table3_to_encrypt;
+FLUSH BINARY LOGS;
+INSERT INTO table3_to_encrypt SELECT NULL,NOW(),b FROM table3_to_encrypt;
+
+--save_master_pos
+
+--echo #####################################################
+--echo # Test 1: Check that if master has an encrypted
+--echo # binary log which it cannot decrypt, it
+--echo # still feeds events to the slave, and SQL
+--echo # thread produces an expected error upon
+--echo # receiving these unreadable events .
+--echo # This behavior is confirmed in MDEV-11323
+--echo #####################################################
+--connection server_2
+
+--disable_connect_log
+START SLAVE IO_THREAD;
+--source include/wait_for_slave_io_to_start.inc
+
+START SLAVE SQL_THREAD;
+--let $slave_sql_errno= 1594
+--source include/wait_for_slave_sql_error.inc
+--enable_connect_log
+
+# Here we should see only table1_to_encrypt and its contents,
+# because it was logged with the initial key
+--sorted_result
+SHOW TABLES;
+SELECT COUNT(*) FROM table1_to_encrypt;
+
+--echo #####################################################
+--echo # Test 2: check that replication works if it starts
+--echo # from a good binary log
+--echo #####################################################
+--connection server_2
+
+--disable_connect_log
+--source include/stop_slave.inc
+RESET SLAVE ALL;
+DROP DATABASE test;
+CREATE DATABASE test;
+USE test;
+--replace_result $SERVER_MYPORT_1 <MASTER_PORT>
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$SERVER_MYPORT_1, MASTER_USER='root', MASTER_LOG_FILE='$good_master_binlog';
+--source include/start_slave.inc
+--enable_connect_log
+--sync_with_master
+
+--sorted_result
+SHOW TABLES;
+
+--echo #####################################################
+--echo # Test 3: check that replication works if we purge
+--echo # master logs up to the good one
+--echo #####################################################
+--connection server_2
+
+--connection server_1
+eval PURGE BINARY LOGS TO '$good_master_binlog';
+
+--connection server_2
+--disable_connect_log
+--source include/stop_slave.inc
+RESET SLAVE ALL;
+DROP DATABASE test;
+CREATE DATABASE test;
+USE test;
+--replace_result $SERVER_MYPORT_1 <MASTER_PORT>
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$SERVER_MYPORT_1, MASTER_USER='root';
+--source include/start_slave.inc
+--enable_connect_log
+--sync_with_master
+
+--sorted_result
+SHOW TABLES;
+
+--echo ##########
+--echo # Cleanup
+--echo ##########
+
+--connection server_1
+
+DROP TABLE table1_to_encrypt, table2_to_encrypt, table3_to_encrypt;
+
+--save_master_pos
+
+--connection server_2
+--sync_with_master
+
+--disable_connect_log
+--source include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_coords.cnf b/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_coords.cnf
new file mode 100644
index 00000000..73c9ad65
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_coords.cnf
@@ -0,0 +1,5 @@
+!include my.cnf
+
+[mysqld.1]
+encrypt-binlog=0
+skip-file-key-management
diff --git a/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_coords.result b/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_coords.result
new file mode 100644
index 00000000..35b44be0
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_coords.result
@@ -0,0 +1,92 @@
+#################
+# Initialization
+#################
+include/rpl_init.inc [topology=1->2]
+connection server_2;
+include/stop_slave.inc
+CHANGE MASTER TO MASTER_USE_GTID=NO;
+include/start_slave.inc
+connection server_1;
+connection server_2;
+include/stop_slave.inc
+CHANGE MASTER TO MASTER_USE_GTID=NO;
+#####################################################
+# Part 1: unencrypted master
+#####################################################
+connection server_1;
+call mtr.add_suppression("Got fatal error 1236 from master when reading data from binary log: 'Could not decrypt binlog: encryption key error;");
+CREATE TABLE table1_no_encryption (
+pk INT AUTO_INCREMENT PRIMARY KEY,
+ts TIMESTAMP NULL,
+b BLOB
+) ENGINE=MyISAM;
+INSERT INTO table1_no_encryption VALUES (NULL,NOW(),'data_no_encryption');
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+FLUSH BINARY LOGS;
+SET binlog_format=ROW;
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+NOT FOUND /table1_no_encryption/ in master-bin.0*
+#####################################################
+# Part 2: restart master, now with binlog encryption
+#####################################################
+connection default;
+connection server_1;
+CREATE TABLE table2_to_encrypt (
+pk INT AUTO_INCREMENT PRIMARY KEY,
+ts TIMESTAMP NULL,
+b BLOB
+) ENGINE=MyISAM;
+INSERT INTO table2_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt');
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+FLUSH BINARY LOGS;
+SET binlog_format=ROW;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+NOT FOUND /table2_to_encrypt/ in master-bin.0*
+#####################################################
+# Part 3: restart master again without encryption
+#####################################################
+connection default;
+connection server_1;
+CREATE TABLE table3_no_encryption (
+pk INT AUTO_INCREMENT PRIMARY KEY,
+ts TIMESTAMP NULL,
+b BLOB
+) ENGINE=MyISAM;
+INSERT INTO table3_no_encryption VALUES (NULL,NOW(),'data_no_encryption');
+INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption;
+INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption;
+#####################################################
+# Check: resume replication and check how it goes
+#####################################################
+connection server_2;
+start slave;
+connection server_1;
+connection server_2;
+include/wait_for_slave_io_error.inc [errno=1236]
+SHOW TABLES;
+Tables_in_test
+table1_no_encryption
+include/stop_slave.inc
+include/reset_slave.inc
+Warnings:
+Note 4190 RESET SLAVE is implicitly changing the value of 'Using_Gtid' from 'No' to 'Slave_Pos'
+##########
+# Cleanup
+##########
+connection server_1;
+reset master;
+SELECT COUNT(*) FROM table1_no_encryption;
+COUNT(*)
+8
+SELECT COUNT(*) FROM table2_to_encrypt;
+COUNT(*)
+8
+SELECT COUNT(*) FROM table3_no_encryption;
+COUNT(*)
+4
+DROP TABLE table1_no_encryption, table2_to_encrypt, table3_no_encryption;
+connection server_2;
+include/start_slave.inc
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_coords.test b/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_coords.test
new file mode 100644
index 00000000..e05994f1
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_coords.test
@@ -0,0 +1,166 @@
+#
+# The test starts with unencrypted master.
+# It stops replication, generates a few statement and row events
+# on the master, then restarts the server with encrypted binlog,
+# generates some more events and restarts it back without encryption
+# (no encryption plugin).
+# Then it resumes replication and should error with
+# ER_MASTER_FATAL_ERROR_READING_BINLOG because the encrypted binlog is
+# sent and unable to be decrypted.
+#
+# Note this variation of encrypted_master_switch_to_unencrypted tests
+# using MASTER_USE_GTID=NO. In contrast to the GTID variant of this
+# test, at part 3 (the error case), the master will scan binlogs
+# starting from the first one (which is unencrypted initially, so
+# replication is okay) and continue until the slave encounters the
+# first encrypted event, which causes the slave to error.
+#
+
+--source include/have_binlog_format_mixed.inc
+
+--echo #################
+--echo # Initialization
+--echo #################
+
+--let $rpl_topology= 1->2
+--source include/rpl_init.inc
+
+--connection server_2
+--source include/stop_slave.inc
+CHANGE MASTER TO MASTER_USE_GTID=NO;
+--source include/start_slave.inc
+
+--connection server_1
+
+--enable_connect_log
+
+# We stop replication because we want it to happen after the switch
+
+--connection server_2
+--disable_connect_log
+--source include/stop_slave.inc
+CHANGE MASTER TO MASTER_USE_GTID=NO;
+--enable_connect_log
+
+--echo #####################################################
+--echo # Part 1: unencrypted master
+--echo #####################################################
+
+--connection server_1
+
+call mtr.add_suppression("Got fatal error 1236 from master when reading data from binary log: 'Could not decrypt binlog: encryption key error;");
+
+CREATE TABLE table1_no_encryption (
+ pk INT AUTO_INCREMENT PRIMARY KEY,
+ ts TIMESTAMP NULL,
+ b BLOB
+) ENGINE=MyISAM;
+
+INSERT INTO table1_no_encryption VALUES (NULL,NOW(),'data_no_encryption');
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+FLUSH BINARY LOGS;
+SET binlog_format=ROW;
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+
+# Make sure that binary logs are not encrypted
+
+--let SEARCH_RANGE = 500000
+--let SEARCH_FILE= master-bin.0*
+--let SEARCH_PATTERN= table1_no_encryption
+--source include/search_pattern_in_file.inc
+
+# We are storing the position now, because up to this point the slave
+# should be able to synchronize with master
+--save_master_pos
+
+--echo #####################################################
+--echo # Part 2: restart master, now with binlog encryption
+--echo #####################################################
+
+--let $rpl_server_parameters= --encrypt-binlog=1 --plugin-load-add=file_key_management --file-key-management --loose-file-key-management-filename=$MYSQL_TEST_DIR/std_data/keys.txt
+
+--let $rpl_server_number= 1
+--source restart_server.inc
+
+CREATE TABLE table2_to_encrypt (
+ pk INT AUTO_INCREMENT PRIMARY KEY,
+ ts TIMESTAMP NULL,
+ b BLOB
+) ENGINE=MyISAM;
+
+INSERT INTO table2_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt');
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+FLUSH BINARY LOGS;
+SET binlog_format=ROW;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+
+# Make sure that binary logs are encrypted
+
+--let SEARCH_FILE= master-bin.0*
+--let SEARCH_PATTERN= table2_to_encrypt
+--source include/search_pattern_in_file.inc
+
+--echo #####################################################
+--echo # Part 3: restart master again without encryption
+--echo #####################################################
+
+--let $rpl_server_parameters= --encrypt-binlog=0
+--let $rpl_server_number= 1
+--source restart_server.inc
+
+CREATE TABLE table3_no_encryption (
+ pk INT AUTO_INCREMENT PRIMARY KEY,
+ ts TIMESTAMP NULL,
+ b BLOB
+) ENGINE=MyISAM;
+
+INSERT INTO table3_no_encryption VALUES (NULL,NOW(),'data_no_encryption');
+INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption;
+INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption;
+
+--echo #####################################################
+--echo # Check: resume replication and check how it goes
+--echo #####################################################
+
+--connection server_2
+start slave;
+# The slave should be able to synchronize with master up to
+# the previously saved position (when the log was still unencrypted)
+--sync_with_master
+
+--connection server_1
+# Now save the current position and make slave to try to syncrhonize.
+# It shouldn't work, the slave IO thread is expected to abort with an error
+--save_master_pos
+
+--connection server_2
+--let slave_io_errno=1236
+--source include/wait_for_slave_io_error.inc
+
+--sorted_result
+SHOW TABLES;
+
+--disable_connect_log
+--source include/stop_slave.inc
+--enable_connect_log
+--let $master_use_gtid_option= No
+--source include/reset_slave.inc
+
+--echo ##########
+--echo # Cleanup
+--echo ##########
+
+--connection server_1
+reset master;
+
+SELECT COUNT(*) FROM table1_no_encryption;
+SELECT COUNT(*) FROM table2_to_encrypt;
+SELECT COUNT(*) FROM table3_no_encryption;
+DROP TABLE table1_no_encryption, table2_to_encrypt, table3_no_encryption;
+
+--connection server_2
+--disable_connect_log
+--source include/start_slave.inc
+--source include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_gtid.cnf b/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_gtid.cnf
new file mode 100644
index 00000000..ad1b8b44
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_gtid.cnf
@@ -0,0 +1,8 @@
+!include my.cnf
+
+[mysqld.1]
+encrypt-binlog=0
+skip-file-key-management
+
+[mysqld.2]
+gtid-domain-id=1
diff --git a/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_gtid.result b/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_gtid.result
new file mode 100644
index 00000000..16ea3055
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_gtid.result
@@ -0,0 +1,84 @@
+#################
+# Initialization
+#################
+include/rpl_init.inc [topology=1->2]
+connection server_2;
+include/stop_slave.inc
+CHANGE MASTER TO MASTER_USE_GTID=SLAVE_POS;
+call mtr.add_suppression(" Got fatal error 1236 from master when reading data from binary log: 'Could not set up decryption for binlog.'");
+#####################################################
+# Part 1: unencrypted master
+#####################################################
+connection server_1;
+CREATE TABLE table1_no_encryption (
+pk INT AUTO_INCREMENT PRIMARY KEY,
+ts TIMESTAMP NULL,
+b BLOB
+) ENGINE=MyISAM;
+INSERT INTO table1_no_encryption VALUES (NULL,NOW(),'data_no_encryption');
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+FLUSH BINARY LOGS;
+SET binlog_format=ROW;
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+NOT FOUND /table1_no_encryption/ in master-bin.0*
+#####################################################
+# Part 2: restart master, now with binlog encryption
+#####################################################
+connection default;
+connection server_1;
+CREATE TABLE table2_to_encrypt (
+pk INT AUTO_INCREMENT PRIMARY KEY,
+ts TIMESTAMP NULL,
+b BLOB
+) ENGINE=MyISAM;
+INSERT INTO table2_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt');
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+FLUSH BINARY LOGS;
+SET binlog_format=ROW;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+NOT FOUND /table2_to_encrypt/ in master-bin.0*
+#####################################################
+# Part 3: restart master again without encryption
+#####################################################
+connection default;
+connection server_1;
+CREATE TABLE table3_no_encryption (
+pk INT AUTO_INCREMENT PRIMARY KEY,
+ts TIMESTAMP NULL,
+b BLOB
+) ENGINE=MyISAM;
+INSERT INTO table3_no_encryption VALUES (NULL,NOW(),'data_no_encryption');
+INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption;
+INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption;
+#####################################################
+# Check: resume replication and check how it goes
+#####################################################
+connection server_2;
+start slave;
+include/wait_for_slave_io_error.inc [errno=1236]
+# Ensuring slave was unable to replicate any transactions..
+# ..success
+SHOW TABLES;
+Tables_in_test
+include/stop_slave.inc
+reset slave;
+##########
+# Cleanup
+##########
+connection server_1;
+reset master;
+SELECT COUNT(*) FROM table1_no_encryption;
+COUNT(*)
+8
+SELECT COUNT(*) FROM table2_to_encrypt;
+COUNT(*)
+8
+SELECT COUNT(*) FROM table3_no_encryption;
+COUNT(*)
+4
+DROP TABLE table1_no_encryption, table2_to_encrypt, table3_no_encryption;
+connection server_2;
+include/start_slave.inc
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_gtid.test b/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_gtid.test
new file mode 100644
index 00000000..f882e8f3
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_gtid.test
@@ -0,0 +1,154 @@
+#
+# The test starts with unencrypted master.
+# It stops replication, generates a few statement and row events
+# on the master, then restarts the server with encrypted binlog,
+# generates some more events and restarts it back without encryption
+# (no encryption plugin).
+# Then it resumes replication and should error with
+# ER_MASTER_FATAL_ERROR_READING_BINLOG because the encrypted binlog is
+# sent and unable to be decrypted.
+#
+# Note this variation of encrypted_master_switch_to_unencrypted tests
+# using MASTER_USE_GTID=SLAVE_POS. encrypted_master_switch_to_unencrypted
+# was the original test which only used binlog coordinates. When tested
+# using MASTER_USE_GTID=Slave_Pos, the master optimizes the detection of
+# an undecryptable binlog. I.e, the master will initially look for a
+# Gtid_list_log_event, but fail to decrypt it and fail immediately in
+# part 3.
+#
+
+--source include/have_binlog_format_mixed.inc
+
+--echo #################
+--echo # Initialization
+--echo #################
+
+--let $rpl_topology= 1->2
+--source include/rpl_init.inc
+
+--enable_connect_log
+
+# We stop replication because we want it to happen after the switch
+
+--connection server_2
+--disable_connect_log
+--source include/stop_slave.inc
+CHANGE MASTER TO MASTER_USE_GTID=SLAVE_POS;
+--enable_connect_log
+call mtr.add_suppression(" Got fatal error 1236 from master when reading data from binary log: 'Could not set up decryption for binlog.'");
+
+--echo #####################################################
+--echo # Part 1: unencrypted master
+--echo #####################################################
+
+--connection server_1
+
+CREATE TABLE table1_no_encryption (
+ pk INT AUTO_INCREMENT PRIMARY KEY,
+ ts TIMESTAMP NULL,
+ b BLOB
+) ENGINE=MyISAM;
+
+INSERT INTO table1_no_encryption VALUES (NULL,NOW(),'data_no_encryption');
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+FLUSH BINARY LOGS;
+SET binlog_format=ROW;
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+
+# Make sure that binary logs are not encrypted
+
+--let SEARCH_RANGE = 500000
+--let SEARCH_FILE= master-bin.0*
+--let SEARCH_PATTERN= table1_no_encryption
+--source include/search_pattern_in_file.inc
+
+--echo #####################################################
+--echo # Part 2: restart master, now with binlog encryption
+--echo #####################################################
+
+--let $rpl_server_parameters= --encrypt-binlog=1 --plugin-load-add=$FILE_KEY_MANAGEMENT_SO --file-key-management --loose-file-key-management-filename=$MYSQL_TEST_DIR/std_data/keys.txt
+
+--let $rpl_server_number= 1
+--source restart_server.inc
+
+CREATE TABLE table2_to_encrypt (
+ pk INT AUTO_INCREMENT PRIMARY KEY,
+ ts TIMESTAMP NULL,
+ b BLOB
+) ENGINE=MyISAM;
+
+INSERT INTO table2_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt');
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+FLUSH BINARY LOGS;
+SET binlog_format=ROW;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+
+# Make sure that binary logs are encrypted
+
+--let SEARCH_FILE= master-bin.0*
+--let SEARCH_PATTERN= table2_to_encrypt
+--source include/search_pattern_in_file.inc
+
+--echo #####################################################
+--echo # Part 3: restart master again without encryption
+--echo #####################################################
+
+--let $rpl_server_parameters= --encrypt-binlog=0
+--let $rpl_server_number= 1
+--source restart_server.inc
+
+CREATE TABLE table3_no_encryption (
+ pk INT AUTO_INCREMENT PRIMARY KEY,
+ ts TIMESTAMP NULL,
+ b BLOB
+) ENGINE=MyISAM;
+
+INSERT INTO table3_no_encryption VALUES (NULL,NOW(),'data_no_encryption');
+INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption;
+INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption;
+
+--echo #####################################################
+--echo # Check: resume replication and check how it goes
+--echo #####################################################
+
+--connection server_2
+start slave;
+# Make slave to try to synchronize. It shouldn't work, the slave IO thread is
+# expected to abort with an error
+--let $slave_io_errno= 1236
+--source include/wait_for_slave_io_error.inc
+
+--echo # Ensuring slave was unable to replicate any transactions..
+--let $gsp= `SELECT @@global.gtid_slave_pos`
+if (`SELECT strcmp("$gsp","")`)
+{
+ die Slave without encryption configured should fail to read encrypted binlog;
+}
+--echo # ..success
+
+--sorted_result
+SHOW TABLES;
+
+--disable_connect_log
+--source include/stop_slave.inc
+--enable_connect_log
+reset slave;
+
+--echo ##########
+--echo # Cleanup
+--echo ##########
+
+--connection server_1
+reset master;
+
+SELECT COUNT(*) FROM table1_no_encryption;
+SELECT COUNT(*) FROM table2_to_encrypt;
+SELECT COUNT(*) FROM table3_no_encryption;
+DROP TABLE table1_no_encryption, table2_to_encrypt, table3_no_encryption;
+
+--connection server_2
+--disable_connect_log
+--source include/start_slave.inc
+--source include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/encrypted_slave.cnf b/mysql-test/suite/binlog_encryption/encrypted_slave.cnf
new file mode 100644
index 00000000..fac94db7
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encrypted_slave.cnf
@@ -0,0 +1,12 @@
+!include my.cnf
+
+[mysqld.1]
+encrypt-binlog=0
+
+[mysqld.2]
+#log-slave-updates
+encrypt-binlog
+plugin-load-add= @ENV.FILE_KEY_MANAGEMENT_SO
+file-key-management
+loose-file-key-management-filename= @ENV.MYSQL_TEST_DIR/std_data/keys.txt
+binlog_checksum=NONE
diff --git a/mysql-test/suite/binlog_encryption/encrypted_slave.result b/mysql-test/suite/binlog_encryption/encrypted_slave.result
new file mode 100644
index 00000000..ff8ae374
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encrypted_slave.result
@@ -0,0 +1,176 @@
+#################
+# Initialization
+#################
+include/rpl_init.inc [topology=1->2]
+connection server_2;
+include/stop_slave_sql.inc
+#################
+# Test flow
+#################
+connection server_1;
+call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
+CREATE DATABASE database_name_to_encrypt;
+USE database_name_to_encrypt;
+CREATE USER user_name_to_encrypt;
+GRANT ALL ON database_name_to_encrypt.* TO user_name_to_encrypt;
+SET PASSWORD FOR user_name_to_encrypt = PASSWORD('password_to_encrypt');
+CREATE TABLE innodb_table_name_to_encrypt (
+int_column_name_to_encrypt INT PRIMARY KEY,
+timestamp_column_name_to_encrypt TIMESTAMP(6) NULL,
+blob_column_name_to_encrypt BLOB,
+virt_column_name_to_encrypt INT AS (int_column_name_to_encrypt % 10) VIRTUAL,
+pers_column_name_to_encrypt INT AS (int_column_name_to_encrypt) PERSISTENT,
+INDEX `index_name_to_encrypt`(`timestamp_column_name_to_encrypt`)
+) ENGINE=InnoDB
+PARTITION BY RANGE (int_column_name_to_encrypt)
+SUBPARTITION BY KEY (int_column_name_to_encrypt)
+SUBPARTITIONS 2 (
+PARTITION partition0_name_to_encrypt VALUES LESS THAN (100),
+PARTITION partition1_name_to_encrypt VALUES LESS THAN (MAXVALUE)
+)
+;
+CREATE TABLE myisam_table_name_to_encrypt (
+int_column_name_to_encrypt INT AUTO_INCREMENT PRIMARY KEY,
+char_column_name_to_encrypt VARCHAR(255),
+datetime_column_name_to_encrypt DATETIME,
+text_column_name_to_encrypt TEXT
+) ENGINE=MyISAM;
+CREATE TABLE aria_table_name_to_encrypt (
+int_column_name_to_encrypt INT AUTO_INCREMENT PRIMARY KEY,
+varchar_column_name_to_encrypt VARCHAR(1024),
+enum_column_name_to_encrypt ENUM(
+'enum_value1_to_encrypt',
+'enum_value2_to_encrypt'
+ ),
+timestamp_column_name_to_encrypt TIMESTAMP(6) NULL,
+blob_column_name_to_encrypt BLOB
+) ENGINE=Aria;
+CREATE TRIGGER trigger_name_to_encrypt
+AFTER INSERT ON myisam_table_name_to_encrypt FOR EACH ROW
+INSERT INTO aria_table_name_to_encrypt (varchar_column_name_to_encrypt)
+VALUES (NEW.char_column_name_to_encrypt);
+CREATE DEFINER=user_name_to_encrypt VIEW view_name_to_encrypt
+AS SELECT * FROM innodb_table_name_to_encrypt;
+CREATE FUNCTION func_name_to_encrypt (func_parameter_to_encrypt INT)
+RETURNS VARCHAR(64)
+RETURN 'func_result_to_encrypt';
+CREATE PROCEDURE proc_name_to_encrypt (
+IN proc_in_parameter_to_encrypt CHAR(32),
+OUT proc_out_parameter_to_encrypt INT
+)
+BEGIN
+DECLARE procvar_name_to_encrypt CHAR(64) DEFAULT 'procvar_val_to_encrypt';
+DECLARE cursor_name_to_encrypt CURSOR FOR
+SELECT virt_column_name_to_encrypt FROM innodb_table_name_to_encrypt;
+DECLARE EXIT HANDLER FOR NOT FOUND
+BEGIN
+SET @stmt_var_to_encrypt = CONCAT(
+"SELECT
+ IF (RAND()>0.5,'enum_value2_to_encrypt','enum_value1_to_encrypt')
+ FROM innodb_table_name_to_encrypt
+ INTO OUTFILE '", proc_in_parameter_to_encrypt, "'");
+PREPARE stmt_to_encrypt FROM @stmt_var_to_encrypt;
+EXECUTE stmt_to_encrypt;
+DEALLOCATE PREPARE stmt_to_encrypt;
+END;
+OPEN cursor_name_to_encrypt;
+proc_label_to_encrypt: LOOP
+FETCH cursor_name_to_encrypt INTO procvar_name_to_encrypt;
+END LOOP;
+CLOSE cursor_name_to_encrypt;
+END $$
+CREATE SERVER server_name_to_encrypt
+FOREIGN DATA WRAPPER mysql
+OPTIONS (HOST 'host_name_to_encrypt');
+connect con1,localhost,user_name_to_encrypt,password_to_encrypt,database_name_to_encrypt;
+CREATE TEMPORARY TABLE tmp_table_name_to_encrypt (
+float_column_name_to_encrypt FLOAT,
+binary_column_name_to_encrypt BINARY(64)
+);
+disconnect con1;
+connection server_1;
+CREATE INDEX index_name_to_encrypt
+ON myisam_table_name_to_encrypt (datetime_column_name_to_encrypt);
+ALTER DATABASE database_name_to_encrypt CHARACTER SET utf8;
+ALTER TABLE innodb_table_name_to_encrypt
+MODIFY timestamp_column_name_to_encrypt TIMESTAMP NOT NULL
+DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
+;
+ALTER ALGORITHM=MERGE VIEW view_name_to_encrypt
+AS SELECT * FROM innodb_table_name_to_encrypt;
+RENAME TABLE innodb_table_name_to_encrypt TO new_table_name_to_encrypt;
+ALTER TABLE new_table_name_to_encrypt RENAME TO innodb_table_name_to_encrypt;
+set @user_var1_to_encrypt= 'dyncol1_val_to_encrypt';
+set @user_var2_to_encrypt= 'dyncol2_name_to_encrypt';
+INSERT INTO view_name_to_encrypt VALUES
+(1, NOW(6), COLUMN_CREATE('dyncol1_name_to_encrypt',@user_var1_to_encrypt), NULL, NULL),
+(2, NOW(6), COLUMN_CREATE(@user_var2_to_encrypt,'dyncol2_val_to_encrypt'), NULL, NULL)
+;
+BEGIN NOT ATOMIC
+DECLARE counter_name_to_encrypt INT DEFAULT 0;
+START TRANSACTION;
+WHILE counter_name_to_encrypt<12 DO
+SELECT COUNT(*) INTO @cnt FROM innodb_table_name_to_encrypt;
+INSERT INTO innodb_table_name_to_encrypt
+SELECT int_column_name_to_encrypt+@cnt, NOW(6), blob_column_name_to_encrypt, NULL, NULL
+FROM innodb_table_name_to_encrypt
+ORDER BY int_column_name_to_encrypt;
+SET counter_name_to_encrypt = counter_name_to_encrypt+1;
+END WHILE;
+COMMIT;
+END
+$$
+INSERT INTO myisam_table_name_to_encrypt
+SELECT NULL, 'char_literal_to_encrypt', NULL, 'text_to_encrypt';
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+CALL proc_name_to_encrypt('file_name_to_encrypt',@useless_var_to_encrypt);
+TRUNCATE TABLE aria_table_name_to_encrypt;
+LOAD DATA INFILE 'file_name_to_encrypt' INTO TABLE aria_table_name_to_encrypt
+(enum_column_name_to_encrypt);
+LOAD DATA LOCAL INFILE '<DATADIR>/database_name_to_encrypt/file_name_to_encrypt'
+INTO TABLE aria_table_name_to_encrypt (enum_column_name_to_encrypt);
+UPDATE view_name_to_encrypt SET blob_column_name_to_encrypt =
+COLUMN_CREATE('dyncol1_name_to_encrypt',func_name_to_encrypt(0))
+;
+DELETE FROM aria_table_name_to_encrypt ORDER BY int_column_name_to_encrypt LIMIT 10;
+ANALYZE TABLE myisam_table_name_to_encrypt;
+CHECK TABLE aria_table_name_to_encrypt;
+CHECKSUM TABLE innodb_table_name_to_encrypt, myisam_table_name_to_encrypt;
+RENAME USER user_name_to_encrypt to new_user_name_to_encrypt;
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM new_user_name_to_encrypt;
+DROP DATABASE database_name_to_encrypt;
+DROP USER new_user_name_to_encrypt;
+DROP SERVER server_name_to_encrypt;
+#################
+# Master binlog checks
+#################
+FOUND 1 /_to_encrypt.*/ in master-bin.0*
+FOUND 1 /COMMIT.*/ in master-bin.0*
+FOUND 1 /TIMESTAMP.*/ in master-bin.0*
+include/save_master_pos.inc
+#################
+# Relay log checks
+#################
+connection server_2;
+include/sync_io_with_master.inc
+NOT FOUND /_to_encrypt/ in slave-relay-bin.0*
+NOT FOUND /COMMIT/ in slave-relay-bin.0*
+NOT FOUND /TIMESTAMP/ in slave-relay-bin.0*
+#################
+# Slave binlog checks
+#################
+include/start_slave.inc
+include/sync_slave_sql_with_io.inc
+include/sync_io_with_master.inc
+NOT FOUND /_to_encrypt/ in slave-bin.0*
+NOT FOUND /COMMIT/ in slave-bin.0*
+NOT FOUND /TIMESTAMP/ in slave-bin.0*
+##########
+# Cleanup
+##########
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/encrypted_slave.test b/mysql-test/suite/binlog_encryption/encrypted_slave.test
new file mode 100644
index 00000000..94777957
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encrypted_slave.test
@@ -0,0 +1,119 @@
+#
+# The test checks that basic DDL and DML events are encrypted
+# in the relay and binary logs on slave.
+# The test is to be run with all binlog formats
+# (combinations for rpl_init.inc take care of that).
+#
+# The test runs with the non-encrypted master and encrypted slave.
+# It generates a sequence of events on master and checks that
+# relay logs and binary logs are encrypted on slave.
+#
+
+--source include/have_partition.inc
+--source encryption_algorithms.inc
+--source include/have_innodb.inc
+
+--echo #################
+--echo # Initialization
+--echo #################
+
+--let $rpl_topology= 1->2
+--source include/rpl_init.inc
+
+--enable_connect_log
+--connection server_2
+
+# We stop SQL thread because we want to have
+# all relay logs at the end of the test flow
+
+--disable_connect_log
+--source include/stop_slave_sql.inc
+--enable_connect_log
+
+--echo #################
+--echo # Test flow
+--echo #################
+
+--connection server_1
+--source testdata.inc
+
+--echo #################
+--echo # Master binlog checks
+--echo #################
+
+--let $master_datadir= `SELECT @@datadir`
+
+--let SEARCH_RANGE = 500000
+--let SEARCH_FILE= $master_datadir/master-bin.0*
+--let SEARCH_PATTERN= _to_encrypt.*
+--source include/search_pattern_in_file.inc
+
+--let SEARCH_FILE= $master_datadir/master-bin.0*
+--let SEARCH_PATTERN= COMMIT.*
+--source include/search_pattern_in_file.inc
+
+--let SEARCH_FILE= $master_datadir/master-bin.0*
+--let SEARCH_PATTERN= TIMESTAMP.*
+--source include/search_pattern_in_file.inc
+
+--disable_connect_log
+--source include/save_master_pos.inc
+--enable_connect_log
+
+--echo #################
+--echo # Relay log checks
+--echo #################
+
+--connection server_2
+--disable_connect_log
+--source include/sync_io_with_master.inc
+--enable_connect_log
+
+--let $slave_datadir= `SELECT @@datadir`
+
+--let SEARCH_FILE= $slave_datadir/slave-relay-bin.0*
+--let SEARCH_PATTERN= _to_encrypt
+--source include/search_pattern_in_file.inc
+
+--let SEARCH_FILE= $slave_datadir/slave-relay-bin.0*
+--let SEARCH_PATTERN= COMMIT
+--source include/search_pattern_in_file.inc
+
+--let SEARCH_FILE= $slave_datadir/slave-relay-bin.0*
+--let SEARCH_PATTERN= TIMESTAMP
+--source include/search_pattern_in_file.inc
+
+--echo #################
+--echo # Slave binlog checks
+--echo #################
+
+# Re-enable SQL thread, let it catch up with IO thread
+# and check slave binary logs
+
+--disable_connect_log
+--source include/start_slave.inc
+--source include/sync_slave_sql_with_io.inc
+--enable_connect_log
+
+--disable_connect_log
+--source include/sync_io_with_master.inc
+--enable_connect_log
+
+--let SEARCH_FILE= $slave_datadir/slave-bin.0*
+--let SEARCH_PATTERN= _to_encrypt
+--source include/search_pattern_in_file.inc
+
+--let SEARCH_FILE= $slave_datadir/slave-bin.0*
+--let SEARCH_PATTERN= COMMIT
+--source include/search_pattern_in_file.inc
+
+--let SEARCH_FILE= $slave_datadir/slave-bin.0*
+--let SEARCH_PATTERN= TIMESTAMP
+--source include/search_pattern_in_file.inc
+
+--echo ##########
+--echo # Cleanup
+--echo ##########
+
+--disable_connect_log
+--source include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/encryption_algorithms.combinations b/mysql-test/suite/binlog_encryption/encryption_algorithms.combinations
new file mode 100644
index 00000000..6bda5a6b
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encryption_algorithms.combinations
@@ -0,0 +1,5 @@
+[ctr]
+loose-file-key-management-encryption-algorithm=aes_ctr
+
+[cbc]
+loose-file-key-management-encryption-algorithm=aes_cbc
diff --git a/mysql-test/suite/binlog_encryption/encryption_algorithms.inc b/mysql-test/suite/binlog_encryption/encryption_algorithms.inc
new file mode 100644
index 00000000..ca559622
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encryption_algorithms.inc
@@ -0,0 +1,2 @@
+# Empty include file just to enable encryption algorithm combinations
+# for those tests which need them
diff --git a/mysql-test/suite/binlog_encryption/encryption_combo.cnf b/mysql-test/suite/binlog_encryption/encryption_combo.cnf
new file mode 100644
index 00000000..bc4ecbcb
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encryption_combo.cnf
@@ -0,0 +1,5 @@
+!include my.cnf
+
+[mysqld.1]
+encrypt-binlog=0
+
diff --git a/mysql-test/suite/binlog_encryption/encryption_combo.result b/mysql-test/suite/binlog_encryption/encryption_combo.result
new file mode 100644
index 00000000..de5d91df
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encryption_combo.result
@@ -0,0 +1,78 @@
+#################
+# Initialization
+#################
+include/rpl_init.inc [topology=1->2]
+connection server_2;
+include/stop_slave.inc
+#####################################################
+# Part 1: unencrypted master
+#####################################################
+connection server_1;
+CREATE TABLE table1_no_encryption (
+pk INT AUTO_INCREMENT PRIMARY KEY,
+ts TIMESTAMP NULL,
+b BLOB
+) ENGINE=MyISAM;
+INSERT INTO table1_no_encryption VALUES (NULL,NOW(),'data_no_encryption');
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+FLUSH BINARY LOGS;
+SET binlog_format=ROW;
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+FOUND 11 /table1_no_encryption/ in master-bin.0*
+#####################################################
+# Part 2: restart master, now with binlog encryption
+#####################################################
+connection default;
+connection server_1;
+CREATE TABLE table2_to_encrypt (
+pk INT AUTO_INCREMENT PRIMARY KEY,
+ts TIMESTAMP NULL,
+b BLOB
+) ENGINE=MyISAM;
+INSERT INTO table2_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt');
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+FLUSH BINARY LOGS;
+SET binlog_format=ROW;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+NOT FOUND /table2_to_encrypt/ in master-bin.0*
+#####################################################
+# Part 3: restart master again without encryption
+#####################################################
+connection default;
+connection server_1;
+CREATE TABLE table3_no_encryption (
+pk INT AUTO_INCREMENT PRIMARY KEY,
+ts TIMESTAMP NULL,
+b BLOB
+) ENGINE=MyISAM;
+INSERT INTO table3_no_encryption VALUES (NULL,NOW(),'data_no_encryption');
+INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption;
+INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption;
+#####################################################
+# Check: resume replication and check that it works
+#####################################################
+connection server_2;
+include/start_slave.inc
+SHOW TABLES;
+Tables_in_test
+table1_no_encryption
+table2_to_encrypt
+table3_no_encryption
+##########
+# Cleanup
+##########
+connection server_1;
+SELECT COUNT(*) FROM table1_no_encryption;
+COUNT(*)
+8
+SELECT COUNT(*) FROM table2_to_encrypt;
+COUNT(*)
+8
+SELECT COUNT(*) FROM table3_no_encryption;
+COUNT(*)
+4
+DROP TABLE table1_no_encryption, table2_to_encrypt, table3_no_encryption;
+connection server_2;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/encryption_combo.test b/mysql-test/suite/binlog_encryption/encryption_combo.test
new file mode 100644
index 00000000..c24e77f4
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/encryption_combo.test
@@ -0,0 +1,137 @@
+#
+# The test checks that master with decryption capabilities can switch
+# between encrypted and unencrypted logs (with server restart),
+# and can feed the mix of encrypted/unencrypted logs to a slave.
+#
+# The test starts with unencrypted master.
+# It stops replication, generates a few statement and row events
+# on the master, then restarts the server with encrypted binlog,
+# generates some more events and restarts it back with unencrypted binlog.
+# Then it resumes replication and checks that all events
+# are replicated successfully.
+#
+
+--source include/have_binlog_format_mixed.inc
+
+--echo #################
+--echo # Initialization
+--echo #################
+
+--let $rpl_topology= 1->2
+--source include/rpl_init.inc
+
+--enable_connect_log
+
+# We stop replication because we want it to happen after the switch
+
+--connection server_2
+--disable_connect_log
+--source include/stop_slave.inc
+--enable_connect_log
+
+--echo #####################################################
+--echo # Part 1: unencrypted master
+--echo #####################################################
+
+--connection server_1
+
+CREATE TABLE table1_no_encryption (
+ pk INT AUTO_INCREMENT PRIMARY KEY,
+ ts TIMESTAMP NULL,
+ b BLOB
+) ENGINE=MyISAM;
+
+INSERT INTO table1_no_encryption VALUES (NULL,NOW(),'data_no_encryption');
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+FLUSH BINARY LOGS;
+SET binlog_format=ROW;
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
+
+# Make sure that binary logs are not encrypted
+
+--let $master_datadir= `SELECT @@datadir`
+
+--let SEARCH_RANGE = 500000
+--let SEARCH_FILE= $master_datadir/master-bin.0*
+--let SEARCH_PATTERN= table1_no_encryption
+--source include/search_pattern_in_file.inc
+
+--echo #####################################################
+--echo # Part 2: restart master, now with binlog encryption
+--echo #####################################################
+
+--let $rpl_server_parameters= --encrypt-binlog=1
+--let $rpl_server_number= 1
+--source restart_server.inc
+
+CREATE TABLE table2_to_encrypt (
+ pk INT AUTO_INCREMENT PRIMARY KEY,
+ ts TIMESTAMP NULL,
+ b BLOB
+) ENGINE=MyISAM;
+
+INSERT INTO table2_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt');
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+FLUSH BINARY LOGS;
+SET binlog_format=ROW;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
+
+# Make sure that binary logs are encrypted
+
+--let SEARCH_FILE= $master_datadir/master-bin.0*
+--let SEARCH_PATTERN= table2_to_encrypt
+--source include/search_pattern_in_file.inc
+
+--echo #####################################################
+--echo # Part 3: restart master again without encryption
+--echo #####################################################
+
+--let $rpl_server_parameters= --encrypt-binlog=0
+--let $rpl_server_number= 1
+--source restart_server.inc
+
+CREATE TABLE table3_no_encryption (
+ pk INT AUTO_INCREMENT PRIMARY KEY,
+ ts TIMESTAMP NULL,
+ b BLOB
+) ENGINE=MyISAM;
+
+INSERT INTO table3_no_encryption VALUES (NULL,NOW(),'data_no_encryption');
+INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption;
+INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption;
+
+--save_master_pos
+
+--echo #####################################################
+--echo # Check: resume replication and check that it works
+--echo #####################################################
+--connection server_2
+
+--disable_connect_log
+--source include/start_slave.inc
+--enable_connect_log
+--sync_with_master
+
+--sorted_result
+SHOW TABLES;
+
+--echo ##########
+--echo # Cleanup
+--echo ##########
+
+--connection server_1
+
+SELECT COUNT(*) FROM table1_no_encryption;
+SELECT COUNT(*) FROM table2_to_encrypt;
+SELECT COUNT(*) FROM table3_no_encryption;
+DROP TABLE table1_no_encryption, table2_to_encrypt, table3_no_encryption;
+
+--save_master_pos
+
+--connection server_2
+--sync_with_master
+
+--disable_connect_log
+--source include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/multisource.cnf b/mysql-test/suite/binlog_encryption/multisource.cnf
new file mode 100644
index 00000000..52db51d9
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/multisource.cnf
@@ -0,0 +1,17 @@
+!include my.cnf
+
+[mysqld.1]
+log-bin=master-bin
+
+[mysqld.2]
+log-bin=master-bin
+
+[mysqld.3]
+innodb
+log-bin=slave-bin
+server-id=3
+log-warnings=2
+
+[ENV]
+SERVER_MYPORT_3= @mysqld.3.port
+SERVER_MYSOCK_3= @mysqld.3.socket
diff --git a/mysql-test/suite/binlog_encryption/multisource.result b/mysql-test/suite/binlog_encryption/multisource.result
new file mode 100644
index 00000000..4b53b465
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/multisource.result
@@ -0,0 +1,251 @@
+connect slave,127.0.0.1,root,,,$SERVER_MYPORT_3;
+change master 'abc' to relay_log_file='';
+ERROR HY000: Failed initializing relay log position: Could not find target log during relay log initialization
+change master 'abc2' to master_host='';
+ERROR HY000: Incorrect arguments to MASTER_HOST
+change master 'master1' to
+master_port=MYPORT_1,
+master_host='127.0.0.1',
+master_user='root';
+start slave 'master1';
+set default_master_connection = 'master1';
+include/wait_for_slave_to_start.inc
+connect master1,127.0.0.1,root,,,$SERVER_MYPORT_1;
+connection slave;
+#
+# Checking SHOW SLAVE 'master1' STATUS
+#
+Master_Port = 'MYPORT_1'
+Relay_Log_File = 'mysqld-relay-bin-master1.000002'
+Slave_IO_Running = 'Yes'
+Slave_SQL_Running = 'Yes'
+Last_Errno = '0'
+Last_SQL_Errno = '0'
+#
+# Checking SHOW SLAVE STATUS
+#
+Master_Port = 'MYPORT_1'
+Relay_Log_File = 'mysqld-relay-bin-master1.000002'
+Slave_IO_Running = 'Yes'
+Slave_SQL_Running = 'Yes'
+Last_Errno = '0'
+Last_SQL_Errno = '0'
+#
+# Checking SHOW ALL SLAVES STATUS
+#
+Connection_name = 'master1'
+Master_Port = 'MYPORT_1'
+Relay_Log_File = 'mysqld-relay-bin-master1.000002'
+Slave_IO_Running = 'Yes'
+Slave_SQL_Running = 'Yes'
+Last_Errno = '0'
+Last_SQL_Errno = '0'
+Slave_heartbeat_period = '60.000'
+#
+connection master1;
+drop database if exists db1;
+create database db1;
+use db1;
+create table t1 (i int auto_increment, f1 varchar(16), primary key pk (i,f1)) engine=MyISAM;
+Warnings:
+Warning 1280 Name 'pk' ignored for PRIMARY key.
+insert into t1 (f1) values ('one'),('two');
+connection slave;
+select * from db1.t1;
+i f1
+1 one
+2 two
+# List of relay log files in the datadir
+mysqld-relay-bin-master1.000001
+mysqld-relay-bin-master1.000002
+mysqld-relay-bin-master1.index
+include/show_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+mysqld-relay-bin-master1.000001 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
+mysqld-relay-bin-master1.000001 # Rotate # # mysqld-relay-bin-master1.000002;pos=4
+include/show_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+mysqld-relay-bin-master1.000002 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
+mysqld-relay-bin-master1.000002 # Rotate # # master-bin.000001;pos=POS
+mysqld-relay-bin-master1.000002 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
+mysqld-relay-bin-master1.000002 # Gtid_list # # []
+mysqld-relay-bin-master1.000002 # Binlog_checkpoint # # master-bin.000001
+mysqld-relay-bin-master1.000002 # Gtid # # GTID #-#-#
+mysqld-relay-bin-master1.000002 # Query # # drop database if exists db1
+mysqld-relay-bin-master1.000002 # Gtid # # GTID #-#-#
+mysqld-relay-bin-master1.000002 # Query # # create database db1
+mysqld-relay-bin-master1.000002 # Gtid # # GTID #-#-#
+mysqld-relay-bin-master1.000002 # Query # # use `db1`; create table t1 (i int auto_increment, f1 varchar(16), primary key pk (i,f1)) engine=MyISAM
+mysqld-relay-bin-master1.000002 # Gtid # # BEGIN GTID #-#-#
+mysqld-relay-bin-master1.000002 # Intvar # # INSERT_ID=1
+mysqld-relay-bin-master1.000002 # Query # # use `db1`; insert into t1 (f1) values ('one'),('two')
+mysqld-relay-bin-master1.000002 # Query # # COMMIT
+change master 'master1' to
+master_port=MYPORT_2,
+master_host='127.0.0.1',
+master_user='root';
+ERROR HY000: This operation cannot be performed as you have a running slave 'master1'; run STOP SLAVE 'master1' first
+change master to
+master_port=MYPORT_2,
+master_host='127.0.0.1',
+master_user='root';
+ERROR HY000: This operation cannot be performed as you have a running slave 'master1'; run STOP SLAVE 'master1' first
+change master 'master2' to
+master_port=MYPORT_1,
+master_host='127.0.0.1',
+master_user='root';
+ERROR HY000: Connection 'master2' conflicts with existing connection 'master1'
+set default_master_connection = '';
+change master to
+master_port=MYPORT_2,
+master_host='127.0.0.1',
+master_user='root',
+master_use_gtid=no;
+start slave;
+include/wait_for_slave_to_start.inc
+#
+# Checking SHOW ALL SLAVES STATUS
+#
+Connection_name = ''
+Connection_name = 'master1'
+Master_Port = 'MYPORT_2'
+Master_Port = 'MYPORT_1'
+Relay_Log_File = 'mysqld-relay-bin.000002'
+Relay_Log_File = 'mysqld-relay-bin-master1.000002'
+Slave_IO_Running = 'Yes'
+Slave_IO_Running = 'Yes'
+Slave_SQL_Running = 'Yes'
+Slave_SQL_Running = 'Yes'
+Last_Errno = '0'
+Last_Errno = '0'
+Last_SQL_Errno = '0'
+Last_SQL_Errno = '0'
+Slave_heartbeat_period = '60.000'
+Slave_heartbeat_period = '60.000'
+#
+connection master1;
+insert into t1 (f1) values ('three');
+connect master2,127.0.0.1,root,,,$SERVER_MYPORT_2;
+drop database if exists db2;
+create database db2;
+use db2;
+create table t1 (pk int auto_increment primary key, f1 int) engine=InnoDB;
+begin;
+insert into t1 (f1) values (1),(2);
+connection slave;
+connection master2;
+connection slave;
+select * from db1.t1;
+i f1
+1 one
+2 two
+3 three
+select * from db2.t1;
+pk f1
+connection master2;
+commit;
+connection slave;
+select * from db2.t1;
+pk f1
+1 1
+2 2
+connection master1;
+flush logs;
+connection slave;
+connection master1;
+purge binary logs to 'master-bin.000002';
+show binary logs;
+Log_name File_size
+master-bin.000002 filesize
+insert into t1 (f1) values ('four');
+create table db1.t3 (f1 int) engine=InnoDB;
+connection slave;
+#
+# Checking SHOW ALL SLAVES STATUS
+#
+Connection_name = ''
+Connection_name = 'master1'
+Master_Port = 'MYPORT_2'
+Master_Port = 'MYPORT_1'
+Relay_Log_File = 'mysqld-relay-bin.000002'
+Relay_Log_File = 'mysqld-relay-bin-master1.000004'
+Slave_IO_Running = 'Yes'
+Slave_IO_Running = 'Yes'
+Slave_SQL_Running = 'Yes'
+Slave_SQL_Running = 'Yes'
+Last_Errno = '0'
+Last_Errno = '0'
+Last_SQL_Errno = '0'
+Last_SQL_Errno = '0'
+Slave_heartbeat_period = '60.000'
+Slave_heartbeat_period = '60.000'
+#
+#
+# MDEV:16437: merge 5.7 P_S replication instrumentation and tables
+#
+SELECT * FROM performance_schema.replication_applier_status_by_coordinator;
+CHANNEL_NAME master1
+THREAD_ID #
+SERVICE_STATE ON
+LAST_ERROR_NUMBER 0
+LAST_ERROR_MESSAGE
+LAST_ERROR_TIMESTAMP 0000-00-00 00:00:00
+LAST_SEEN_TRANSACTION 0-1-7
+LAST_TRANS_RETRY_COUNT 0
+CHANNEL_NAME
+THREAD_ID #
+SERVICE_STATE ON
+LAST_ERROR_NUMBER 0
+LAST_ERROR_MESSAGE
+LAST_ERROR_TIMESTAMP 0000-00-00 00:00:00
+LAST_SEEN_TRANSACTION 0-2-4
+LAST_TRANS_RETRY_COUNT 0
+select * from db1.t1;
+i f1
+1 one
+2 two
+3 three
+4 four
+include/show_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+mysqld-relay-bin.000001 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
+mysqld-relay-bin.000001 # Rotate # # mysqld-relay-bin.000002;pos=4
+include/show_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+mysqld-relay-bin.000002 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
+mysqld-relay-bin.000002 # Rotate # # master-bin.000001;pos=POS
+mysqld-relay-bin.000002 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
+mysqld-relay-bin.000002 # Gtid_list # # []
+mysqld-relay-bin.000002 # Binlog_checkpoint # # master-bin.000001
+mysqld-relay-bin.000002 # Gtid # # GTID #-#-#
+mysqld-relay-bin.000002 # Query # # drop database if exists db2
+mysqld-relay-bin.000002 # Gtid # # GTID #-#-#
+mysqld-relay-bin.000002 # Query # # create database db2
+mysqld-relay-bin.000002 # Gtid # # GTID #-#-#
+mysqld-relay-bin.000002 # Query # # use `db2`; create table t1 (pk int auto_increment primary key, f1 int) engine=InnoDB
+mysqld-relay-bin.000002 # Gtid # # BEGIN GTID #-#-#
+mysqld-relay-bin.000002 # Intvar # # INSERT_ID=1
+mysqld-relay-bin.000002 # Query # # use `db2`; insert into t1 (f1) values (1),(2)
+mysqld-relay-bin.000002 # Xid # # COMMIT /* XID */
+disconnect slave;
+connect slave,127.0.0.1,root,,,$SERVER_MYPORT_3;
+stop slave io_thread;
+show status like 'Slave_running';
+Variable_name Value
+Slave_running OFF
+set default_master_connection = 'master1';
+show status like 'Slave_running';
+Variable_name Value
+Slave_running ON
+drop database db1;
+drop database db2;
+include/reset_master_slave.inc
+disconnect slave;
+connection master1;
+drop database db1;
+include/reset_master_slave.inc
+disconnect master1;
+connection master2;
+drop database db2;
+include/reset_master_slave.inc
+disconnect master2;
diff --git a/mysql-test/suite/binlog_encryption/multisource.test b/mysql-test/suite/binlog_encryption/multisource.test
new file mode 100644
index 00000000..53d9f408
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/multisource.test
@@ -0,0 +1 @@
+--source suite/rpl/include/multisource.inc
diff --git a/mysql-test/suite/binlog_encryption/my.cnf b/mysql-test/suite/binlog_encryption/my.cnf
new file mode 100644
index 00000000..d787ebe1
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/my.cnf
@@ -0,0 +1,27 @@
+!include include/default_mysqld.cnf
+!include include/default_client.cnf
+
+[mysqld.1]
+innodb
+plugin-load-add= @ENV.FILE_KEY_MANAGEMENT_SO
+loose-file-key-management-filename= @ENV.MYSQLTEST_VARDIR/std_data/keys.txt
+encrypt-binlog
+log-basename= master
+
+[mysqld.2]
+#!use-slave-opt
+innodb
+log-slave-updates
+log-basename= slave
+
+[ENV]
+
+# We will adopt tests with master-slave setup as well as rpl_init setup,
+# so need both sets of variables
+MASTER_MYPORT= @mysqld.1.port
+SERVER_MYPORT_1= @mysqld.1.port
+SERVER_MYSOCK_1= @mysqld.1.socket
+
+SLAVE_MYPORT= @mysqld.2.port
+SERVER_MYPORT_2= @mysqld.2.port
+SERVER_MYSOCK_2= @mysqld.2.socket
diff --git a/mysql-test/suite/binlog_encryption/mysqlbinlog.combinations b/mysql-test/suite/binlog_encryption/mysqlbinlog.combinations
new file mode 100644
index 00000000..710c53d0
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/mysqlbinlog.combinations
@@ -0,0 +1,6 @@
+[cmpr]
+log-bin-compress=1
+log-bin-compress-min-len=10
+
+[ncmpr]
+log-bin-compress=0
diff --git a/mysql-test/suite/binlog_encryption/mysqlbinlog.result b/mysql-test/suite/binlog_encryption/mysqlbinlog.result
new file mode 100644
index 00000000..e97e0569
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/mysqlbinlog.result
@@ -0,0 +1,7 @@
+RESET MASTER;
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+REPLACE INTO t1 VALUES (4);
+DROP TABLE t1;
+FLUSH LOGS;
+FOUND 1 /Ignorable event type 164.*/ in binlog_enc.sql
diff --git a/mysql-test/suite/binlog_encryption/mysqlbinlog.test b/mysql-test/suite/binlog_encryption/mysqlbinlog.test
new file mode 100644
index 00000000..108dbd87
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/mysqlbinlog.test
@@ -0,0 +1,24 @@
+source include/have_log_bin.inc;
+source include/have_debug.inc;
+
+let datadir=`select @@datadir`;
+RESET MASTER;
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+REPLACE INTO t1 VALUES (4);
+DROP TABLE t1;
+FLUSH LOGS;
+
+let filename= master-bin.000001;
+let local=$datadir/$filename;
+let remote=--read-from-remote-server --protocol=tcp --host=127.0.0.1 --port=$MASTER_MYPORT -uroot $filename;
+let outfile=$MYSQLTEST_VARDIR/tmp/binlog_enc.sql;
+--error 1
+exec $MYSQL_BINLOG $local > $outfile;
+exec $MYSQL_BINLOG $local --force-read >> $outfile;
+exec $MYSQL_BINLOG $remote >> $outfile;
+--let SEARCH_FILE= $outfile
+--let SEARCH_PATTERN= Ignorable event type 164.*
+--source include/search_pattern_in_file.inc
+remove_file $outfile;
+
diff --git a/mysql-test/suite/binlog_encryption/restart_server.inc b/mysql-test/suite/binlog_encryption/restart_server.inc
new file mode 100644
index 00000000..8f0fe7d8
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/restart_server.inc
@@ -0,0 +1,35 @@
+#
+# We can not use the common include/restart_mysqld.inc or include/rpl_restart_server.inc,
+# because they have hardcoded connection names (master, master1)
+# which are not initiated by rpl_init.inc.
+# This is the relevant and simplified part of the same set of scripts.
+#
+# ==== Usage ====
+#
+# --let $rpl_server_number= N
+# Number to identify the server that needs to reconnect.
+# 1 is the master server, 2 the slave server
+# [--let $rpl_server_parameters= --flag1 --flag2 ...]
+# --source restart_server.inc
+#
+
+--let $_cur_con= $CURRENT_CONNECTION
+
+--connection default
+--enable_reconnect
+
+--connection $_cur_con
+--enable_reconnect
+--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.$rpl_server_number.expect
+
+shutdown_server;
+
+--source include/wait_until_disconnected.inc
+
+--let $_rpl_start_server_command= restart
+if ($rpl_server_parameters)
+{
+ --let $_rpl_start_server_command= restart:$rpl_server_parameters
+}
+--exec echo "$_rpl_start_server_command" > $MYSQLTEST_VARDIR/tmp/mysqld.$rpl_server_number.expect
+--source include/wait_until_connected_again.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_binlog_errors.cnf b/mysql-test/suite/binlog_encryption/rpl_binlog_errors.cnf
new file mode 100644
index 00000000..2d3db66e
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_binlog_errors.cnf
@@ -0,0 +1,7 @@
+!include my.cnf
+
+[mysqld.1]
+max_binlog_size=4096
+
+[mysqld.2]
+skip-slave-start
diff --git a/mysql-test/suite/binlog_encryption/rpl_binlog_errors.result b/mysql-test/suite/binlog_encryption/rpl_binlog_errors.result
new file mode 100644
index 00000000..0c79b079
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_binlog_errors.result
@@ -0,0 +1,286 @@
+include/master-slave.inc
+[connection master]
+#######################################################################
+####################### PART 1: MASTER TESTS ##########################
+#######################################################################
+connection slave;
+include/stop_slave.inc
+connection master;
+call mtr.add_suppression("Can't generate a unique log-filename");
+call mtr.add_suppression("Writing one row to the row-based binary log failed.*");
+call mtr.add_suppression("Error writing file .*");
+call mtr.add_suppression("Could not use master-bin for logging");
+SET @old_debug= @@global.debug_dbug;
+SELECT repeat('x',8192) INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug_46166.data';
+SELECT repeat('x',10) INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug_46166-2.data';
+RESET MASTER;
+###################### TEST #1
+FLUSH LOGS;
+# assert: must show two binlogs
+show binary logs;
+Log_name File_size
+master-bin.000001 #
+master-bin.000002 #
+###################### TEST #2
+RESET MASTER;
+SET @@global.debug_dbug="d,error_unique_log_filename";
+FLUSH LOGS;
+ERROR HY000: Can't generate a unique log-filename master-bin.(1-999)
+
+# assert: must show one binlog
+show binary logs;
+Log_name File_size
+master-bin.000001 #
+SET @@global.debug_dbug=@old_debug;
+RESET MASTER;
+###################### TEST #3
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (a VARCHAR(16384)) Engine=InnoDB;
+CREATE TABLE t4 (a VARCHAR(16384));
+INSERT INTO t1 VALUES (1);
+RESET MASTER;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug_46166.data' INTO TABLE t2;
+# assert: must show two binlog
+show binary logs;
+Log_name File_size
+master-bin.000001 #
+master-bin.000002 #
+SET @@global.debug_dbug=@old_debug;
+DELETE FROM t2;
+RESET MASTER;
+###################### TEST #4
+SET @@global.debug_dbug="d,error_unique_log_filename";
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug_46166.data' INTO TABLE t2;
+ERROR HY000: Can't generate a unique log-filename master-bin.(1-999)
+
+# assert: must show one entry
+SELECT count(*) FROM t2;
+count(*)
+1
+SET @@global.debug_dbug=@old_debug;
+DELETE FROM t2;
+RESET MASTER;
+###################### TEST #5
+SET @@global.debug_dbug="d,error_unique_log_filename";
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug_46166-2.data' INTO TABLE t2;
+# assert: must show one entry
+SELECT count(*) FROM t2;
+count(*)
+1
+SET @@global.debug_dbug=@old_debug;
+DELETE FROM t2;
+RESET MASTER;
+###################### TEST #6
+SET @@global.debug_dbug="d,error_unique_log_filename";
+SET AUTOCOMMIT=0;
+INSERT INTO t2 VALUES ('muse');
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug_46166.data' INTO TABLE t2;
+INSERT INTO t2 VALUES ('muse');
+COMMIT;
+ERROR HY000: Can't generate a unique log-filename master-bin.(1-999)
+
+# assert: must show three entries
+SELECT count(*) FROM t2;
+count(*)
+3
+SET AUTOCOMMIT= 1;
+SET @@global.debug_dbug=@old_debug;
+DELETE FROM t2;
+RESET MASTER;
+###################### TEST #7
+SET @@global.debug_dbug="d,error_unique_log_filename";
+SET @@binlog_annotate_row_events= 0;
+SELECT count(*) FROM t4;
+count(*)
+0
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug_46166.data' INTO TABLE t4;
+ERROR HY000: Can't generate a unique log-filename master-bin.(1-999)
+
+# assert: must show 1 entry
+SELECT count(*) FROM t4;
+count(*)
+1
+### check that the incident event is written to the current log
+SET @@global.debug_dbug=@old_debug;
+include/show_binlog_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000001 # Incident # # #1 (LOST_EVENTS)
+DELETE FROM t4;
+RESET MASTER;
+###################### TEST #8
+SET @@global.debug_dbug="d,error_unique_log_filename";
+# must show 0 entries
+SELECT count(*) FROM t4;
+count(*)
+0
+SELECT count(*) FROM t2;
+count(*)
+0
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug_46166.data' INTO TABLE t4;
+ERROR HY000: Can't generate a unique log-filename master-bin.(1-999)
+
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug_46166.data' INTO TABLE t2;
+ERROR HY000: Can't generate a unique log-filename master-bin.(1-999)
+
+INSERT INTO t2 VALUES ('aaa'), ('bbb'), ('ccc');
+ERROR HY000: Can't generate a unique log-filename master-bin.(1-999)
+
+# INFO: Count(*) Before Offending DELETEs
+# assert: must show 1 entry
+SELECT count(*) FROM t4;
+count(*)
+1
+# assert: must show 4 entries
+SELECT count(*) FROM t2;
+count(*)
+4
+DELETE FROM t4;
+ERROR HY000: Can't generate a unique log-filename master-bin.(1-999)
+
+DELETE FROM t2;
+ERROR HY000: Can't generate a unique log-filename master-bin.(1-999)
+
+# INFO: Count(*) After Offending DELETEs
+# assert: must show zero entries
+SELECT count(*) FROM t4;
+count(*)
+0
+SELECT count(*) FROM t2;
+count(*)
+0
+SET @@global.debug_dbug=@old_debug;
+###################### TEST #9
+SET @@global.debug_dbug="d,error_unique_log_filename";
+SET SQL_LOG_BIN=0;
+INSERT INTO t2 VALUES ('aaa'), ('bbb'), ('ccc'), ('ddd');
+INSERT INTO t4 VALUES ('eee'), ('fff'), ('ggg'), ('hhh');
+# assert: must show four entries
+SELECT count(*) FROM t2;
+count(*)
+4
+SELECT count(*) FROM t4;
+count(*)
+4
+DELETE FROM t2;
+DELETE FROM t4;
+# assert: must show zero entries
+SELECT count(*) FROM t2;
+count(*)
+0
+SELECT count(*) FROM t4;
+count(*)
+0
+SET SQL_LOG_BIN=1;
+SET @@global.debug_dbug=@old_debug;
+###################### TEST #10
+call mtr.add_suppression("MYSQL_BIN_LOG::open failed to sync the index file.");
+call mtr.add_suppression("Could not use .*");
+RESET MASTER;
+SHOW WARNINGS;
+Level Code Message
+SET @@global.debug_dbug="d,fault_injection_registering_index";
+FLUSH LOGS;
+ERROR HY000: Can't open file: 'master-bin.000002' (errno: 1 "Operation not permitted")
+SET @@global.debug_dbug=@old_debug;
+SHOW BINARY LOGS;
+ERROR HY000: You are not using binary logging
+CREATE TABLE t5 (a INT);
+INSERT INTO t4 VALUES ('bbbbb');
+INSERT INTO t2 VALUES ('aaaaa');
+DELETE FROM t4;
+DELETE FROM t2;
+DROP TABLE t5;
+flush tables;
+###################### TEST #11
+include/rpl_restart_server.inc [server_number=1]
+SET @@global.debug_dbug="d,fault_injection_openning_index";
+FLUSH LOGS;
+ERROR HY000: Can't open file: 'master-bin.index' (errno: 1 "Operation not permitted")
+SET @@global.debug_dbug=@old_debug;
+RESET MASTER;
+ERROR HY000: Binlog closed, cannot RESET MASTER
+CREATE TABLE t5 (a INT);
+INSERT INTO t4 VALUES ('bbbbb');
+INSERT INTO t2 VALUES ('aaaaa');
+DELETE FROM t4;
+DELETE FROM t2;
+DROP TABLE t5;
+flush tables;
+include/rpl_restart_server.inc [server_number=1]
+###################### TEST #12
+SET @@global.debug_dbug="d,fault_injection_new_file_rotate_event";
+FLUSH LOGS;
+ERROR HY000: Can't open file: 'master-bin' (errno: 2 "No such file or directory")
+SET @@global.debug_dbug=@old_debug;
+RESET MASTER;
+ERROR HY000: Binlog closed, cannot RESET MASTER
+CREATE TABLE t5 (a INT);
+INSERT INTO t4 VALUES ('bbbbb');
+INSERT INTO t2 VALUES ('aaaaa');
+DELETE FROM t4;
+DELETE FROM t2;
+DROP TABLE t5;
+flush tables;
+include/rpl_restart_server.inc [server_number=1]
+DROP TABLE t1, t2, t4;
+RESET MASTER;
+connection slave;
+include/start_slave.inc
+connection master;
+#######################################################################
+####################### PART 2: SLAVE TESTS ###########################
+#######################################################################
+include/rpl_reset.inc
+connection slave;
+include/stop_slave.inc
+CHANGE MASTER TO MASTER_USE_GTID=NO;
+include/start_slave.inc
+call mtr.add_suppression("Slave I/O: Relay log write failure: could not queue event from master.*");
+call mtr.add_suppression("Error writing file .*");
+call mtr.add_suppression("Could not use .*");
+call mtr.add_suppression("MYSQL_BIN_LOG::open failed to sync the index file.");
+call mtr.add_suppression("Can't generate a unique log-filename .*");
+###################### TEST #13
+SET @saved_debug=@@global.debug_dbug;
+include/stop_slave.inc
+SET @@global.debug_dbug="d,error_unique_log_filename";
+START SLAVE io_thread;
+include/wait_for_slave_io_error.inc [errno=1595]
+Last_IO_Error = 'Relay log write failure: could not queue event from master'
+SET @@global.debug_dbug=@saved_debug;
+include/rpl_restart_server.inc [server_number=2]
+###################### TEST #14
+SET @saved_debug=@@global.debug_dbug;
+include/stop_slave.inc
+SET @@global.debug_dbug="d,fault_injection_new_file_rotate_event";
+START SLAVE io_thread;
+include/wait_for_slave_io_error.inc [errno=1595]
+Last_IO_Error = 'Relay log write failure: could not queue event from master'
+SET @@global.debug_dbug=@saved_debug;
+include/rpl_restart_server.inc [server_number=2]
+###################### TEST #15
+SET @saved_debug=@@global.debug_dbug;
+include/stop_slave.inc
+SET @@global.debug_dbug="d,fault_injection_registering_index";
+START SLAVE io_thread;
+include/wait_for_slave_io_error.inc [errno=1595]
+Last_IO_Error = 'Relay log write failure: could not queue event from master'
+SET @@global.debug_dbug=@saved_debug;
+include/rpl_restart_server.inc [server_number=2]
+###################### TEST #16
+SET @saved_debug=@@global.debug_dbug;
+include/stop_slave.inc
+SET @@global.debug_dbug="d,fault_injection_openning_index";
+START SLAVE io_thread;
+include/wait_for_slave_io_error.inc [errno=1595]
+Last_IO_Error = 'Relay log write failure: could not queue event from master'
+SET @@global.debug_dbug=@saved_debug;
+include/rpl_restart_server.inc [server_number=2]
+include/stop_slave_sql.inc
+Warnings:
+Note 1255 Slave already has been stopped
+RESET SLAVE;
+Warnings:
+Note 4190 RESET SLAVE is implicitly changing the value of 'Using_Gtid' from 'No' to 'Slave_Pos'
+RESET MASTER;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_binlog_errors.test b/mysql-test/suite/binlog_encryption/rpl_binlog_errors.test
new file mode 100644
index 00000000..25849c11
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_binlog_errors.test
@@ -0,0 +1,2 @@
+--let $binlog_limit= 5,1
+--source suite/rpl/t/rpl_binlog_errors.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_cant_read_event_incident.result b/mysql-test/suite/binlog_encryption/rpl_cant_read_event_incident.result
new file mode 100644
index 00000000..86659816
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_cant_read_event_incident.result
@@ -0,0 +1,33 @@
+include/master-slave.inc
+[connection master]
+connection slave;
+include/stop_slave.inc
+CHANGE MASTER TO MASTER_USE_GTID=NO;
+include/start_slave.inc
+include/stop_slave.inc
+connection master;
+call mtr.add_suppression("Error in Log_event::read_log_event()");
+include/rpl_stop_server.inc [server_number=1]
+include/rpl_start_server.inc [server_number=1]
+show binlog events;
+ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Wrong offset or I/O error
+connection slave;
+call mtr.add_suppression("Slave I/O: Got fatal error 1236 from master when reading data from binary log");
+include/reset_slave.inc
+Warnings:
+Note 4190 RESET SLAVE is implicitly changing the value of 'Using_Gtid' from 'No' to 'Slave_Pos'
+start slave;
+include/wait_for_slave_param.inc [Last_IO_Errno]
+Last_IO_Errno = '1236'
+Last_IO_Error = 'Got fatal error 1236 from master when reading data from binary log: 'binlog truncated in the middle of event; consider out of disk space on master; the first event '.' at XXX, the last event read from 'master-bin.000001' at XXX, the last byte read from 'master-bin.000001' at XXX.''
+connection master;
+reset master;
+connection slave;
+stop slave;
+reset slave;
+Warnings:
+Note 4190 RESET SLAVE is implicitly changing the value of 'Using_Gtid' from 'No' to 'Slave_Pos'
+drop table if exists t;
+reset master;
+End of the tests
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_cant_read_event_incident.test b/mysql-test/suite/binlog_encryption/rpl_cant_read_event_incident.test
new file mode 100644
index 00000000..406af58c
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_cant_read_event_incident.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_cant_read_event_incident.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_checksum.cnf b/mysql-test/suite/binlog_encryption/rpl_checksum.cnf
new file mode 100644
index 00000000..9d7ada8c
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_checksum.cnf
@@ -0,0 +1,10 @@
+!include my.cnf
+
+[mysqld.1]
+binlog-checksum=CRC32
+
+[mysqld.2]
+binlog-checksum=CRC32
+plugin-load-add= @ENV.FILE_KEY_MANAGEMENT_SO
+loose-file-key-management-filename=@ENV.MYSQLTEST_VARDIR/std_data/keys.txt
+encrypt-binlog
diff --git a/mysql-test/suite/binlog_encryption/rpl_checksum.result b/mysql-test/suite/binlog_encryption/rpl_checksum.result
new file mode 100644
index 00000000..0b894e05
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_checksum.result
@@ -0,0 +1,206 @@
+include/master-slave.inc
+[connection master]
+connection slave;
+include/stop_slave.inc
+CHANGE MASTER TO MASTER_USE_GTID=NO;
+include/start_slave.inc
+connection master;
+call mtr.add_suppression('Slave can not handle replication events with the checksum that master is configured to log');
+call mtr.add_suppression('Replication event checksum verification failed');
+call mtr.add_suppression('Relay log write failure: could not queue event from master');
+call mtr.add_suppression('Master is configured to log replication events with checksum, but will not send such events to slaves that cannot process them');
+connection master;
+set @master_save_binlog_checksum= @@global.binlog_checksum;
+set @save_master_verify_checksum = @@global.master_verify_checksum;
+select @@global.binlog_checksum as 'must be CRC32 because of the command line option';
+must be CRC32 because of the command line option
+CRC32
+select @@session.binlog_checksum as 'no session var';
+ERROR HY000: Variable 'binlog_checksum' is a GLOBAL variable
+select @@global.master_verify_checksum as 'must be zero because of default';
+must be zero because of default
+0
+select @@session.master_verify_checksum as 'no session var';
+ERROR HY000: Variable 'master_verify_checksum' is a GLOBAL variable
+connection slave;
+set @slave_save_binlog_checksum= @@global.binlog_checksum;
+set @save_slave_sql_verify_checksum = @@global.slave_sql_verify_checksum;
+select @@global.slave_sql_verify_checksum as 'must be one because of default';
+must be one because of default
+1
+select @@session.slave_sql_verify_checksum as 'no session var';
+ERROR HY000: Variable 'slave_sql_verify_checksum' is a GLOBAL variable
+connection master;
+show binary logs;
+Log_name File_size
+master-bin.000001 #
+set @@global.binlog_checksum = NONE;
+select @@global.binlog_checksum;
+@@global.binlog_checksum
+NONE
+*** must be rotations seen ***
+show binary logs;
+Log_name File_size
+master-bin.000001 #
+master-bin.000002 #
+set @@global.binlog_checksum = default;
+select @@global.binlog_checksum;
+@@global.binlog_checksum
+CRC32
+set @@global.binlog_checksum = CRC32;
+select @@global.binlog_checksum;
+@@global.binlog_checksum
+CRC32
+set @@global.binlog_checksum = CRC32;
+set @@global.master_verify_checksum = 0;
+set @@global.master_verify_checksum = default;
+set @@global.binlog_checksum = ADLER32;
+ERROR 42000: Variable 'binlog_checksum' can't be set to the value of 'ADLER32'
+set @@global.master_verify_checksum = 2;
+ERROR 42000: Variable 'master_verify_checksum' can't be set to the value of '2'
+connection slave;
+set @@global.slave_sql_verify_checksum = 0;
+set @@global.slave_sql_verify_checksum = default;
+set @@global.slave_sql_verify_checksum = 2;
+ERROR 42000: Variable 'slave_sql_verify_checksum' can't be set to the value of '2'
+connection master;
+set @@global.binlog_checksum = NONE;
+create table t1 (a int);
+flush logs;
+flush logs;
+flush logs;
+connection slave;
+flush logs;
+flush logs;
+flush logs;
+select count(*) as zero from t1;
+zero
+0
+include/stop_slave.inc
+connection master;
+set @@global.binlog_checksum = CRC32;
+insert into t1 values (1) /* will not be applied on slave due to simulation */;
+connection slave;
+set @saved_dbug = @@global.debug_dbug;
+set @@global.debug_dbug='d,simulate_slave_unaware_checksum';
+start slave;
+include/wait_for_slave_io_error.inc [errno=1236]
+Last_IO_Error = 'Got fatal error 1236 from master when reading data from binary log: 'Slave can not handle replication events with the checksum that master is configured to log; the first event 'master-bin.000009' at 411, the last event read from 'master-bin.000010' at 4, the last byte read from 'master-bin.000010' at 256.''
+select count(*) as zero from t1;
+zero
+0
+set @@global.debug_dbug = @saved_dbug;
+connection slave;
+include/start_slave.inc
+connection master;
+set @@global.master_verify_checksum = 1;
+set @save_dbug = @@session.debug_dbug;
+set @@session.debug_dbug='d,simulate_checksum_test_failure';
+show binlog events;
+ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Wrong offset or I/O error
+SET debug_dbug= @save_dbug;
+set @@global.master_verify_checksum = default;
+connection slave;
+connection slave;
+include/stop_slave.inc
+connection master;
+create table t2 (a int);
+connection slave;
+set @saved_dbug = @@global.debug_dbug;
+set @@global.debug_dbug='d,simulate_checksum_test_failure';
+start slave io_thread;
+include/wait_for_slave_io_error.inc [errno=1595,1913]
+set @@global.debug_dbug = @saved_dbug;
+start slave io_thread;
+include/wait_for_slave_param.inc [Read_Master_Log_Pos]
+set @@global.slave_sql_verify_checksum = 1;
+set @@global.debug_dbug='d,simulate_checksum_test_failure';
+start slave sql_thread;
+include/wait_for_slave_sql_error.inc [errno=1593]
+Last_SQL_Error = 'Error initializing relay log position: I/O error reading event at position 4'
+set @@global.debug_dbug = @saved_dbug;
+include/start_slave.inc
+connection master;
+connection slave;
+select count(*) as 'must be zero' from t2;
+must be zero
+0
+connection slave;
+stop slave;
+include/reset_slave.inc
+Warnings:
+Note 4190 RESET SLAVE is implicitly changing the value of 'Using_Gtid' from 'No' to 'Slave_Pos'
+set @@global.binlog_checksum= IF(floor((rand()*1000)%2), "CRC32", "NONE");
+flush logs;
+connection master;
+set @@global.binlog_checksum= CRC32;
+reset master;
+flush logs;
+create table t3 (a int, b char(5));
+connection slave;
+include/start_slave.inc
+connection master;
+connection slave;
+select count(*) as 'must be zero' from t3;
+must be zero
+0
+include/stop_slave.inc
+change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root';
+connection master;
+flush logs;
+reset master;
+insert into t3 value (1, @@global.binlog_checksum);
+connection slave;
+include/start_slave.inc
+flush logs;
+connection master;
+connection slave;
+select count(*) as 'must be one' from t3;
+must be one
+1
+connection master;
+set @@global.binlog_checksum= IF(floor((rand()*1000)%2), "CRC32", "NONE");
+insert into t3 value (1, @@global.binlog_checksum);
+connection slave;
+connection master;
+drop table t1, t2, t3;
+set @@global.binlog_checksum = @master_save_binlog_checksum;
+set @@global.master_verify_checksum = @save_master_verify_checksum;
+connection slave;
+*** Bug#59123 / MDEV-5799: INCIDENT_EVENT checksum written to error log as garbage characters ***
+connection master;
+CREATE TABLE t4 (a INT PRIMARY KEY);
+INSERT INTO t4 VALUES (1);
+SET sql_log_bin=0;
+CALL mtr.add_suppression("\\[ERROR\\] Can't generate a unique log-filename");
+SET sql_log_bin=1;
+SET @old_dbug= @@GLOBAL.debug_dbug;
+SET debug_dbug= '+d,binlog_inject_new_name_error';
+FLUSH LOGS;
+ERROR HY000: Can't generate a unique log-filename master-bin.(1-999)
+
+SET debug_dbug= @old_dbug;
+INSERT INTO t4 VALUES (2);
+connection slave;
+include/wait_for_slave_sql_error.inc [errno=1590]
+Last_SQL_Error = 'The incident LOST_EVENTS occurred on the master. Message: error writing to the binary log'
+FOUND 1 /Slave SQL: The incident LOST_EVENTS occurred on the master\. Message: error writing to the binary log, Internal MariaDB error code: 1590/ in mysqld.2.err
+SELECT * FROM t4 ORDER BY a;
+a
+1
+STOP SLAVE IO_THREAD;
+SET sql_slave_skip_counter= 1;
+include/start_slave.inc
+connection master;
+connection slave;
+SELECT * FROM t4 ORDER BY a;
+a
+1
+2
+connection slave;
+set @@global.binlog_checksum = @slave_save_binlog_checksum;
+set @@global.slave_sql_verify_checksum = @save_slave_sql_verify_checksum;
+End of tests
+connection master;
+DROP TABLE t4;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_checksum.test b/mysql-test/suite/binlog_encryption/rpl_checksum.test
new file mode 100644
index 00000000..a2abd019
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_checksum.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_checksum.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_checksum_cache.result b/mysql-test/suite/binlog_encryption/rpl_checksum_cache.result
new file mode 100644
index 00000000..9508e94e
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_checksum_cache.result
@@ -0,0 +1,119 @@
+include/master-slave.inc
+[connection master]
+call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave. Statement: insert into t2 set data=repeat.*'a', @act_size.*");
+call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave. Statement: insert into t1 values.* NAME_CONST.*'n',.*, @data .*");
+set @save_binlog_cache_size = @@global.binlog_cache_size;
+set @save_binlog_checksum = @@global.binlog_checksum;
+set @save_master_verify_checksum = @@global.master_verify_checksum;
+set @@global.binlog_cache_size = 4096;
+set @@global.binlog_checksum = CRC32;
+set @@global.master_verify_checksum = 1;
+include/stop_slave.inc
+include/start_slave.inc
+flush status;
+show status like "binlog_cache_use";
+Variable_name Value
+Binlog_cache_use 0
+show status like "binlog_cache_disk_use";
+Variable_name Value
+Binlog_cache_disk_use 0
+drop table if exists t1;
+create table t1 (a int PRIMARY KEY, b CHAR(32)) engine=innodb;
+create procedure test.p_init (n int, size int)
+begin
+while n > 0 do
+select round(RAND() * size) into @act_size;
+set @data = repeat('a', @act_size);
+insert into t1 values(n, @data );
+set n= n-1;
+end while;
+end|
+begin;
+call test.p_init(4000, 32);
+commit;
+show status like "binlog_cache_use";
+Variable_name Value
+Binlog_cache_use 1
+*** binlog_cache_disk_use must be non-zero ***
+show status like "binlog_cache_disk_use";
+Variable_name Value
+Binlog_cache_disk_use 1
+include/diff_tables.inc [master:test.t1, slave:test.t1]
+begin;
+delete from t1;
+commit;
+flush status;
+create table t2(a int auto_increment primary key, data VARCHAR(12288)) ENGINE=Innodb;
+show status like "binlog_cache_use";
+Variable_name Value
+Binlog_cache_use 1
+*** binlog_cache_disk_use must be non-zero ***
+show status like "binlog_cache_disk_use";
+Variable_name Value
+Binlog_cache_disk_use 1
+include/diff_tables.inc [master:test.t2, slave:test.t2]
+begin;
+delete from t2;
+commit;
+flush status;
+create table t3(a int auto_increment primary key, data VARCHAR(8192)) engine=innodb;
+show status like "binlog_cache_use";
+Variable_name Value
+Binlog_cache_use 1
+*** binlog_cache_disk_use must be non-zero ***
+show status like "binlog_cache_disk_use";
+Variable_name Value
+Binlog_cache_disk_use 1
+include/diff_tables.inc [master:test.t3, slave:test.t3]
+begin;
+delete from t3;
+commit;
+flush status;
+create procedure test.p1 (n int)
+begin
+while n > 0 do
+case (select (round(rand()*100) % 3) + 1)
+when 1 then
+select round(RAND() * 32) into @act_size;
+set @data = repeat('a', @act_size);
+insert into t1 values(n, @data);
+when 2 then
+begin
+select round(8192 + RAND() * 4096) into @act_size;
+insert into t2 set data=repeat('a', @act_size);
+end;
+when 3 then
+begin
+select round(3686.4000 + RAND() * 819.2000) into @act_size;
+insert into t3 set data= repeat('a', @act_size);
+end;
+end case;
+set n= n-1;
+end while;
+end|
+set autocommit= 0;
+begin;
+call test.p1(1000);
+commit;
+show status like "binlog_cache_use";
+Variable_name Value
+Binlog_cache_use 1
+*** binlog_cache_disk_use must be non-zero ***
+show status like "binlog_cache_disk_use";
+Variable_name Value
+Binlog_cache_disk_use 1
+include/diff_tables.inc [master:test.t1, slave:test.t1]
+include/diff_tables.inc [master:test.t2, slave:test.t2]
+include/diff_tables.inc [master:test.t3, slave:test.t3]
+begin;
+delete from t1;
+delete from t2;
+delete from t3;
+commit;
+drop table t1, t2, t3;
+set @@global.binlog_cache_size = @save_binlog_cache_size;
+set @@global.binlog_checksum = @save_binlog_checksum;
+set @@global.master_verify_checksum = @save_master_verify_checksum;
+drop procedure test.p_init;
+drop procedure test.p1;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_checksum_cache.test b/mysql-test/suite/binlog_encryption/rpl_checksum_cache.test
new file mode 100644
index 00000000..56fb2be0
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_checksum_cache.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_checksum_cache.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_corruption.cnf b/mysql-test/suite/binlog_encryption/rpl_corruption.cnf
new file mode 100644
index 00000000..7f7d0eeb
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_corruption.cnf
@@ -0,0 +1,9 @@
+!include my.cnf
+
+[mysqld.1]
+binlog-checksum=CRC32
+master-verify-checksum=1
+
+[mysqld.2]
+binlog-checksum=CRC32
+slave-sql-verify-checksum=1
diff --git a/mysql-test/suite/binlog_encryption/rpl_corruption.result b/mysql-test/suite/binlog_encryption/rpl_corruption.result
new file mode 100644
index 00000000..7c60e15a
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_corruption.result
@@ -0,0 +1,67 @@
+include/master-slave.inc
+[connection master]
+connection slave;
+include/stop_slave.inc
+CHANGE MASTER TO MASTER_USE_GTID=NO;
+include/start_slave.inc
+connection master;
+call mtr.add_suppression('Found invalid event in binary log');
+call mtr.add_suppression('Slave I/O: Relay log write failure: could not queue event from master');
+call mtr.add_suppression('event read from binlog did not pass crc check');
+call mtr.add_suppression('Replication event checksum verification failed');
+call mtr.add_suppression('Event crc check failed! Most likely there is event corruption');
+call mtr.add_suppression('Slave SQL: Error initializing relay log position: I/O error reading event at position .*, error.* 1593');
+SET @old_master_verify_checksum = @@master_verify_checksum;
+# 1. Creating test table/data and set corruption position for testing
+connection master;
+* insert/update/delete rows in table t1 *
+CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10), c VARCHAR(100));
+include/stop_slave.inc
+# 2. Corruption in master binlog and SHOW BINLOG EVENTS
+SET @saved_dbug = @@global.debug_dbug;
+SET @@global.debug_dbug="d,corrupt_read_log_event_char";
+SHOW BINLOG EVENTS;
+ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Wrong offset or I/O error
+SET @@global.debug_dbug=@saved_dbug;
+# 3. Master read a corrupted event from binlog and send the error to slave
+SET @@global.debug_dbug="d,corrupt_read_log_event2_set";
+connection slave;
+START SLAVE IO_THREAD;
+include/wait_for_slave_io_error.inc [errno=1236]
+connection master;
+SET @@global.debug_dbug=@saved_dbug;
+# 4. Master read a corrupted event from binlog and send it to slave
+connection master;
+SET GLOBAL master_verify_checksum=0;
+SET @@global.debug_dbug="d,corrupt_read_log_event2_set";
+connection slave;
+START SLAVE IO_THREAD;
+include/wait_for_slave_io_error.inc [errno=1595,1743]
+connection master;
+SET @@global.debug_dbug=@saved_dbug;
+SET GLOBAL master_verify_checksum=1;
+# 5. Slave. Corruption in network
+connection slave;
+SET @saved_dbug_slave = @@GLOBAL.debug_dbug;
+SET @@global.debug_dbug="d,corrupt_queue_event";
+START SLAVE IO_THREAD;
+include/wait_for_slave_io_error.inc [errno=1595,1743]
+SET @@global.debug_dbug=@saved_dbug_slave;
+# 6. Slave. Corruption in relay log
+SET @@global.debug_dbug="d,corrupt_read_log_event_char";
+START SLAVE SQL_THREAD;
+include/wait_for_slave_sql_error.inc [errno=1593]
+SET @@global.debug_dbug=@saved_dbug_slave;
+# 7. Seek diff for tables on master and slave
+connection slave;
+include/start_slave.inc
+connection master;
+connection slave;
+include/diff_tables.inc [master:test.t1, slave:test.t1]
+# 8. Clean up
+connection master;
+set @@global.debug_dbug = @saved_dbug;
+SET GLOBAL master_verify_checksum = @old_master_verify_checksum;
+DROP TABLE t1;
+connection slave;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_corruption.test b/mysql-test/suite/binlog_encryption/rpl_corruption.test
new file mode 100644
index 00000000..f6ba2944
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_corruption.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_corruption.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_gtid_basic.cnf b/mysql-test/suite/binlog_encryption/rpl_gtid_basic.cnf
new file mode 100644
index 00000000..ae47ef7a
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_gtid_basic.cnf
@@ -0,0 +1,24 @@
+!include my.cnf
+
+[mysqld.1]
+log-slave-updates
+
+[mysqld.2]
+init-rpl-role= slave
+master-retry-count= 10
+skip-slave-start
+
+[mysqld.3]
+log-slave-updates
+innodb
+
+[mysqld.4]
+log-slave-updates
+innodb
+
+[ENV]
+SERVER_MYPORT_3= @mysqld.3.port
+SERVER_MYSOCK_3= @mysqld.3.socket
+
+SERVER_MYPORT_4= @mysqld.4.port
+SERVER_MYSOCK_4= @mysqld.4.socket
diff --git a/mysql-test/suite/binlog_encryption/rpl_gtid_basic.combinations b/mysql-test/suite/binlog_encryption/rpl_gtid_basic.combinations
new file mode 100644
index 00000000..710c53d0
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_gtid_basic.combinations
@@ -0,0 +1,6 @@
+[cmpr]
+log-bin-compress=1
+log-bin-compress-min-len=10
+
+[ncmpr]
+log-bin-compress=0
diff --git a/mysql-test/suite/binlog_encryption/rpl_gtid_basic.result b/mysql-test/suite/binlog_encryption/rpl_gtid_basic.result
new file mode 100644
index 00000000..2bdfe0b1
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_gtid_basic.result
@@ -0,0 +1,646 @@
+include/rpl_init.inc [topology=1->2->3->4]
+connection server_1;
+*** GTID position should be empty here ***
+SELECT BINLOG_GTID_POS('<BINLOG_FILE>',<BINLOG_POS>);
+BINLOG_GTID_POS('<BINLOG_FILE>',<BINLOG_POS>)
+
+CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10)) ENGINE=MyISAM;
+CREATE TABLE t2 (a INT PRIMARY KEY, b VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1, "m1");
+INSERT INTO t1 VALUES (2, "m2"), (3, "m3"), (4, "m4");
+INSERT INTO t2 VALUES (1, "i1");
+BEGIN;
+INSERT INTO t2 VALUES (2, "i2"), (3, "i3");
+INSERT INTO t2 VALUES (4, "i4");
+COMMIT;
+*** GTID position should be non-empty here ***
+SELECT BINLOG_GTID_POS('<BINLOG_FILE>',<BINLOG_POS>);
+BINLOG_GTID_POS('<BINLOG_FILE>',<BINLOG_POS>)
+<GTID_POS_SERVER_1>
+connection server_2;
+*** GTID position should be the same as on server_1 ***
+SELECT BINLOG_GTID_POS('<BINLOG_FILE>',<BINLOG_POS>);
+BINLOG_GTID_POS('<BINLOG_FILE>',<BINLOG_POS>)
+<GTID_POS_SERVER_1>
+SELECT * FROM t1 ORDER BY a;
+a b
+1 m1
+2 m2
+3 m3
+4 m4
+SELECT * FROM t2 ORDER BY a;
+a b
+1 i1
+2 i2
+3 i3
+4 i4
+connection server_3;
+SELECT * FROM t1 ORDER BY a;
+a b
+1 m1
+2 m2
+3 m3
+4 m4
+SELECT * FROM t2 ORDER BY a;
+a b
+1 i1
+2 i2
+3 i3
+4 i4
+connection server_4;
+SELECT * FROM t1 ORDER BY a;
+a b
+1 m1
+2 m2
+3 m3
+4 m4
+SELECT * FROM t2 ORDER BY a;
+a b
+1 i1
+2 i2
+3 i3
+4 i4
+*** Now take out D, let it fall behind a bit, and then test re-attaching it to A ***
+connection server_4;
+include/stop_slave.inc
+connection server_1;
+INSERT INTO t1 VALUES (5, "m1a");
+INSERT INTO t2 VALUES (5, "i1a");
+connection server_4;
+CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT,
+MASTER_USE_GTID=CURRENT_POS;
+Warnings:
+Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
+include/start_slave.inc
+SELECT * FROM t1 ORDER BY a;
+a b
+1 m1
+2 m2
+3 m3
+4 m4
+5 m1a
+SELECT * FROM t2 ORDER BY a;
+a b
+1 i1
+2 i2
+3 i3
+4 i4
+5 i1a
+*** Now move B to D (C is still replicating from B) ***
+connection server_2;
+include/stop_slave.inc
+CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_4,
+MASTER_USE_GTID=CURRENT_POS;
+Warnings:
+Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
+include/start_slave.inc
+connection server_4;
+UPDATE t2 SET b="j1a" WHERE a=5;
+connection server_2;
+SELECT * FROM t1 ORDER BY a;
+a b
+1 m1
+2 m2
+3 m3
+4 m4
+5 m1a
+SELECT * FROM t2 ORDER BY a;
+a b
+1 i1
+2 i2
+3 i3
+4 i4
+5 j1a
+*** Now move C to D, after letting it fall a little behind ***
+connection server_3;
+include/stop_slave.inc
+connection server_1;
+INSERT INTO t2 VALUES (6, "i6b");
+INSERT INTO t2 VALUES (7, "i7b");
+include/save_master_gtid.inc
+connection server_3;
+CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_4,
+MASTER_USE_GTID=CURRENT_POS;
+Warnings:
+Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
+include/start_slave.inc
+include/sync_with_master_gtid.inc
+SELECT * FROM t2 ORDER BY a;
+a b
+1 i1
+2 i2
+3 i3
+4 i4
+5 j1a
+6 i6b
+7 i7b
+*** Now change everything back to what it was, to make rpl_end.inc happy
+connection server_2;
+include/sync_with_master_gtid.inc
+include/stop_slave.inc
+CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_MYPORT;
+include/start_slave.inc
+include/wait_for_slave_to_start.inc
+connection server_3;
+include/stop_slave.inc
+CHANGE MASTER TO master_host = '127.0.0.1', master_port = SLAVE_MYPORT;
+include/start_slave.inc
+include/sync_with_master_gtid.inc
+connection server_4;
+include/stop_slave.inc
+CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_3;
+include/start_slave.inc
+connection server_1;
+DROP TABLE t1,t2;
+include/save_master_gtid.inc
+*** A few more checks for BINLOG_GTID_POS function ***
+SELECT BINLOG_GTID_POS();
+ERROR 42000: Incorrect parameter count in the call to native function 'BINLOG_GTID_POS'
+SELECT BINLOG_GTID_POS('a');
+ERROR 42000: Incorrect parameter count in the call to native function 'BINLOG_GTID_POS'
+SELECT BINLOG_GTID_POS('a',1,NULL);
+ERROR 42000: Incorrect parameter count in the call to native function 'BINLOG_GTID_POS'
+SELECT BINLOG_GTID_POS(1,'a');
+BINLOG_GTID_POS(1,'a')
+NULL
+Warnings:
+Warning 1292 Truncated incorrect INTEGER value: 'a'
+SELECT BINLOG_GTID_POS(NULL,NULL);
+BINLOG_GTID_POS(NULL,NULL)
+NULL
+SELECT BINLOG_GTID_POS('',1);
+BINLOG_GTID_POS('',1)
+
+SELECT BINLOG_GTID_POS('a',1);
+BINLOG_GTID_POS('a',1)
+NULL
+SELECT BINLOG_GTID_POS('master-bin.000001',-1);
+BINLOG_GTID_POS('master-bin.000001',-1)
+NULL
+SELECT BINLOG_GTID_POS('master-bin.000001',0);
+BINLOG_GTID_POS('master-bin.000001',0)
+
+SELECT BINLOG_GTID_POS('master-bin.000001',18446744073709551615);
+BINLOG_GTID_POS('master-bin.000001',18446744073709551615)
+NULL
+SELECT BINLOG_GTID_POS('master-bin.000001',18446744073709551616);
+BINLOG_GTID_POS('master-bin.000001',18446744073709551616)
+NULL
+Warnings:
+Warning 1916 Got overflow when converting '18446744073709551616' to INT. Value truncated
+*** Some tests of @@GLOBAL.gtid_binlog_state ***
+connection server_2;
+include/sync_with_master_gtid.inc
+include/stop_slave.inc
+connection server_1;
+SET @old_state= @@GLOBAL.gtid_binlog_state;
+SET GLOBAL gtid_binlog_state = '';
+ERROR HY000: This operation is not allowed if any GTID has been logged to the binary log. Run RESET MASTER first to erase the log
+RESET MASTER;
+SET GLOBAL gtid_binlog_state = '';
+FLUSH LOGS;
+show binary logs;
+Log_name File_size
+master-bin.000001 #
+master-bin.000002 #
+SET GLOBAL gtid_binlog_state = '0-1-10,1-2-20,0-3-30';
+show binary logs;
+Log_name File_size
+master-bin.000001 #
+include/show_binlog_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000001 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
+master-bin.000001 # Start_encryption # #
+master-bin.000001 # Gtid_list # # [#-#-#]
+master-bin.000001 # Binlog_checkpoint # # master-bin.000001
+SET GLOBAL gtid_binlog_state = @old_state;
+ERROR HY000: This operation is not allowed if any GTID has been logged to the binary log. Run RESET MASTER first to erase the log
+RESET MASTER;
+SET GLOBAL gtid_binlog_state = @old_state;
+CREATE TABLE t1 (a INT PRIMARY KEY);
+SET gtid_seq_no=100;
+INSERT INTO t1 VALUES (1);
+include/save_master_gtid.inc
+connection server_2;
+include/start_slave.inc
+include/sync_with_master_gtid.inc
+SELECT * FROM t1;
+a
+1
+Gtid_IO_Pos = '0-1-100'
+*** Test @@LAST_GTID and MASTER_GTID_WAIT() ***
+connection server_1;
+DROP TABLE t1;
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+connection server_2;
+include/stop_slave.inc
+connect m1,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+SELECT @@last_gtid;
+@@last_gtid
+
+SET gtid_seq_no=110;
+SELECT @@last_gtid;
+@@last_gtid
+
+BEGIN;
+SELECT @@last_gtid;
+@@last_gtid
+
+INSERT INTO t1 VALUES (2);
+SELECT @@last_gtid;
+@@last_gtid
+
+COMMIT;
+SELECT @@last_gtid;
+@@last_gtid
+0-1-110
+connect s1,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+SET @pos= '0-1-110';
+SELECT master_gtid_wait(NULL);
+master_gtid_wait(NULL)
+NULL
+SELECT master_gtid_wait('', NULL);
+master_gtid_wait('', NULL)
+0
+SHOW STATUS LIKE 'Master_gtid_wait_count';
+Variable_name Value
+Master_gtid_wait_count 1
+SHOW STATUS LIKE 'Master_gtid_wait_timeouts';
+Variable_name Value
+Master_gtid_wait_timeouts 0
+SHOW STATUS LIKE 'Master_gtid_wait_time';
+Variable_name Value
+Master_gtid_wait_time 0
+SELECT master_gtid_wait(@pos, 0.5);
+master_gtid_wait(@pos, 0.5)
+-1
+SELECT * FROM t1 ORDER BY a;
+a
+SELECT master_gtid_wait(@pos);
+connection server_2;
+include/start_slave.inc
+connection s1;
+master_gtid_wait(@pos)
+0
+SELECT * FROM t1 ORDER BY a;
+a
+2
+include/stop_slave.inc
+connection server_1;
+SET gtid_domain_id= 1;
+INSERT INTO t1 VALUES (3);
+connection s1;
+SET @pos= 'POS';
+SELECT master_gtid_wait(@pos, 0);
+master_gtid_wait(@pos, 0)
+-1
+SELECT * FROM t1 WHERE a >= 3;
+a
+SELECT master_gtid_wait(@pos, -1);
+connection server_2;
+include/start_slave.inc
+connection s1;
+master_gtid_wait(@pos, -1)
+0
+SELECT * FROM t1 WHERE a >= 3;
+a
+3
+SELECT master_gtid_wait('1-1-1', 0);
+master_gtid_wait('1-1-1', 0)
+0
+connection s1;
+SELECT master_gtid_wait('2-1-1,1-1-4,0-1-110');
+connect s2,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+SELECT master_gtid_wait('0-1-1000', 0.5);
+connect s3,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+SELECT master_gtid_wait('0-1-2000');
+connect s4,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+SELECT master_gtid_wait('2-1-10');
+connect s5,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+SELECT master_gtid_wait('2-1-6', 1);
+connect s6,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+SELECT master_gtid_wait('2-1-5');
+connect s7,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+SELECT master_gtid_wait('2-1-10');
+connect s8,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+SELECT master_gtid_wait('2-1-5,1-1-4,0-1-110');
+connect s9,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+SELECT master_gtid_wait('2-1-2');
+connection server_2;
+SHOW STATUS LIKE 'Master_gtid_wait_timeouts';
+Variable_name Value
+Master_gtid_wait_timeouts 0
+SHOW STATUS LIKE 'Master_gtid_wait_count';
+Variable_name Value
+Master_gtid_wait_count 3
+SELECT master_gtid_wait('1-1-1');
+master_gtid_wait('1-1-1')
+0
+SHOW STATUS LIKE 'Master_gtid_wait_timeouts';
+Variable_name Value
+Master_gtid_wait_timeouts 0
+SHOW STATUS LIKE 'Master_gtid_wait_count';
+Variable_name Value
+Master_gtid_wait_count 4
+SET @a= MASTER_GTID_WAIT_TIME;
+SELECT IF(@a <= 100*1000*1000, "OK", CONCAT("Error: wait time ", @a, " is larger than expected"))
+AS Master_gtid_wait_time_as_expected;
+Master_gtid_wait_time_as_expected
+OK
+connect s10,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+SELECT master_gtid_wait('0-1-109');
+connection server_2;
+SHOW STATUS LIKE 'Master_gtid_wait_timeouts';
+Variable_name Value
+Master_gtid_wait_timeouts 0
+SHOW STATUS LIKE 'Master_gtid_wait_count';
+Variable_name Value
+Master_gtid_wait_count 4
+SELECT master_gtid_wait('2-1-2', 0.5);
+master_gtid_wait('2-1-2', 0.5)
+-1
+SHOW STATUS LIKE 'Master_gtid_wait_timeouts';
+Variable_name Value
+Master_gtid_wait_timeouts 1
+SHOW STATUS LIKE 'Master_gtid_wait_count';
+Variable_name Value
+Master_gtid_wait_count 5
+SET @a= MASTER_GTID_WAIT_TIME;
+SELECT IF(@a BETWEEN 0.4*1000*1000 AND 100*1000*1000, "OK", CONCAT("Error: wait time ", @a, " not as expected")) AS Master_gtid_wait_time_as_expected;
+Master_gtid_wait_time_as_expected
+OK
+KILL QUERY KILL_ID;
+connection s3;
+ERROR 70100: Query execution was interrupted
+connection server_1;
+SET gtid_domain_id=2;
+SET gtid_seq_no=2;
+INSERT INTO t1 VALUES (4);
+connection s9;
+master_gtid_wait('2-1-2')
+0
+connection server_2;
+KILL CONNECTION KILL_ID;
+connection s6;
+Got one of the listed errors
+connection server_1;
+SET gtid_domain_id=1;
+SET gtid_seq_no=4;
+INSERT INTO t1 VALUES (5);
+SET gtid_domain_id=2;
+SET gtid_seq_no=5;
+INSERT INTO t1 VALUES (6);
+connection s8;
+master_gtid_wait('2-1-5,1-1-4,0-1-110')
+0
+connection s1;
+master_gtid_wait('2-1-1,1-1-4,0-1-110')
+0
+connection s2;
+master_gtid_wait('0-1-1000', 0.5)
+-1
+connection s5;
+master_gtid_wait('2-1-6', 1)
+-1
+connection s10;
+master_gtid_wait('0-1-109')
+0
+connection server_1;
+SET gtid_domain_id=2;
+SET gtid_seq_no=10;
+INSERT INTO t1 VALUES (7);
+connection s4;
+master_gtid_wait('2-1-10')
+0
+connection s7;
+master_gtid_wait('2-1-10')
+0
+*** Test gtid_slave_pos when used with GTID ***
+connection server_2;
+include/stop_slave.inc
+connection server_1;
+SET gtid_domain_id=2;
+SET gtid_seq_no=1000;
+INSERT INTO t1 VALUES (10);
+INSERT INTO t1 VALUES (11);
+connection server_2;
+SET sql_slave_skip_counter= 1;
+include/start_slave.inc
+SELECT * FROM t1 WHERE a >= 10 ORDER BY a;
+a
+11
+SELECT IF(LOCATE("2-1-1001", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 2-1-1001 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status;
+status
+Ok
+include/stop_slave.inc
+connection server_1;
+SET gtid_domain_id=2;
+SET gtid_seq_no=1010;
+INSERT INTO t1 VALUES (12);
+INSERT INTO t1 VALUES (13);
+connection server_2;
+SET sql_slave_skip_counter= 2;
+include/start_slave.inc
+SELECT * FROM t1 WHERE a >= 10 ORDER BY a;
+a
+11
+13
+SELECT IF(LOCATE("2-1-1011", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 2-1-1011 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status;
+status
+Ok
+include/stop_slave.inc
+connection server_1;
+SET gtid_domain_id=2;
+SET gtid_seq_no=1020;
+INSERT INTO t1 VALUES (14);
+INSERT INTO t1 VALUES (15);
+INSERT INTO t1 VALUES (16);
+connection server_2;
+SET sql_slave_skip_counter= 3;
+include/start_slave.inc
+SELECT * FROM t1 WHERE a >= 10 ORDER BY a;
+a
+11
+13
+15
+16
+SELECT IF(LOCATE("2-1-1022", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 2-1-1022 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status;
+status
+Ok
+include/stop_slave.inc
+connection server_1;
+SET gtid_domain_id=2;
+SET gtid_seq_no=1030;
+SET @@binlog_annotate_row_events= 0;
+INSERT INTO t1 VALUES (17);
+INSERT INTO t1 VALUES (18);
+INSERT INTO t1 VALUES (19);
+SET @@binlog_annotate_row_events= 1;
+connection server_2;
+SET sql_slave_skip_counter= 5;
+include/start_slave.inc
+SELECT * FROM t1 WHERE a >= 10 ORDER BY a;
+a
+11
+13
+15
+16
+19
+SELECT IF(LOCATE("2-1-1032", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 2-1-1032 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status;
+status
+Ok
+include/stop_slave.inc
+connection server_1;
+SET gtid_domain_id=3;
+SET gtid_seq_no=100;
+CREATE TABLE t2 (a INT PRIMARY KEY);
+DROP TABLE t2;
+SET gtid_domain_id=2;
+SET gtid_seq_no=1040;
+INSERT INTO t1 VALUES (20);
+connection server_2;
+SET @saved_mode= @@GLOBAL.slave_ddl_exec_mode;
+SET GLOBAL slave_ddl_exec_mode=STRICT;
+SET sql_slave_skip_counter=1;
+START SLAVE UNTIL master_gtid_pos="3-1-100";
+include/sync_with_master_gtid.inc
+include/wait_for_slave_to_stop.inc
+SELECT * FROM t2;
+ERROR 42S02: Table 'test.t2' doesn't exist
+SELECT IF(LOCATE("3-1-100", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 3-1-100 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status;
+status
+Ok
+SET sql_log_bin=0;
+CALL mtr.add_suppression("Slave: Unknown table 'test\\.t2' Error_code: 1051");
+SET sql_log_bin=1;
+START SLAVE;
+include/wait_for_slave_sql_error.inc [errno=1051]
+SELECT IF(LOCATE("3-1-100", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 3-1-100 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status;
+status
+Ok
+STOP SLAVE IO_THREAD;
+SET sql_slave_skip_counter=2;
+include/start_slave.inc
+SELECT * FROM t1 WHERE a >= 20 ORDER BY a;
+a
+20
+SELECT IF(LOCATE("3-1-101", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 3-1-101 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status;
+status
+Ok
+SELECT IF(LOCATE("2-1-1040", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 2-1-1040 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status;
+status
+Ok
+SET GLOBAL slave_ddl_exec_mode= @saved_mode;
+*** Test GTID-connecting to a master with out-of-order sequence numbers in the binlog. ***
+connection server_1;
+SET gtid_domain_id= @@GLOBAL.gtid_domain_id;
+INSERT INTO t1 VALUES (31);
+connection server_2;
+SET gtid_domain_id= @@GLOBAL.gtid_domain_id;
+INSERT INTO t1 VALUES (32);
+connection server_1;
+INSERT INTO t1 VALUES (33);
+connection server_2;
+connection server_3;
+include/stop_slave.inc
+connection server_1;
+INSERT INTO t1 VALUES (34);
+connection server_2;
+connection server_3;
+include/start_slave.inc
+SELECT * FROM t1 WHERE a >= 30 ORDER BY a;
+a
+31
+32
+33
+34
+connection server_4;
+SELECT * FROM t1 WHERE a >= 30 ORDER BY a;
+a
+31
+32
+33
+34
+*** MDEV-31723: Crash on SET SESSION gtid_seq_no= DEFAULT
+connection server_1;
+SET SESSION gtid_seq_no= 2000;
+SELECT @@SESSION.gtid_seq_no;
+@@SESSION.gtid_seq_no
+2000
+INSERT INTO t1 VALUES (40);
+SELECT @@SESSION.gtid_seq_no;
+@@SESSION.gtid_seq_no
+0
+SELECT REGEXP_REPLACE(@@gtid_binlog_pos, ".*\\b(0-1-[0-9]+)\\b.*", "\\1") AS dom0_pos;
+dom0_pos
+0-1-2000
+INSERT INTO t1 VALUES (41);
+SELECT REGEXP_REPLACE(@@gtid_binlog_pos, ".*\\b(0-1-[0-9]+)\\b.*", "\\1") AS dom0_pos;
+dom0_pos
+0-1-2001
+SET SESSION gtid_seq_no= 2010;
+INSERT INTO t1 VALUES (42);
+SELECT REGEXP_REPLACE(@@gtid_binlog_pos, ".*\\b(0-1-[0-9]+)\\b.*", "\\1") AS dom0_pos;
+dom0_pos
+0-1-2010
+SET @old_strict= @@GLOBAL.gtid_strict_mode;
+SET GLOBAL gtid_strict_mode= 1;
+SET SESSION gtid_seq_no= 0;
+INSERT INTO t1 VALUES (43);
+SELECT REGEXP_REPLACE(@@gtid_binlog_pos, ".*\\b(0-1-[0-9]+)\\b.*", "\\1") AS dom0_pos;
+dom0_pos
+0-1-2011
+SET GLOBAL gtid_strict_mode= @old_strict;
+INSERT INTO t1 VALUES (44);
+SELECT REGEXP_REPLACE(@@gtid_binlog_pos, ".*\\b(0-1-[0-9]+)\\b.*", "\\1") AS dom0_pos;
+dom0_pos
+0-1-2012
+SET SESSION gtid_seq_no= 2020;
+SET SESSION gtid_seq_no= 2030;
+INSERT INTO t1 VALUES (45);
+SELECT REGEXP_REPLACE(@@gtid_binlog_pos, ".*\\b(0-1-[0-9]+)\\b.*", "\\1") AS dom0_pos;
+dom0_pos
+0-1-2030
+SET SESSION gtid_seq_no= 2040;
+SET SESSION gtid_seq_no= DEFAULT;
+INSERT INTO t1 VALUES (46);
+SELECT REGEXP_REPLACE(@@gtid_binlog_pos, ".*\\b(0-1-[0-9]+)\\b.*", "\\1") AS dom0_pos;
+dom0_pos
+0-1-2031
+INSERT INTO t1 VALUES (47);
+SELECT REGEXP_REPLACE(@@gtid_binlog_pos, ".*\\b(0-1-[0-9]+)\\b.*", "\\1") AS dom0_pos;
+dom0_pos
+0-1-2032
+SET SESSION gtid_seq_no= 2050;
+SET SESSION gtid_seq_no= 0;
+INSERT INTO t1 VALUES (48);
+SELECT REGEXP_REPLACE(@@gtid_binlog_pos, ".*\\b(0-1-[0-9]+)\\b.*", "\\1") AS dom0_pos;
+dom0_pos
+0-1-2033
+connection server_1;
+DROP TABLE t1;
+include/rpl_end.inc
+#
+# Start of 10.2 tests
+#
+#
+# MDEV-10134 Add full support for DEFAULT
+#
+CREATE TABLE t1 (a VARCHAR(100) DEFAULT BINLOG_GTID_POS("master-bin.000001", 600));
+ERROR HY000: Function or expression 'binlog_gtid_pos()' cannot be used in the DEFAULT clause of `a`
+#
+# End of 10.2 tests
+#
+#
+# Start of 10.3 tests
+#
+#
+# MDEV-13967 Parameter data type control for Item_long_func
+#
+SELECT MASTER_GTID_WAIT(ROW(1,1),'str');
+ERROR HY000: Illegal parameter data type row for operation 'master_gtid_wait'
+SELECT MASTER_GTID_WAIT('str',ROW(1,1));
+ERROR HY000: Illegal parameter data type row for operation 'master_gtid_wait'
+#
+# End of 10.3 tests
+#
diff --git a/mysql-test/suite/binlog_encryption/rpl_gtid_basic.test b/mysql-test/suite/binlog_encryption/rpl_gtid_basic.test
new file mode 100644
index 00000000..b183c1d4
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_gtid_basic.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_gtid_basic.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_incident.cnf b/mysql-test/suite/binlog_encryption/rpl_incident.cnf
new file mode 100644
index 00000000..7294976f
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_incident.cnf
@@ -0,0 +1,7 @@
+!include my.cnf
+
+[mysqld.1]
+binlog_checksum=NONE
+
+[mysqld.2]
+binlog_checksum=NONE
diff --git a/mysql-test/suite/binlog_encryption/rpl_incident.result b/mysql-test/suite/binlog_encryption/rpl_incident.result
new file mode 100644
index 00000000..6dbe4417
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_incident.result
@@ -0,0 +1,51 @@
+include/master-slave.inc
+[connection master]
+SET @old_binlog_checksum=@@binlog_checksum;
+SET GLOBAL BINLOG_CHECKSUM=none;
+connection slave;
+SET @old_binlog_checksum=@@binlog_checksum;
+SET GLOBAL BINLOG_CHECKSUM=none;
+connection master;
+**** On Master ****
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+SELECT * FROM t1;
+a
+1
+2
+3
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug= '+d,incident_database_resync_on_replace,*';
+REPLACE INTO t1 VALUES (4);
+SELECT * FROM t1;
+a
+1
+2
+3
+4
+set @@global.debug_dbug = @saved_dbug;
+connection slave;
+call mtr.add_suppression("Slave SQL.*The incident LOST_EVENTS occurred on the master.* 1590");
+include/wait_for_slave_sql_error.inc [errno=1590]
+Last_SQL_Error = 'The incident LOST_EVENTS occurred on the master. Message: <none>'
+**** On Slave ****
+SELECT * FROM t1;
+a
+1
+2
+3
+SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
+START SLAVE;
+SELECT * FROM t1;
+a
+1
+2
+3
+4
+include/check_slave_is_running.inc
+connection master;
+SET GLOBAL BINLOG_CHECKSUM=@old_binlog_checksum;
+DROP TABLE t1;
+connection slave;
+SET GLOBAL BINLOG_CHECKSUM=@old_binlog_checksum;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_incident.test b/mysql-test/suite/binlog_encryption/rpl_incident.test
new file mode 100644
index 00000000..5a707774
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_incident.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_incident.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_init_slave_errors.result b/mysql-test/suite/binlog_encryption/rpl_init_slave_errors.result
new file mode 100644
index 00000000..fc23734c
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_init_slave_errors.result
@@ -0,0 +1,23 @@
+include/master-slave.inc
+[connection master]
+connection slave;
+stop slave;
+reset slave;
+connection slave;
+set @saved_dbug = @@global.debug_dbug;
+SET GLOBAL debug_dbug= "d,simulate_io_slave_error_on_init,simulate_sql_slave_error_on_init";
+start slave;
+include/wait_for_slave_sql_error.inc [errno=1593]
+Last_SQL_Error = 'Failed during slave thread initialization'
+call mtr.add_suppression("Failed during slave.* thread initialization");
+set @@global.debug_dbug = @saved_dbug;
+connection slave;
+reset slave;
+SET GLOBAL init_slave= "garbage";
+start slave;
+include/wait_for_slave_sql_error.inc [errno=1064]
+Last_SQL_Error = 'Slave SQL thread aborted. Can't execute init_slave query'
+SET GLOBAL init_slave= "";
+include/stop_slave_io.inc
+RESET SLAVE;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_init_slave_errors.test b/mysql-test/suite/binlog_encryption/rpl_init_slave_errors.test
new file mode 100644
index 00000000..532db963
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_init_slave_errors.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_init_slave_errors.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_loaddata_local.result b/mysql-test/suite/binlog_encryption/rpl_loaddata_local.result
new file mode 100644
index 00000000..f0d24df2
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_loaddata_local.result
@@ -0,0 +1,134 @@
+include/master-slave.inc
+[connection master]
+create table t1(a int);
+select * into outfile 'MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile' from t1;
+truncate table t1;
+load data local infile 'MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile' into table t1;
+connection slave;
+select a,count(*) from t1 group by a;
+a count(*)
+1 10000
+connection master;
+drop table t1;
+connection slave;
+connection master;
+create table t1(a int);
+insert into t1 values (1), (2), (2), (3);
+select * into outfile 'MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile' from t1;
+drop table t1;
+create table t1(a int primary key);
+load data local infile 'MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile' into table t1;
+Warnings:
+Warning 1062 Duplicate entry '2' for key 'PRIMARY'
+SELECT * FROM t1 ORDER BY a;
+a
+1
+2
+3
+connection slave;
+SELECT * FROM t1 ORDER BY a;
+a
+1
+2
+3
+connection master;
+drop table t1;
+connection slave;
+==== Bug22504 Initialize ====
+connection master;
+SET sql_mode='ignore_space';
+CREATE TABLE t1(a int);
+insert into t1 values (1), (2), (3), (4);
+select * into outfile 'MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile' from t1;
+truncate table t1;
+load data local infile 'MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile' into table t1;
+SELECT * FROM t1 ORDER BY a;
+a
+1
+2
+3
+4
+connection slave;
+SELECT * FROM t1 ORDER BY a;
+a
+1
+2
+3
+4
+==== Clean up ====
+connection master;
+DROP TABLE t1;
+connection slave;
+
+Bug #43746:
+"return wrong query string when parse 'load data infile' sql statement"
+
+connection master;
+SELECT @@SESSION.sql_mode INTO @old_mode;
+SET sql_mode='ignore_space';
+CREATE TABLE t1(a int);
+INSERT INTO t1 VALUES (1), (2), (3), (4);
+SELECT * INTO OUTFILE 'MYSQLD_DATADIR/bug43746.sql' FROM t1;
+TRUNCATE TABLE t1;
+LOAD DATA LOCAL INFILE 'MYSQLD_DATADIR/bug43746.sql' INTO TABLE t1;
+LOAD/* look mum, with comments in weird places! */DATA/* oh hai */LOCAL INFILE 'MYSQLD_DATADIR/bug43746.sql'/* we are */INTO/* from the internets */TABLE t1;
+LOAD DATA/*!10000 LOCAL */INFILE 'MYSQLD_DATADIR/bug43746.sql' INTO TABLE t1;
+LOAD DATA LOCAL INFILE 'MYSQLD_DATADIR/bug43746.sql' /*!10000 INTO */ TABLE t1;
+LOAD DATA LOCAL INFILE 'MYSQLD_DATADIR/bug43746.sql' /*!10000 INTO TABLE */ t1;
+LOAD DATA /*!10000 LOCAL INFILE 'MYSQLD_DATADIR/bug43746.sql' INTO TABLE */ t1;
+LOAD DATA/*!10000 LOCAL */INFILE 'MYSQLD_DATADIR/bug43746.sql'/*!10000 INTO*/TABLE t1;
+LOAD DATA/*!10000 LOCAL */INFILE 'MYSQLD_DATADIR/bug43746.sql'/* empty */INTO TABLE t1;
+LOAD DATA/*!10000 LOCAL */INFILE 'MYSQLD_DATADIR/bug43746.sql' INTO/* empty */TABLE t1;
+LOAD/*!999999 special comments that do not expand */DATA/*!999999 code from the future */LOCAL INFILE 'MYSQLD_DATADIR/bug43746.sql'/*!999999 have flux capacitor */INTO/*!999999 will travel */TABLE t1;
+SET sql_mode='PIPES_AS_CONCAT,ANSI_QUOTES,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER';
+LOAD DATA LOCAL INFILE 'MYSQLD_DATADIR/bug43746.sql' INTO TABLE t1;
+connection slave;
+
+Bug #59267:
+"LOAD DATA LOCAL INFILE not executed on slave with SBR"
+
+connection master;
+SELECT * INTO OUTFILE 'MYSQLD_DATADIR/bug59267.sql' FROM t1;
+TRUNCATE TABLE t1;
+LOAD DATA LOCAL INFILE 'MYSQLD_DATADIR/bug59267.sql' INTO TABLE t1;
+SELECT 'Master', COUNT(*) FROM t1;
+Master COUNT(*)
+Master 44
+connection slave;
+SELECT 'Slave', COUNT(*) FROM t1;
+Slave COUNT(*)
+Slave 44
+connection master;
+DROP TABLE t1;
+SET SESSION sql_mode=@old_mode;
+connection slave;
+connection master;
+
+Bug #60580/#11902767:
+"statement improperly replicated crashes slave sql thread"
+
+connection master;
+CREATE TABLE t1(f1 INT, f2 INT);
+CREATE TABLE t2(f1 INT, f2 TIMESTAMP);
+INSERT INTO t2 VALUES(1, '2011-03-22 21:01:28');
+INSERT INTO t2 VALUES(2, '2011-03-21 21:01:28');
+INSERT INTO t2 VALUES(3, '2011-03-20 21:01:28');
+CREATE TABLE t3 AS SELECT * FROM t2;
+CREATE VIEW v1 AS SELECT * FROM t2
+WHERE f1 IN (SELECT f1 FROM t3 WHERE (t3.f2 IS NULL));
+SELECT 1 INTO OUTFILE 'MYSQLD_DATADIR/bug60580.csv' FROM DUAL;
+LOAD DATA LOCAL INFILE 'MYSQLD_DATADIR/bug60580.csv' INTO TABLE t1 (@f1) SET f2 = (SELECT f1 FROM v1 WHERE f1=@f1);
+SELECT * FROM t1;
+f1 f2
+NULL NULL
+connection slave;
+SELECT * FROM t1;
+f1 f2
+NULL NULL
+connection master;
+DROP VIEW v1;
+DROP TABLE t1, t2, t3;
+connection slave;
+connection master;
+include/rpl_end.inc
+# End of 5.1 tests
diff --git a/mysql-test/suite/binlog_encryption/rpl_loaddata_local.test b/mysql-test/suite/binlog_encryption/rpl_loaddata_local.test
new file mode 100644
index 00000000..35ad0964
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_loaddata_local.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_loaddata_local.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_loadfile.result b/mysql-test/suite/binlog_encryption/rpl_loadfile.result
new file mode 100644
index 00000000..19a11e99
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_loadfile.result
@@ -0,0 +1,254 @@
+include/master-slave.inc
+[connection master]
+connection master;
+DROP PROCEDURE IF EXISTS test.p1;
+DROP TABLE IF EXISTS test.t1;
+CREATE TABLE test.t1 (a INT, blob_column LONGBLOB, PRIMARY KEY(a));
+INSERT INTO test.t1 VALUES(1,'test');
+UPDATE test.t1 SET blob_column=LOAD_FILE('../../std_data/words2.dat') WHERE a=1;
+create procedure test.p1()
+begin
+INSERT INTO test.t1 VALUES(2,'test');
+UPDATE test.t1 SET blob_column=LOAD_FILE('../../std_data/words2.dat') WHERE a=2;
+end|
+CALL test.p1();
+SELECT * FROM test.t1 ORDER BY blob_column;
+a blob_column
+1 abase
+abased
+abasement
+abasements
+abases
+abash
+abashed
+abashes
+abashing
+abasing
+abate
+abated
+abatement
+abatements
+abater
+abates
+abating
+Abba
+abbe
+abbey
+abbeys
+abbot
+abbots
+Abbott
+abbreviate
+abbreviated
+abbreviates
+abbreviating
+abbreviation
+abbreviations
+Abby
+abdomen
+abdomens
+abdominal
+abduct
+abducted
+abduction
+abductions
+abductor
+abductors
+abducts
+Abe
+abed
+Abel
+Abelian
+Abelson
+Aberdeen
+Abernathy
+aberrant
+aberration
+
+2 abase
+abased
+abasement
+abasements
+abases
+abash
+abashed
+abashes
+abashing
+abasing
+abate
+abated
+abatement
+abatements
+abater
+abates
+abating
+Abba
+abbe
+abbey
+abbeys
+abbot
+abbots
+Abbott
+abbreviate
+abbreviated
+abbreviates
+abbreviating
+abbreviation
+abbreviations
+Abby
+abdomen
+abdomens
+abdominal
+abduct
+abducted
+abduction
+abductions
+abductor
+abductors
+abducts
+Abe
+abed
+Abel
+Abelian
+Abelson
+Aberdeen
+Abernathy
+aberrant
+aberration
+
+connection slave;
+connection slave;
+SELECT * FROM test.t1 ORDER BY blob_column;
+a blob_column
+1 abase
+abased
+abasement
+abasements
+abases
+abash
+abashed
+abashes
+abashing
+abasing
+abate
+abated
+abatement
+abatements
+abater
+abates
+abating
+Abba
+abbe
+abbey
+abbeys
+abbot
+abbots
+Abbott
+abbreviate
+abbreviated
+abbreviates
+abbreviating
+abbreviation
+abbreviations
+Abby
+abdomen
+abdomens
+abdominal
+abduct
+abducted
+abduction
+abductions
+abductor
+abductors
+abducts
+Abe
+abed
+Abel
+Abelian
+Abelson
+Aberdeen
+Abernathy
+aberrant
+aberration
+
+2 abase
+abased
+abasement
+abasements
+abases
+abash
+abashed
+abashes
+abashing
+abasing
+abate
+abated
+abatement
+abatements
+abater
+abates
+abating
+Abba
+abbe
+abbey
+abbeys
+abbot
+abbots
+Abbott
+abbreviate
+abbreviated
+abbreviates
+abbreviating
+abbreviation
+abbreviations
+Abby
+abdomen
+abdomens
+abdominal
+abduct
+abducted
+abduction
+abductions
+abductor
+abductors
+abducts
+Abe
+abed
+Abel
+Abelian
+Abelson
+Aberdeen
+Abernathy
+aberrant
+aberration
+
+connection master;
+DROP PROCEDURE IF EXISTS test.p1;
+DROP TABLE test.t1;
+connection slave;
+include/rpl_reset.inc
+connection master;
+SELECT repeat('x',20) INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug_39701.data';
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (t text);
+CREATE PROCEDURE p(file varchar(4096))
+BEGIN
+INSERT INTO t1 VALUES (LOAD_FILE(file));
+END|
+connection slave;
+include/stop_slave.inc
+connection master;
+CALL p('MYSQLTEST_VARDIR/tmp/bug_39701.data');
+connection slave;
+include/start_slave.inc
+connection master;
+connection slave;
+include/diff_tables.inc [master:t1, slave:t1]
+connection master;
+DROP TABLE t1;
+DROP PROCEDURE p;
+include/rpl_end.inc
+#
+# Check that the loaded data is encrypted in the master binlog
+#
+NOT FOUND /xxxxxxxxxxx/ in master-bin.0*
diff --git a/mysql-test/suite/binlog_encryption/rpl_loadfile.test b/mysql-test/suite/binlog_encryption/rpl_loadfile.test
new file mode 100644
index 00000000..235c4a3d
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_loadfile.test
@@ -0,0 +1,12 @@
+--source suite/rpl/t/rpl_loadfile.test
+
+--let $datadir= `SELECT @@datadir`
+
+--echo #
+--echo # Check that the loaded data is encrypted in the master binlog
+--echo #
+
+--let SEARCH_FILE=$datadir/master-bin.0*
+--let SEARCH_RANGE = 500000
+--let SEARCH_PATTERN= xxxxxxxxxxx
+--source include/search_pattern_in_file.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_mixed_binlog_max_cache_size.result b/mysql-test/suite/binlog_encryption/rpl_mixed_binlog_max_cache_size.result
new file mode 100644
index 00000000..e94e097f
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_mixed_binlog_max_cache_size.result
@@ -0,0 +1,217 @@
+include/master-slave.inc
+[connection master]
+connection slave;
+include/stop_slave.inc
+CHANGE MASTER TO MASTER_USE_GTID=NO;
+include/start_slave.inc
+connection master;
+call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
+call mtr.add_suppression("Write to binary log failed: Multi-row statements required more than .max_binlog_stmt_cache_size");
+call mtr.add_suppression("Write to binary log failed: Multi-statement transaction required more than .max_binlog_cache_size");
+SET GLOBAL max_binlog_cache_size = 4096;
+SET GLOBAL binlog_cache_size = 4096;
+SET GLOBAL max_binlog_stmt_cache_size = 4096;
+SET GLOBAL binlog_stmt_cache_size = 4096;
+disconnect master;
+connect master,127.0.0.1,root,,test,$MASTER_MYPORT,;
+CREATE TABLE t1(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=Innodb;
+CREATE TABLE t2(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=MyIsam;
+CREATE TABLE t3(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=Innodb;
+########################################################################################
+# 1 - SINGLE STATEMENT
+########################################################################################
+connection master;
+*** Single statement on transactional table ***
+Got one of the listed errors
+*** Single statement on non-transactional table ***
+Got one of the listed errors
+include/wait_for_slave_sql_error_and_skip.inc [errno=1590]
+*** Single statement on both transactional and non-transactional tables. ***
+Got one of the listed errors
+include/wait_for_slave_sql_error_and_skip.inc [errno=1590]
+include/diff_tables.inc [master:t1,slave:t1]
+########################################################################################
+# 2 - BEGIN - IMPLICIT COMMIT by DDL
+########################################################################################
+connection master;
+TRUNCATE TABLE t1;
+TRUNCATE TABLE t2;
+TRUNCATE TABLE t3;
+set default_storage_engine=innodb;
+BEGIN;
+Got one of the listed errors
+Got one of the listed errors
+Got one of the listed errors
+INSERT INTO t1 (a, data) VALUES (7, 's');;
+INSERT INTO t2 (a, data) VALUES (8, 's');;
+INSERT INTO t1 (a, data) VALUES (9, 's');;
+ALTER TABLE t3 ADD COLUMN d int;
+BEGIN;
+Got one of the listed errors
+Got one of the listed errors
+INSERT INTO t1 (a, data) VALUES (19, 's');;
+INSERT INTO t2 (a, data) VALUES (20, 's');;
+INSERT INTO t1 (a, data) VALUES (21, 's');;
+CREATE TABLE t4 SELECT * FROM t1;
+BEGIN;
+Got one of the listed errors
+Got one of the listed errors
+INSERT INTO t1 (a, data) VALUES (27, 's');;
+INSERT INTO t2 (a, data) VALUES (28, 's');;
+INSERT INTO t1 (a, data) VALUES (29, 's');;
+CREATE TABLE t5 (a int);
+connection slave;
+include/diff_tables.inc [master:t1,slave:t1]
+########################################################################################
+# 3 - BEGIN - COMMIT
+########################################################################################
+connection master;
+TRUNCATE TABLE t1;
+TRUNCATE TABLE t2;
+TRUNCATE TABLE t3;
+BEGIN;
+Got one of the listed errors
+Got one of the listed errors
+Got one of the listed errors
+COMMIT;
+connection slave;
+include/diff_tables.inc [master:t1,slave:t1]
+########################################################################################
+# 4 - BEGIN - ROLLBACK
+########################################################################################
+connection master;
+TRUNCATE TABLE t1;
+TRUNCATE TABLE t2;
+TRUNCATE TABLE t3;
+BEGIN;
+Got one of the listed errors
+Got one of the listed errors
+Got one of the listed errors
+ROLLBACK;
+Warnings:
+Warning 1196 Some non-transactional changed tables couldn't be rolled back
+connection slave;
+include/diff_tables.inc [master:t1,slave:t1]
+########################################################################################
+# 5 - PROCEDURE
+########################################################################################
+connection master;
+TRUNCATE TABLE t1;
+TRUNCATE TABLE t2;
+TRUNCATE TABLE t3;
+CREATE PROCEDURE p1(pd VARCHAR(30000))
+BEGIN
+INSERT INTO t1 (a, data) VALUES (1, pd);
+INSERT INTO t1 (a, data) VALUES (2, pd);
+INSERT INTO t1 (a, data) VALUES (3, pd);
+INSERT INTO t1 (a, data) VALUES (4, pd);
+INSERT INTO t1 (a, data) VALUES (5, 's');
+END//
+TRUNCATE TABLE t1;
+TRUNCATE TABLE t1;
+BEGIN;
+Got one of the listed errors
+COMMIT;
+TRUNCATE TABLE t1;
+BEGIN;
+Got one of the listed errors
+ROLLBACK;
+connection slave;
+include/diff_tables.inc [master:t1,slave:t1]
+########################################################################################
+# 6 - XID
+########################################################################################
+connection master;
+TRUNCATE TABLE t1;
+TRUNCATE TABLE t2;
+TRUNCATE TABLE t3;
+BEGIN;
+Got one of the listed errors
+Got one of the listed errors
+Got one of the listed errors
+INSERT INTO t1 (a, data) VALUES (7, 's');;
+INSERT INTO t2 (a, data) VALUES (8, 's');;
+INSERT INTO t1 (a, data) VALUES (9, 's');;
+ROLLBACK TO sv;
+Warnings:
+Warning 1196 Some non-transactional changed tables couldn't be rolled back
+COMMIT;
+connection slave;
+include/diff_tables.inc [master:t1,slave:t1]
+########################################################################################
+# 7 - NON-TRANS TABLE
+########################################################################################
+connection master;
+TRUNCATE TABLE t1;
+TRUNCATE TABLE t2;
+TRUNCATE TABLE t3;
+BEGIN;
+Got one of the listed errors
+Got one of the listed errors
+Got one of the listed errors
+INSERT INTO t1 (a, data) VALUES (8, 's');;
+INSERT INTO t1 (a, data) VALUES (9, 's');;
+INSERT INTO t2 (a, data) VALUES (10, 's');;
+INSERT INTO t1 (a, data) VALUES (11, 's');;
+COMMIT;
+BEGIN;
+Got one of the listed errors
+COMMIT;
+connection slave;
+include/diff_tables.inc [master:t1,slave:t1]
+########################################################################
+# 8 - Bug#55375(Regression Bug) Transaction bigger than
+# max_binlog_cache_size crashes slave
+########################################################################
+# [ On Slave ]
+SET GLOBAL max_binlog_cache_size = 4096;
+SET GLOBAL binlog_cache_size = 4096;
+SET GLOBAL max_binlog_stmt_cache_size = 4096;
+SET GLOBAL binlog_stmt_cache_size = 4096;
+include/stop_slave.inc
+include/start_slave.inc
+CALL mtr.add_suppression("Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage.*");
+CALL mtr.add_suppression("Multi-statement transaction required more than 'max_binlog_stmt_cache_size' bytes of storage.*");
+CALL mtr.add_suppression("Writing one row to the row-based binary log failed.*");
+CALL mtr.add_suppression("Slave SQL.*The incident LOST_EVENTS occurred on the master. Message: error writing to the binary log");
+connection master;
+TRUNCATE t1;
+connection slave;
+connection master;
+SET GLOBAL max_binlog_cache_size= ORIGINAL_VALUE;
+SET GLOBAL binlog_cache_size= ORIGINAL_VALUE;
+SET GLOBAL max_binlog_stmt_cache_size= ORIGINAL_VALUE;
+SET GLOBAL binlog_stmt_cache_size= ORIGINAL_VALUE;
+disconnect master;
+connect master,127.0.0.1,root,,test,$MASTER_MYPORT,;
+BEGIN;
+Repeat statement 'INSERT INTO t1 VALUES($n, repeat("a", 32))' 128 times
+COMMIT;
+connection slave;
+include/wait_for_slave_sql_error.inc [errno=1197]
+SELECT count(*) FROM t1;
+count(*)
+0
+include/show_binlog_events.inc
+SET GLOBAL max_binlog_cache_size= ORIGINAL_VALUE;
+SET GLOBAL binlog_cache_size= ORIGINAL_VALUE;
+SET GLOBAL max_binlog_stmt_cache_size= ORIGINAL_VALUE;
+SET GLOBAL binlog_stmt_cache_size= ORIGINAL_VALUE;
+include/stop_slave.inc
+include/start_slave.inc
+connection master;
+connection slave;
+SELECT count(*) FROM t1;
+count(*)
+128
+########################################################################################
+# CLEAN
+########################################################################################
+connection master;
+DROP TABLE t1;
+DROP TABLE t2;
+DROP TABLE t3;
+DROP TABLE IF EXISTS t4;
+DROP TABLE t5;
+DROP PROCEDURE p1;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_mixed_binlog_max_cache_size.test b/mysql-test/suite/binlog_encryption/rpl_mixed_binlog_max_cache_size.test
new file mode 100644
index 00000000..144f86cc
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_mixed_binlog_max_cache_size.test
@@ -0,0 +1,7 @@
+--source include/master-slave.inc
+--source include/not_embedded.inc
+--source include/not_windows.inc
+--source include/have_binlog_format_mixed.inc
+
+--source suite/rpl/include/rpl_binlog_max_cache_size.test
+--source include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_packet.cnf b/mysql-test/suite/binlog_encryption/rpl_packet.cnf
new file mode 100644
index 00000000..0f01aec7
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_packet.cnf
@@ -0,0 +1,10 @@
+!include my.cnf
+
+[mysqld.1]
+max_allowed_packet=1024
+net_buffer_length=1024
+
+[mysqld.2]
+max_allowed_packet=1024
+net_buffer_length=1024
+slave_max_allowed_packet=1024
diff --git a/mysql-test/suite/binlog_encryption/rpl_packet.result b/mysql-test/suite/binlog_encryption/rpl_packet.result
new file mode 100644
index 00000000..4a2a5d70
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_packet.result
@@ -0,0 +1,83 @@
+include/master-slave.inc
+[connection master]
+call mtr.add_suppression("Slave I/O: Got a packet bigger than 'slave_max_allowed_packet' bytes, .*error.* 1153");
+call mtr.add_suppression("Log entry on master is longer than slave_max_allowed_packet");
+drop database if exists DB_NAME_OF_MAX_LENGTH_AKA_NAME_LEN_64_BYTES_____________________;
+create database DB_NAME_OF_MAX_LENGTH_AKA_NAME_LEN_64_BYTES_____________________;
+connection master;
+SET @@global.max_allowed_packet=1024;
+SET @@global.net_buffer_length=1024;
+connection slave;
+include/stop_slave.inc
+include/start_slave.inc
+disconnect master;
+connect master,localhost,root,,DB_NAME_OF_MAX_LENGTH_AKA_NAME_LEN_64_BYTES_____________________;
+connection master;
+select @@net_buffer_length, @@max_allowed_packet;
+@@net_buffer_length @@max_allowed_packet
+1024 1024
+create table `t1` (`f1` LONGTEXT) ENGINE=MyISAM;
+INSERT INTO `t1`(`f1`) VALUES ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1023');
+connection slave;
+select count(*) from `DB_NAME_OF_MAX_LENGTH_AKA_NAME_LEN_64_BYTES_____________________`.`t1` /* must be 1 */;
+count(*)
+1
+SHOW STATUS LIKE 'Slave_running';
+Variable_name Value
+Slave_running ON
+select * from information_schema.session_status where variable_name= 'SLAVE_RUNNING';
+VARIABLE_NAME VARIABLE_VALUE
+SLAVE_RUNNING ON
+connection master;
+drop database DB_NAME_OF_MAX_LENGTH_AKA_NAME_LEN_64_BYTES_____________________;
+connection slave;
+connection master;
+SET @@global.max_allowed_packet=4096;
+SET @@global.net_buffer_length=4096;
+connection slave;
+include/stop_slave.inc
+include/start_slave.inc
+disconnect master;
+connect master, localhost, root;
+connection master;
+CREATE TABLE `t1` (`f1` LONGTEXT) ENGINE=MyISAM;
+connection slave;
+connection master;
+INSERT INTO `t1`(`f1`) VALUES ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2048');
+connection slave;
+include/wait_for_slave_io_error.inc [errno=1153]
+Last_IO_Error = 'Got a packet bigger than 'slave_max_allowed_packet' bytes'
+include/stop_slave_sql.inc
+include/rpl_reset.inc
+connection master;
+DROP TABLE t1;
+connection slave;
+connection master;
+CREATE TABLE t1 (f1 int PRIMARY KEY, f2 LONGTEXT, f3 LONGTEXT) ENGINE=MyISAM;
+connection slave;
+connection master;
+INSERT INTO t1(f1, f2, f3) VALUES(1, REPEAT('a', @@global.max_allowed_packet), REPEAT('b', @@global.max_allowed_packet));
+connection slave;
+include/wait_for_slave_io_error.inc [errno=1153]
+Last_IO_Error = 'Got a packet bigger than 'slave_max_allowed_packet' bytes'
+STOP SLAVE;
+RESET SLAVE;
+connection master;
+RESET MASTER;
+SET @max_allowed_packet_0= @@session.max_allowed_packet;
+SHOW BINLOG EVENTS;
+SET @max_allowed_packet_1= @@session.max_allowed_packet;
+SHOW BINLOG EVENTS;
+SET @max_allowed_packet_2= @@session.max_allowed_packet;
+==== clean up ====
+connection master;
+DROP TABLE t1;
+SET @@global.max_allowed_packet= 1024;
+Warnings:
+Warning 1708 The value of 'max_allowed_packet' should be no less than the value of 'net_buffer_length'
+SET @@global.net_buffer_length= 1024;
+SET @@global.slave_max_allowed_packet= 1073741824;
+connection slave;
+DROP TABLE t1;
+RESET SLAVE;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_packet.test b/mysql-test/suite/binlog_encryption/rpl_packet.test
new file mode 100644
index 00000000..28beae1a
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_packet.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_packet.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_analyze_table_hang.result b/mysql-test/suite/binlog_encryption/rpl_parallel_analyze_table_hang.result
new file mode 100644
index 00000000..3c3cd260
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_analyze_table_hang.result
@@ -0,0 +1,51 @@
+*** MDEV-7888: ANALYZE TABLE does wakeup_subsequent_commits(), causing wrong binlog order and parallel replication hang ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+SET @old_parallel_mode=@@GLOBAL.slave_parallel_mode;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_mode='conservative';
+SET GLOBAL slave_parallel_threads=10;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
+connection server_2;
+include/stop_slave.inc
+SET @old_dbug= @@GLOBAL.debug_dbug;
+SET GLOBAL debug_dbug= '+d,inject_analyze_table_sleep';
+connection server_1;
+SET @old_dbug= @@SESSION.debug_dbug;
+SET SESSION debug_dbug="+d,binlog_force_commit_id";
+SET @commit_id= 10000;
+ANALYZE TABLE t2;
+Table Op Msg_type Msg_text
+test.t2 analyze status Engine-independent statistics collected
+test.t2 analyze status OK
+INSERT INTO t3 VALUES (120, 0);
+SET @commit_id= 10001;
+INSERT INTO t3 VALUES (121, 0);
+SET SESSION debug_dbug=@old_dbug;
+SELECT * FROM t3 WHERE a >= 120 ORDER BY a;
+a b
+120 0
+121 0
+include/save_master_gtid.inc
+connection server_2;
+include/start_slave.inc
+include/sync_with_master_gtid.inc
+SELECT * FROM t3 WHERE a >= 120 ORDER BY a;
+a b
+120 0
+121 0
+include/stop_slave.inc
+SET GLOBAL debug_dbug= @old_dbug;
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+SET GLOBAL slave_parallel_mode=@old_parallel_mode;
+include/start_slave.inc
+connection server_1;
+DROP TABLE t2,t3;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_analyze_table_hang.test b/mysql-test/suite/binlog_encryption/rpl_parallel_analyze_table_hang.test
new file mode 100644
index 00000000..14eb643b
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_analyze_table_hang.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_analyze_table_hang.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_deadlock_corrupt_binlog.result b/mysql-test/suite/binlog_encryption/rpl_parallel_deadlock_corrupt_binlog.result
new file mode 100644
index 00000000..f3203cfe
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_deadlock_corrupt_binlog.result
@@ -0,0 +1,94 @@
+*** MDEV-7335: Potential parallel slave deadlock with specific binlog corruption ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+include/stop_slave.inc
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+SET GLOBAL slave_parallel_threads=10;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB;
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=1;
+SET @old_dbug= @@GLOBAL.debug_dbug;
+SET GLOBAL debug_dbug="+d,slave_discard_xid_for_gtid_0_x_1000";
+CALL mtr.add_suppression("Unexpected break of being relay-logged GTID");
+connection server_1;
+INSERT INTO t2 VALUES (101);
+INSERT INTO t2 VALUES (102);
+INSERT INTO t2 VALUES (103);
+INSERT INTO t2 VALUES (104);
+INSERT INTO t2 VALUES (105);
+SET gtid_seq_no=1000;
+INSERT INTO t2 VALUES (106);
+INSERT INTO t2 VALUES (107);
+INSERT INTO t2 VALUES (108);
+INSERT INTO t2 VALUES (109);
+INSERT INTO t2 VALUES (110);
+INSERT INTO t2 VALUES (111);
+INSERT INTO t2 VALUES (112);
+INSERT INTO t2 VALUES (113);
+INSERT INTO t2 VALUES (114);
+INSERT INTO t2 VALUES (115);
+INSERT INTO t2 VALUES (116);
+INSERT INTO t2 VALUES (117);
+INSERT INTO t2 VALUES (118);
+INSERT INTO t2 VALUES (119);
+INSERT INTO t2 VALUES (120);
+INSERT INTO t2 VALUES (121);
+INSERT INTO t2 VALUES (122);
+INSERT INTO t2 VALUES (123);
+INSERT INTO t2 VALUES (124);
+INSERT INTO t2 VALUES (125);
+INSERT INTO t2 VALUES (126);
+INSERT INTO t2 VALUES (127);
+INSERT INTO t2 VALUES (128);
+INSERT INTO t2 VALUES (129);
+INSERT INTO t2 VALUES (130);
+include/save_master_gtid.inc
+connection server_2;
+include/start_slave.inc
+include/sync_with_master_gtid.inc
+SELECT * FROM t2 WHERE a >= 100 ORDER BY a;
+a
+101
+102
+103
+104
+105
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+include/stop_slave.inc
+SET GLOBAL debug_dbug=@old_dbug;
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+SET DEBUG_SYNC= 'RESET';
+connection server_1;
+DROP TABLE t2;
+SET DEBUG_SYNC= 'RESET';
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_deadlock_corrupt_binlog.test b/mysql-test/suite/binlog_encryption/rpl_parallel_deadlock_corrupt_binlog.test
new file mode 100644
index 00000000..bc509a29
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_deadlock_corrupt_binlog.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_deadlock_corrupt_binlog.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_domain.result b/mysql-test/suite/binlog_encryption/rpl_parallel_domain.result
new file mode 100644
index 00000000..69b9678d
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_domain.result
@@ -0,0 +1,71 @@
+include/master-slave.inc
+[connection master]
+connection server_2;
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+SET GLOBAL slave_parallel_threads=10;
+ERROR HY000: This operation cannot be performed as you have a running slave ''; run STOP SLAVE '' first
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=10;
+SELECT IF(COUNT(*) < 10, "OK", CONCAT("Found too many system user processes: ", COUNT(*))) FROM information_schema.processlist WHERE user = "system user";
+IF(COUNT(*) < 10, "OK", CONCAT("Found too many system user processes: ", COUNT(*)))
+OK
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+SELECT IF(COUNT(*) >= 10, "OK", CONCAT("Found too few system user processes: ", COUNT(*))) FROM information_schema.processlist WHERE user = "system user";
+IF(COUNT(*) >= 10, "OK", CONCAT("Found too few system user processes: ", COUNT(*)))
+OK
+include/stop_slave.inc
+SELECT IF(COUNT(*) < 10, "OK", CONCAT("Found too many system user processes: ", COUNT(*))) FROM information_schema.processlist WHERE user = "system user";
+IF(COUNT(*) < 10, "OK", CONCAT("Found too many system user processes: ", COUNT(*)))
+OK
+include/start_slave.inc
+SELECT IF(COUNT(*) >= 10, "OK", CONCAT("Found too few system user processes: ", COUNT(*))) FROM information_schema.processlist WHERE user = "system user";
+IF(COUNT(*) >= 10, "OK", CONCAT("Found too few system user processes: ", COUNT(*)))
+OK
+*** Test long-running query in domain 1 can run in parallel with short queries in domain 0 ***
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=MyISAM;
+CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+INSERT INTO t2 VALUES (1);
+connection server_2;
+connect con_temp1,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+LOCK TABLE t1 WRITE;
+connection server_1;
+SET gtid_domain_id=1;
+INSERT INTO t1 VALUES (2);
+SET gtid_domain_id=0;
+INSERT INTO t2 VALUES (2);
+INSERT INTO t2 VALUES (3);
+BEGIN;
+INSERT INTO t2 VALUES (4);
+INSERT INTO t2 VALUES (5);
+COMMIT;
+INSERT INTO t2 VALUES (6);
+connection server_2;
+SELECT * FROM t2 ORDER by a;
+a
+1
+2
+3
+4
+5
+6
+connection con_temp1;
+SELECT * FROM t1;
+a
+1
+UNLOCK TABLES;
+connection server_2;
+SELECT * FROM t1 ORDER BY a;
+a
+1
+2
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+connection server_1;
+DROP TABLE t1,t2;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_domain.test b/mysql-test/suite/binlog_encryption/rpl_parallel_domain.test
new file mode 100644
index 00000000..8e86bea8
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_domain.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_domain.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_domain_slave_single_grp.result b/mysql-test/suite/binlog_encryption/rpl_parallel_domain_slave_single_grp.result
new file mode 100644
index 00000000..613aac64
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_domain_slave_single_grp.result
@@ -0,0 +1,101 @@
+*** Test two transactions in different domains committed in opposite order on slave but in a single group commit. ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=10;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=MyISAM;
+CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+INSERT INTO t2 VALUES (1);
+connection server_2;
+include/stop_slave.inc
+connection server_1;
+SET sql_log_bin=0;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+SET @old_format= @@SESSION.binlog_format;
+SET binlog_format='statement';
+SET gtid_domain_id=1;
+INSERT INTO t2 VALUES (foo(10,
+'commit_before_enqueue SIGNAL ready1 WAIT_FOR cont1',
+'commit_after_release_LOCK_prepare_ordered SIGNAL ready2'));
+connection server_2;
+FLUSH LOGS;
+SET sql_log_bin=0;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+IF d1 != '' THEN
+SET debug_sync = d1;
+END IF;
+IF d2 != '' THEN
+SET debug_sync = d2;
+END IF;
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+SET @old_format=@@GLOBAL.binlog_format;
+SET GLOBAL binlog_format=statement;
+SET GLOBAL slave_parallel_threads=0;
+SET GLOBAL slave_parallel_threads=10;
+include/start_slave.inc
+SET debug_sync='now WAIT_FOR ready1';
+connection server_1;
+SET gtid_domain_id=2;
+INSERT INTO t2 VALUES (foo(11,
+'commit_before_enqueue SIGNAL ready3 WAIT_FOR cont3',
+'commit_after_release_LOCK_prepare_ordered SIGNAL ready4 WAIT_FOR cont4'));
+SET gtid_domain_id=0;
+SELECT * FROM t2 WHERE a >= 10 ORDER BY a;
+a
+10
+11
+connection server_2;
+SET debug_sync='now WAIT_FOR ready3';
+SET debug_sync='now SIGNAL cont3';
+SET debug_sync='now WAIT_FOR ready4';
+SET debug_sync='now SIGNAL cont1';
+SET debug_sync='now WAIT_FOR ready2';
+SET debug_sync='now SIGNAL cont4';
+SELECT * FROM t2 WHERE a >= 10 ORDER BY a;
+a
+10
+11
+include/show_binlog_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+slave-bin.000002 # Binlog_checkpoint # # slave-bin.000002
+slave-bin.000002 # Gtid # # BEGIN GTID #-#-# cid=#
+slave-bin.000002 # Query # # use `test`; INSERT INTO t2 VALUES (foo(11,
+'commit_before_enqueue SIGNAL ready3 WAIT_FOR cont3',
+'commit_after_release_LOCK_prepare_ordered SIGNAL ready4 WAIT_FOR cont4'))
+slave-bin.000002 # Xid # # COMMIT /* XID */
+slave-bin.000002 # Gtid # # BEGIN GTID #-#-# cid=#
+slave-bin.000002 # Query # # use `test`; INSERT INTO t2 VALUES (foo(10,
+'commit_before_enqueue SIGNAL ready1 WAIT_FOR cont1',
+'commit_after_release_LOCK_prepare_ordered SIGNAL ready2'))
+slave-bin.000002 # Xid # # COMMIT /* XID */
+FLUSH LOGS;
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+SET DEBUG_SYNC= 'RESET';
+SET GLOBAL binlog_format=@old_format;
+connection server_1;
+DROP function foo;
+DROP TABLE t1,t2;
+SET DEBUG_SYNC= 'RESET';
+SET GLOBAL binlog_format=@old_format;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_domain_slave_single_grp.test b/mysql-test/suite/binlog_encryption/rpl_parallel_domain_slave_single_grp.test
new file mode 100644
index 00000000..6f45f982
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_domain_slave_single_grp.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_domain_slave_single_grp.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_free_deferred_event.result b/mysql-test/suite/binlog_encryption/rpl_parallel_free_deferred_event.result
new file mode 100644
index 00000000..6718561a
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_free_deferred_event.result
@@ -0,0 +1,44 @@
+*** MDEV-5788 Incorrect free of rgi->deferred_events in parallel replication ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+include/stop_slave.inc
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
+connection server_2;
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+include/stop_slave.inc
+SET GLOBAL replicate_ignore_table="test.t3";
+SET GLOBAL slave_parallel_threads=2;
+include/start_slave.inc
+connection server_1;
+INSERT INTO t3 VALUES (100, rand());
+INSERT INTO t3 VALUES (101, rand());
+connection server_2;
+connection server_1;
+INSERT INTO t3 VALUES (102, rand());
+INSERT INTO t3 VALUES (103, rand());
+INSERT INTO t3 VALUES (104, rand());
+INSERT INTO t3 VALUES (105, rand());
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL replicate_ignore_table="";
+include/start_slave.inc
+connection server_1;
+INSERT INTO t3 VALUES (106, rand());
+INSERT INTO t3 VALUES (107, rand());
+connection server_2;
+SELECT * FROM t3 WHERE a >= 100 ORDER BY a;
+a b
+106 #
+107 #
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+connection server_1;
+DROP TABLE t3;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_free_deferred_event.test b/mysql-test/suite/binlog_encryption/rpl_parallel_free_deferred_event.test
new file mode 100644
index 00000000..aa31efb5
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_free_deferred_event.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_free_deferred_event.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_gco_wait_kill.result b/mysql-test/suite/binlog_encryption/rpl_parallel_gco_wait_kill.result
new file mode 100644
index 00000000..f12d1944
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_gco_wait_kill.result
@@ -0,0 +1,263 @@
+*** Test killing thread that is waiting to start transaction until previous transaction commits ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+SET @old_parallel_mode= @@GLOBAL.slave_parallel_mode;
+include/stop_slave.inc
+SET sql_log_bin=0;
+CALL mtr.add_suppression("Query execution was interrupted");
+CALL mtr.add_suppression("Slave: Connection was killed");
+CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends");
+SET sql_log_bin=1;
+SET GLOBAL slave_parallel_threads=10;
+SET GLOBAL slave_parallel_mode= 'conservative';
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+connect con_temp3,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+connect con_temp4,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+connect con_temp5,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
+INSERT INTO t3 VALUES(100, 100);
+connection server_2;
+connection server_1;
+SET sql_log_bin=0;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+connection server_2;
+SET sql_log_bin=0;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+IF d1 != '' THEN
+SET debug_sync = d1;
+END IF;
+IF d2 != '' THEN
+SET debug_sync = d2;
+END IF;
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=0;
+SET GLOBAL slave_parallel_threads=4;
+include/start_slave.inc
+connection server_1;
+SET gtid_domain_id=2;
+BEGIN;
+INSERT INTO t3 VALUES (70, foo(70,
+'rpl_parallel_start_waiting_for_prior SIGNAL t4_waiting', ''));
+INSERT INTO t3 VALUES (60, foo(60,
+'ha_write_row_end SIGNAL d2_query WAIT_FOR d2_cont2',
+'rpl_parallel_end_of_group SIGNAL d2_done WAIT_FOR d2_cont'));
+COMMIT;
+SET gtid_domain_id=0;
+connection server_2;
+SET debug_sync='now WAIT_FOR d2_query';
+connection server_1;
+SET gtid_domain_id=1;
+BEGIN;
+INSERT INTO t3 VALUES (61, foo(61,
+'rpl_parallel_start_waiting_for_prior SIGNAL t3_waiting',
+'rpl_parallel_start_waiting_for_prior_killed SIGNAL t3_killed'));
+INSERT INTO t3 VALUES (62, foo(62,
+'ha_write_row_end SIGNAL d1_query WAIT_FOR d1_cont2',
+'rpl_parallel_end_of_group SIGNAL d1_done WAIT_FOR d1_cont'));
+COMMIT;
+SET gtid_domain_id=0;
+connection server_2;
+SET debug_sync='now WAIT_FOR d1_query';
+connection server_1;
+SET gtid_domain_id=0;
+INSERT INTO t3 VALUES (63, foo(63,
+'ha_write_row_end SIGNAL d0_query WAIT_FOR d0_cont2',
+'rpl_parallel_end_of_group SIGNAL d0_done WAIT_FOR d0_cont'));
+connection server_2;
+SET debug_sync='now WAIT_FOR d0_query';
+connection server_1;
+SET gtid_domain_id=3;
+BEGIN;
+INSERT INTO t3 VALUES (68, foo(68,
+'rpl_parallel_start_waiting_for_prior SIGNAL t2_waiting', ''));
+INSERT INTO t3 VALUES (69, foo(69,
+'ha_write_row_end SIGNAL d3_query WAIT_FOR d3_cont2',
+'rpl_parallel_end_of_group SIGNAL d3_done WAIT_FOR d3_cont'));
+COMMIT;
+SET gtid_domain_id=0;
+connection server_2;
+SET debug_sync='now WAIT_FOR d3_query';
+SET debug_sync='now SIGNAL d2_cont2';
+SET debug_sync='now WAIT_FOR d2_done';
+SET debug_sync='now SIGNAL d1_cont2';
+SET debug_sync='now WAIT_FOR d1_done';
+SET debug_sync='now SIGNAL d0_cont2';
+SET debug_sync='now WAIT_FOR d0_done';
+SET debug_sync='now SIGNAL d3_cont2';
+SET debug_sync='now WAIT_FOR d3_done';
+connection con_temp3;
+INSERT INTO t3 VALUES (64, foo(64,
+'rpl_parallel_before_mark_start_commit SIGNAL t1_waiting WAIT_FOR t1_cont', ''));
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2 WAIT_FOR master_cont2';
+INSERT INTO t3 VALUES (65, foo(65, '', ''));
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued2';
+connection con_temp4;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3';
+INSERT INTO t3 VALUES (66, foo(66, '', ''));
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued3';
+connection con_temp5;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued4';
+INSERT INTO t3 VALUES (67, foo(67, '', ''));
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued4';
+SET debug_sync='now SIGNAL master_cont2';
+connection con_temp3;
+connection con_temp4;
+connection con_temp5;
+connection server_1;
+SELECT * FROM t3 WHERE a >= 60 ORDER BY a;
+a b
+60 60
+61 61
+62 62
+63 63
+64 64
+65 65
+66 66
+67 67
+68 68
+69 69
+70 70
+100 100
+SET debug_sync='RESET';
+connection server_2;
+SET debug_sync='now SIGNAL d0_cont';
+SET debug_sync='now WAIT_FOR t1_waiting';
+SET debug_sync='now SIGNAL d3_cont';
+SET debug_sync='now WAIT_FOR t2_waiting';
+SET debug_sync='now SIGNAL d1_cont';
+SET debug_sync='now WAIT_FOR t3_waiting';
+SET debug_sync='now SIGNAL d2_cont';
+SET debug_sync='now WAIT_FOR t4_waiting';
+KILL THD_ID;
+SET debug_sync='now WAIT_FOR t3_killed';
+SET debug_sync='now SIGNAL t1_cont';
+include/wait_for_slave_sql_error.inc [errno=1317,1927,1964]
+STOP SLAVE IO_THREAD;
+SELECT * FROM t3 WHERE a >= 60 AND a != 65 ORDER BY a;
+a b
+60 60
+61 61
+62 62
+63 63
+64 64
+68 68
+69 69
+70 70
+100 100
+SET debug_sync='RESET';
+SET GLOBAL slave_parallel_threads=0;
+SET GLOBAL slave_parallel_threads=10;
+SET sql_log_bin=0;
+DROP FUNCTION foo;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+connection server_1;
+UPDATE t3 SET b=b+1 WHERE a=60;
+connection server_2;
+include/start_slave.inc
+SELECT * FROM t3 WHERE a >= 60 ORDER BY a;
+a b
+60 61
+61 61
+62 62
+63 63
+64 64
+65 65
+66 66
+67 67
+68 68
+69 69
+70 70
+100 100
+SET sql_log_bin=0;
+DROP FUNCTION foo;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+IF d1 != '' THEN
+SET debug_sync = d1;
+END IF;
+IF d2 != '' THEN
+SET debug_sync = d2;
+END IF;
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=0;
+SET GLOBAL slave_parallel_threads=10;
+include/start_slave.inc
+*** 5. Test killing thread that is waiting for queue of max length to shorten ***
+SET @old_max_queued= @@GLOBAL.slave_parallel_max_queued;
+SET GLOBAL slave_parallel_max_queued=9000;
+connection server_1;
+INSERT INTO t3 VALUES (80, foo(0,
+'ha_write_row_end SIGNAL query_waiting WAIT_FOR query_cont', ''));
+connection server_2;
+SET debug_sync='now WAIT_FOR query_waiting';
+SET @old_dbug= @@GLOBAL.debug_dbug;
+SET GLOBAL debug_dbug="+d,rpl_parallel_wait_queue_max";
+connection server_1;
+SELECT * FROM t3 WHERE a >= 80 ORDER BY a;
+a b
+80 0
+81 10000
+100 100
+connection server_2;
+SET debug_sync='now WAIT_FOR wait_queue_ready';
+KILL THD_ID;
+SET debug_sync='now WAIT_FOR wait_queue_killed';
+SET debug_sync='now SIGNAL query_cont';
+include/wait_for_slave_sql_error.inc [errno=1317,1927,1964]
+STOP SLAVE IO_THREAD;
+SET GLOBAL debug_dbug=@old_dbug;
+SET GLOBAL slave_parallel_max_queued= @old_max_queued;
+connection server_1;
+INSERT INTO t3 VALUES (82,0);
+connection server_2;
+SET debug_sync='RESET';
+include/start_slave.inc
+SELECT * FROM t3 WHERE a >= 80 ORDER BY a;
+a b
+80 0
+81 10000
+82 0
+100 100
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_mode=@old_parallel_mode;
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+SET DEBUG_SYNC= 'RESET';
+connection server_1;
+DROP function foo;
+DROP TABLE t3;
+SET DEBUG_SYNC= 'RESET';
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_gco_wait_kill.test b/mysql-test/suite/binlog_encryption/rpl_parallel_gco_wait_kill.test
new file mode 100644
index 00000000..84655914
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_gco_wait_kill.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_gco_wait_kill.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_gtid_slave_pos_update_fail.result b/mysql-test/suite/binlog_encryption/rpl_parallel_gtid_slave_pos_update_fail.result
new file mode 100644
index 00000000..2e7e7f54
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_gtid_slave_pos_update_fail.result
@@ -0,0 +1,65 @@
+include/master-slave.inc
+[connection master]
+connection server_2;
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=10;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t4 (a INT PRIMARY KEY, b INT, KEY b_idx(b)) ENGINE=InnoDB;
+INSERT INTO t4 VALUES (1,NULL), (2,2), (3,NULL), (4,4), (5, NULL), (6, 6);
+connect con1,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+connect con2,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+connection server_2;
+include/stop_slave.inc
+connection con1;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1';
+UPDATE t4 SET b=NULL WHERE a=6;
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued1';
+connection con2;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2';
+DELETE FROM t4 WHERE b <= 1;
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued2';
+SET debug_sync='now SIGNAL master_cont1';
+connection con1;
+connection con2;
+SET debug_sync='RESET';
+connection server_2;
+SET @old_dbug= @@GLOBAL.debug_dbug;
+SET GLOBAL debug_dbug="+d,disable_thd_need_ordering_with";
+include/start_slave.inc
+SET GLOBAL debug_dbug=@old_dbug;
+SELECT * FROM t4 ORDER BY a;
+a b
+1 NULL
+2 2
+3 NULL
+4 4
+5 NULL
+6 NULL
+SET @last_gtid= 'GTID';
+SELECT IF(@@gtid_slave_pos LIKE CONCAT('%',@last_gtid,'%'), "GTID found ok",
+CONCAT("GTID ", @last_gtid, " not found in gtid_slave_pos=", @@gtid_slave_pos))
+AS result;
+result
+GTID found ok
+SELECT "ROW FOUND" AS `Is the row found?`
+ FROM mysql.gtid_slave_pos
+WHERE CONCAT(domain_id, "-", server_id, "-", seq_no) = @last_gtid;
+Is the row found?
+ROW FOUND
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+SET DEBUG_SYNC= 'RESET';
+connection server_1;
+DROP TABLE t4;
+SET DEBUG_SYNC= 'RESET';
+disconnect con1;
+disconnect con2;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_gtid_slave_pos_update_fail.test b/mysql-test/suite/binlog_encryption/rpl_parallel_gtid_slave_pos_update_fail.test
new file mode 100644
index 00000000..f259b5a7
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_gtid_slave_pos_update_fail.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_gtid_slave_pos_update_fail.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_ignore_error_on_rotate.result b/mysql-test/suite/binlog_encryption/rpl_parallel_ignore_error_on_rotate.result
new file mode 100644
index 00000000..d00740db
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_ignore_error_on_rotate.result
@@ -0,0 +1,74 @@
+*** MDEV-6551: Some replication errors are ignored if slave_parallel_threads > 0 ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+include/stop_slave.inc
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+SET @old_parallel_mode=@@GLOBAL.slave_parallel_mode;
+SET GLOBAL slave_parallel_threads=1;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends");
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB;
+SET gtid_domain_id=1;
+INSERT INTO t2 VALUES (1);
+SET gtid_domain_id=0;
+SET gtid_domain_id=2;
+INSERT INTO t2 VALUES (2);
+SET gtid_domain_id=0;
+INSERT INTO t2 VALUES (31);
+include/save_master_gtid.inc
+connection server_2;
+include/sync_with_master_gtid.inc
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads= 0;
+include/start_slave.inc
+SET sql_log_bin= 0;
+INSERT INTO t2 VALUES (32);
+SET sql_log_bin= 1;
+connection server_1;
+INSERT INTO t2 VALUES (32);
+FLUSH LOGS;
+INSERT INTO t2 VALUES (33);
+INSERT INTO t2 VALUES (34);
+SELECT * FROM t2 WHERE a >= 30 ORDER BY a;
+a
+31
+32
+33
+34
+include/save_master_gtid.inc
+connection server_2;
+include/wait_for_slave_sql_error.inc [errno=1062]
+connection server_2;
+include/stop_slave_io.inc
+SET GLOBAL slave_parallel_threads=10;
+START SLAVE;
+include/wait_for_slave_sql_error.inc [errno=1062]
+START SLAVE SQL_THREAD;
+include/wait_for_slave_sql_error.inc [errno=1062]
+SELECT * FROM t2 WHERE a >= 30 ORDER BY a;
+a
+31
+32
+SET sql_slave_skip_counter= 1;
+ERROR HY000: When using parallel replication and GTID with multiple replication domains, @@sql_slave_skip_counter can not be used. Instead, setting @@gtid_slave_pos explicitly can be used to skip to after a given GTID position
+include/stop_slave_io.inc
+include/start_slave.inc
+include/sync_with_master_gtid.inc
+SELECT * FROM t2 WHERE a >= 30 ORDER BY a;
+a
+31
+32
+33
+34
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+SET GLOBAL slave_parallel_mode=@old_parallel_mode;
+include/start_slave.inc
+connection server_1;
+DROP TABLE t2;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_ignore_error_on_rotate.test b/mysql-test/suite/binlog_encryption/rpl_parallel_ignore_error_on_rotate.test
new file mode 100644
index 00000000..fe017a7b
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_ignore_error_on_rotate.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_ignore_error_on_rotate.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_ignored_errors.result b/mysql-test/suite/binlog_encryption/rpl_parallel_ignored_errors.result
new file mode 100644
index 00000000..ce11b814
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_ignored_errors.result
@@ -0,0 +1,51 @@
+include/master-slave.inc
+[connection master]
+connection server_2;
+include/stop_slave.inc
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+SET @old_parallel_mode=@@GLOBAL.slave_parallel_mode;
+SET @old_debug= @@GLOBAL.debug_dbug;
+SET GLOBAL slave_parallel_mode='optimistic';
+SET GLOBAL slave_parallel_threads= 3;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends");
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1);
+include/save_master_gtid.inc
+connection server_2;
+include/sync_with_master_gtid.inc
+connect con_temp2,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+BEGIN;
+INSERT INTO t1 VALUES (32);
+connection server_1;
+INSERT INTO t1 VALUES (32);
+connection server_2;
+SET GLOBAL debug_dbug="+d,hold_worker_on_schedule";
+SET debug_sync="debug_sync_action SIGNAL reached_pause WAIT_FOR continue_worker";
+connection server_1;
+SET gtid_seq_no=100;
+INSERT INTO t1 VALUES (33);
+connection server_2;
+SET debug_sync='now WAIT_FOR reached_pause';
+connection server_1;
+INSERT INTO t1 VALUES (34);
+connection server_2;
+connection con_temp2;
+COMMIT;
+connection server_2;
+include/stop_slave.inc
+include/assert.inc [table t1 should have zero rows where a>32]
+SELECT * FROM t1 WHERE a>32;
+a
+DELETE FROM t1 WHERE a=32;
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+SET GLOBAL slave_parallel_mode=@old_parallel_mode;
+SET GLOBAL debug_dbug=@old_debug;
+SET DEBUG_SYNC= 'RESET';
+include/start_slave.inc
+connection server_1;
+DROP TABLE t1;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_ignored_errors.test b/mysql-test/suite/binlog_encryption/rpl_parallel_ignored_errors.test
new file mode 100644
index 00000000..0c3e5386
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_ignored_errors.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_ignored_errors.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_incorrect_relay_pos.result b/mysql-test/suite/binlog_encryption/rpl_parallel_incorrect_relay_pos.result
new file mode 100644
index 00000000..6ca7f2b6
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_incorrect_relay_pos.result
@@ -0,0 +1,75 @@
+*** MDEV-7237: Parallel replication: incorrect relaylog position after stop/start the slave ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+include/stop_slave.inc
+CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends");
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+SET @old_parallel_mode=@@GLOBAL.slave_parallel_mode;
+SET GLOBAL slave_parallel_threads=10;
+SET GLOBAL slave_parallel_mode='conservative';
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (40);
+connection server_2;
+connect con_temp2,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+include/stop_slave.inc
+CHANGE MASTER TO master_use_gtid=no;
+SET @old_dbug= @@GLOBAL.debug_dbug;
+SET GLOBAL debug_dbug="+d,rpl_parallel_scheduled_gtid_0_x_100";
+SET GLOBAL debug_dbug="+d,rpl_parallel_wait_for_done_trigger";
+SET GLOBAL slave_parallel_threads=0;
+SET GLOBAL slave_parallel_threads=10;
+connection server_1;
+INSERT INTO t2 VALUES (41);
+INSERT INTO t2 VALUES (42);
+SET @old_format= @@binlog_format;
+SET binlog_format= statement;
+DELETE FROM t2 WHERE a=40;
+SET binlog_format= @old_format;
+INSERT INTO t2 VALUES (43);
+INSERT INTO t2 VALUES (44);
+FLUSH LOGS;
+INSERT INTO t2 VALUES (45);
+SET gtid_seq_no=100;
+INSERT INTO t2 VALUES (46);
+connection con_temp2;
+BEGIN;
+SELECT * FROM t2 WHERE a=40 FOR UPDATE;
+a
+40
+connection server_2;
+include/start_slave.inc
+SET debug_sync= 'now WAIT_FOR scheduled_gtid_0_x_100';
+STOP SLAVE;
+connection con_temp2;
+SET debug_sync= 'now WAIT_FOR wait_for_done_waiting';
+ROLLBACK;
+connection server_2;
+include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t2 WHERE a >= 40 ORDER BY a;
+a
+41
+42
+include/start_slave.inc
+SELECT * FROM t2 WHERE a >= 40 ORDER BY a;
+a
+41
+42
+43
+44
+45
+46
+include/stop_slave.inc
+SET GLOBAL debug_dbug=@old_dbug;
+SET DEBUG_SYNC= 'RESET';
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+SET GLOBAL slave_parallel_mode=@old_parallel_mode;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+DROP TABLE t2;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_incorrect_relay_pos.test b/mysql-test/suite/binlog_encryption/rpl_parallel_incorrect_relay_pos.test
new file mode 100644
index 00000000..ddec96e8
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_incorrect_relay_pos.test
@@ -0,0 +1 @@
+--source suite/rpl/include/rpl_parallel_incorrect_relay_pos.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_innodb_lock_conflict.result b/mysql-test/suite/binlog_encryption/rpl_parallel_innodb_lock_conflict.result
new file mode 100644
index 00000000..1411db16
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_innodb_lock_conflict.result
@@ -0,0 +1,79 @@
+***MDEV-5914: Parallel replication deadlock due to InnoDB lock conflicts ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+SET sql_log_bin=0;
+CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends");
+SET sql_log_bin=1;
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=10;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t4 (a INT PRIMARY KEY, b INT, KEY b_idx(b)) ENGINE=InnoDB;
+INSERT INTO t4 VALUES (1,NULL), (2,2), (3,NULL), (4,4), (5, NULL), (6, 6);
+connect con1,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+connect con2,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+connection con1;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1';
+UPDATE t4 SET b=NULL WHERE a=6;
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued1';
+connection con2;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2';
+DELETE FROM t4 WHERE b <= 3;
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued2';
+SET debug_sync='now SIGNAL master_cont1';
+connection con1;
+connection con2;
+SET debug_sync='RESET';
+connection server_2;
+include/start_slave.inc
+include/stop_slave.inc
+SELECT * FROM t4 ORDER BY a;
+a b
+1 NULL
+3 NULL
+4 4
+5 NULL
+6 NULL
+connection server_1;
+DELETE FROM t4;
+INSERT INTO t4 VALUES (1,NULL), (2,2), (3,NULL), (4,4), (5, NULL), (6, 6);
+connection con1;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1';
+INSERT INTO t4 VALUES (7, NULL);
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued1';
+connection con2;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2';
+DELETE FROM t4 WHERE b <= 3;
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued2';
+SET debug_sync='now SIGNAL master_cont1';
+connection con1;
+connection con2;
+SET debug_sync='RESET';
+connection server_2;
+include/start_slave.inc
+include/stop_slave.inc
+SELECT * FROM t4 ORDER BY a;
+a b
+1 NULL
+3 NULL
+4 4
+5 NULL
+6 6
+7 NULL
+connection server_2;
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+SET DEBUG_SYNC= 'RESET';
+connection server_1;
+disconnect con1;
+disconnect con2;
+DROP TABLE t4;
+SET DEBUG_SYNC= 'RESET';
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_innodb_lock_conflict.test b/mysql-test/suite/binlog_encryption/rpl_parallel_innodb_lock_conflict.test
new file mode 100644
index 00000000..8f8cb25a
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_innodb_lock_conflict.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_innodb_lock_conflict.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_missed_error_handling.result b/mysql-test/suite/binlog_encryption/rpl_parallel_missed_error_handling.result
new file mode 100644
index 00000000..e9d04c02
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_missed_error_handling.result
@@ -0,0 +1,65 @@
+*** MDEV-5921: In parallel replication, an error is not correctly signalled to the next transaction ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+include/stop_slave.inc
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+SET GLOBAL slave_parallel_threads=10;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends");
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
+connection server_2;
+connection server_1;
+INSERT INTO t3 VALUES (110, 1);
+connection server_2;
+SELECT * FROM t3 WHERE a >= 110 ORDER BY a;
+a b
+110 1
+SET sql_log_bin=0;
+INSERT INTO t3 VALUES (111, 666);
+SET sql_log_bin=1;
+connection server_1;
+connect con1,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1';
+INSERT INTO t3 VALUES (111, 2);
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued1';
+connect con2,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2';
+INSERT INTO t3 VALUES (112, 3);
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued2';
+SET debug_sync='now SIGNAL master_cont1';
+connection con1;
+connection con2;
+SET debug_sync='RESET';
+connection server_2;
+include/wait_for_slave_sql_error.inc [errno=1062]
+include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t3 WHERE a >= 110 ORDER BY a;
+a b
+110 1
+111 666
+SET sql_log_bin=0;
+DELETE FROM t3 WHERE a=111 AND b=666;
+SET sql_log_bin=1;
+START SLAVE SQL_THREAD;
+SELECT * FROM t3 WHERE a >= 110 ORDER BY a;
+a b
+110 1
+111 2
+112 3
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+SET DEBUG_SYNC= 'RESET';
+connection server_1;
+disconnect con1;
+disconnect con2;
+DROP TABLE t3;
+SET DEBUG_SYNC= 'RESET';
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_missed_error_handling.test b/mysql-test/suite/binlog_encryption/rpl_parallel_missed_error_handling.test
new file mode 100644
index 00000000..d0eaf07f
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_missed_error_handling.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_missed_error_handling.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_mode.result b/mysql-test/suite/binlog_encryption/rpl_parallel_mode.result
new file mode 100644
index 00000000..313290b1
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_mode.result
@@ -0,0 +1,75 @@
+*** MDEV-6676 - test syntax of @@slave_parallel_mode ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+include/stop_slave.inc
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+SET @old_parallel_mode=@@GLOBAL.slave_parallel_mode;
+SET GLOBAL slave_parallel_threads=10;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB;
+connection server_2;
+Parallel_Mode = 'optimistic'
+include/stop_slave.inc
+SET GLOBAL slave_parallel_mode='aggressive';
+Parallel_Mode = 'aggressive'
+SET GLOBAL slave_parallel_mode='conservative';
+Parallel_Mode = 'conservative'
+*** MDEV-6676 - test that empty parallel_mode does not replicate in parallel ***
+connection server_1;
+INSERT INTO t2 VALUES (1040);
+include/save_master_gtid.inc
+connection server_2;
+SET GLOBAL slave_parallel_mode='none';
+SET @old_dbug= @@GLOBAL.debug_dbug;
+SET GLOBAL debug_dbug="+d,slave_crash_if_parallel_apply";
+include/start_slave.inc
+include/sync_with_master_gtid.inc
+SELECT * FROM t2 WHERE a >= 1040 ORDER BY a;
+a
+1040
+include/stop_slave.inc
+SET GLOBAL debug_dbug=@old_dbug;
+*** MDEV-6676 - test disabling domain-based parallel replication ***
+connection server_1;
+SET gtid_domain_id = 1;
+INSERT INTO t2 VALUES (1041);
+INSERT INTO t2 VALUES (1042);
+INSERT INTO t2 VALUES (1043);
+INSERT INTO t2 VALUES (1044);
+INSERT INTO t2 VALUES (1045);
+INSERT INTO t2 VALUES (1046);
+DELETE FROM t2 WHERE a >= 1041;
+SET gtid_domain_id = 2;
+INSERT INTO t2 VALUES (1041);
+INSERT INTO t2 VALUES (1042);
+INSERT INTO t2 VALUES (1043);
+INSERT INTO t2 VALUES (1044);
+INSERT INTO t2 VALUES (1045);
+INSERT INTO t2 VALUES (1046);
+SET gtid_domain_id = 0;
+include/save_master_gtid.inc
+connection server_2;
+SET GLOBAL slave_parallel_mode=minimal;
+include/start_slave.inc
+include/sync_with_master_gtid.inc
+SELECT * FROM t2 WHERE a >= 1040 ORDER BY a;
+a
+1040
+1041
+1042
+1043
+1044
+1045
+1046
+include/stop_slave.inc
+SET GLOBAL debug_dbug=@old_dbug;
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+SET GLOBAL slave_parallel_mode=@old_parallel_mode;
+include/start_slave.inc
+connection server_1;
+DROP TABLE t2;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_mode.test b/mysql-test/suite/binlog_encryption/rpl_parallel_mode.test
new file mode 100644
index 00000000..37235506
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_mode.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_mode.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_partial_binlog_trans.result b/mysql-test/suite/binlog_encryption/rpl_parallel_partial_binlog_trans.result
new file mode 100644
index 00000000..ab1cac69
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_partial_binlog_trans.result
@@ -0,0 +1,51 @@
+*** MDEV_6435: Incorrect error handling when query binlogged partially on master with "killed" error ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+include/stop_slave.inc
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+SET GLOBAL slave_parallel_threads=1;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t6 (a INT) ENGINE=MyISAM;
+CREATE TRIGGER tr AFTER INSERT ON t6 FOR EACH ROW SET @a = 1;
+connect con1,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+connection con1;
+SET debug_sync='sp_head_execute_before_loop SIGNAL ready WAIT_FOR cont';
+INSERT INTO t6 VALUES (1), (2), (3);
+connection server_1;
+SET debug_sync='now WAIT_FOR ready';
+KILL QUERY CONID;
+SET debug_sync='now SIGNAL cont';
+connection con1;
+ERROR 70100: Query execution was interrupted
+SET debug_sync='RESET';
+connection server_1;
+SET debug_sync='RESET';
+connection server_2;
+include/wait_for_slave_sql_error.inc [errno=1317]
+STOP SLAVE IO_THREAD;
+SET GLOBAL gtid_slave_pos= 'AFTER_ERROR_GTID_POS';
+include/start_slave.inc
+connection server_1;
+INSERT INTO t6 VALUES (4);
+SELECT * FROM t6 ORDER BY a;
+a
+1
+4
+connection server_2;
+SELECT * FROM t6 ORDER BY a;
+a
+4
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+SET DEBUG_SYNC= 'RESET';
+connection server_1;
+DROP TABLE t6;
+SET DEBUG_SYNC= 'RESET';
+disconnect con1;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_partial_binlog_trans.test b/mysql-test/suite/binlog_encryption/rpl_parallel_partial_binlog_trans.test
new file mode 100644
index 00000000..c2b4a1f6
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_partial_binlog_trans.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_partial_binlog_trans.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_record_gtid_wakeup.result b/mysql-test/suite/binlog_encryption/rpl_parallel_record_gtid_wakeup.result
new file mode 100644
index 00000000..cbe53e4f
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_record_gtid_wakeup.result
@@ -0,0 +1,48 @@
+*** MDEV-7929: record_gtid() for non-transactional event group calls wakeup_subsequent_commits() too early, causing slave hang. ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=10;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=MyISAM;
+CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
+connection server_2;
+include/stop_slave.inc
+SET @old_dbug= @@GLOBAL.debug_dbug;
+SET GLOBAL debug_dbug= '+d,inject_record_gtid_serverid_100_sleep';
+connection server_1;
+SET @old_dbug= @@SESSION.debug_dbug;
+SET SESSION debug_dbug="+d,binlog_force_commit_id";
+SET @old_server_id= @@SESSION.server_id;
+SET SESSION server_id= 100;
+SET @commit_id= 10010;
+ALTER TABLE t1 COMMENT "Hulubulu!";
+SET SESSION server_id= @old_server_id;
+INSERT INTO t3 VALUES (130, 0);
+SET @commit_id= 10011;
+INSERT INTO t3 VALUES (131, 0);
+SET SESSION debug_dbug=@old_dbug;
+SELECT * FROM t3 WHERE a >= 130 ORDER BY a;
+a b
+130 0
+131 0
+include/save_master_gtid.inc
+connection server_2;
+include/start_slave.inc
+include/sync_with_master_gtid.inc
+SELECT * FROM t3 WHERE a >= 130 ORDER BY a;
+a b
+130 0
+131 0
+include/stop_slave.inc
+SET GLOBAL debug_dbug= @old_dbug;
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+connection server_1;
+DROP TABLE t1,t3;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_record_gtid_wakeup.test b/mysql-test/suite/binlog_encryption/rpl_parallel_record_gtid_wakeup.test
new file mode 100644
index 00000000..577256bf
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_record_gtid_wakeup.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_record_gtid_wakeup.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_retry_deadlock.result b/mysql-test/suite/binlog_encryption/rpl_parallel_retry_deadlock.result
new file mode 100644
index 00000000..1f5a23db
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_retry_deadlock.result
@@ -0,0 +1,192 @@
+*** MDEV-7326 Server deadlock in connection with parallel replication ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+SET @old_parallel_mode=@@GLOBAL.slave_parallel_mode;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_mode='conservative';
+SET GLOBAL slave_parallel_threads=10;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=MyISAM;
+CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t6 (a INT) ENGINE=MyISAM;
+connection server_2;
+connection server_1;
+SET sql_log_bin=0;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+connection server_2;
+SET sql_log_bin=0;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+IF d1 != '' THEN
+SET debug_sync = d1;
+END IF;
+IF d2 != '' THEN
+SET debug_sync = d2;
+END IF;
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=0;
+SET GLOBAL slave_parallel_threads=3;
+SET GLOBAL debug_dbug="+d,rpl_parallel_simulate_temp_err_xid";
+include/start_slave.inc
+connection server_1;
+SET @old_format= @@SESSION.binlog_format;
+SET binlog_format= STATEMENT;
+INSERT INTO t1 VALUES (foo(50,
+"rpl_parallel_start_waiting_for_prior SIGNAL t3_ready",
+"rpl_parallel_end_of_group SIGNAL prep_ready WAIT_FOR prep_cont"));
+connection server_2;
+SET DEBUG_SYNC= "now WAIT_FOR prep_ready";
+connection server_1;
+INSERT INTO t2 VALUES (foo(50,
+"rpl_parallel_simulate_temp_err_xid SIGNAL t1_ready1 WAIT_FOR t1_cont1",
+"rpl_parallel_retry_after_unmark SIGNAL t1_ready2 WAIT_FOR t1_cont2"));
+connection server_2;
+SET DEBUG_SYNC= "now WAIT_FOR t1_ready1";
+connection server_1;
+INSERT INTO t1 VALUES (foo(51,
+"rpl_parallel_before_mark_start_commit SIGNAL t2_ready1 WAIT_FOR t2_cont1",
+"rpl_parallel_after_mark_start_commit SIGNAL t2_ready2"));
+connection server_2;
+SET DEBUG_SYNC= "now WAIT_FOR t2_ready1";
+SET DEBUG_SYNC= "now SIGNAL t1_cont1";
+SET DEBUG_SYNC= "now WAIT_FOR t1_ready2";
+connection server_1;
+INSERT INTO t1 VALUES (52);
+SET BINLOG_FORMAT= @old_format;
+SELECT * FROM t2 WHERE a>=50 ORDER BY a;
+a
+50
+SELECT * FROM t1 WHERE a>=50 ORDER BY a;
+a
+50
+51
+52
+connection server_2;
+SET DEBUG_SYNC= "now SIGNAL prep_cont";
+SET DEBUG_SYNC= "now WAIT_FOR t3_ready";
+SET DEBUG_SYNC= "now SIGNAL t2_cont1";
+SET DEBUG_SYNC= "now WAIT_FOR t2_ready2";
+SET DEBUG_SYNC= "now SIGNAL t1_cont2";
+connection server_1;
+connection server_2;
+SELECT * FROM t2 WHERE a>=50 ORDER BY a;
+a
+50
+SELECT * FROM t1 WHERE a>=50 ORDER BY a;
+a
+50
+51
+52
+SET DEBUG_SYNC="reset";
+include/stop_slave.inc
+SET GLOBAL debug_dbug=@old_dbug;
+SET GLOBAL slave_parallel_mode=@old_parallel_mode;
+SET GLOBAL slave_parallel_threads=0;
+SET GLOBAL slave_parallel_threads=10;
+include/start_slave.inc
+*** MDEV-7326 Server deadlock in connection with parallel replication ***
+connect con_temp3,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+connect con_temp4,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+connection server_2;
+include/stop_slave.inc
+SET @old_parallel_mode= @@GLOBAL.slave_parallel_mode;
+SET GLOBAL slave_parallel_mode='conservative';
+SET GLOBAL slave_parallel_threads=0;
+SET GLOBAL slave_parallel_threads=3;
+SET GLOBAL debug_dbug="+d,rpl_parallel_simulate_temp_err_xid";
+include/start_slave.inc
+connection server_1;
+SET @old_format= @@SESSION.binlog_format;
+SET binlog_format= STATEMENT;
+INSERT INTO t1 VALUES (foo(60,
+"rpl_parallel_start_waiting_for_prior SIGNAL t3_ready",
+"rpl_parallel_end_of_group SIGNAL prep_ready WAIT_FOR prep_cont"));
+connection server_2;
+SET DEBUG_SYNC= "now WAIT_FOR prep_ready";
+connection server_1;
+INSERT INTO t2 VALUES (foo(60,
+"rpl_parallel_simulate_temp_err_xid SIGNAL t1_ready1 WAIT_FOR t1_cont1",
+"rpl_parallel_retry_after_unmark SIGNAL t1_ready2 WAIT_FOR t1_cont2"));
+connection server_2;
+SET DEBUG_SYNC= "now WAIT_FOR t1_ready1";
+connection con_temp3;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1';
+SET binlog_format=statement;
+INSERT INTO t1 VALUES (foo(61,
+"rpl_parallel_before_mark_start_commit SIGNAL t2_ready1 WAIT_FOR t2_cont1",
+"rpl_parallel_after_mark_start_commit SIGNAL t2_ready2"));
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued1';
+connection con_temp4;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2';
+INSERT INTO t6 VALUES (62);
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued2';
+SET debug_sync='now SIGNAL master_cont1';
+connection con_temp3;
+connection con_temp4;
+connection server_1;
+SET debug_sync='RESET';
+SET BINLOG_FORMAT= @old_format;
+SELECT * FROM t2 WHERE a>=60 ORDER BY a;
+a
+60
+SELECT * FROM t1 WHERE a>=60 ORDER BY a;
+a
+60
+61
+SELECT * FROM t6 WHERE a>=60 ORDER BY a;
+a
+62
+connection server_2;
+SET DEBUG_SYNC= "now WAIT_FOR t2_ready1";
+SET DEBUG_SYNC= "now SIGNAL t1_cont1";
+SET DEBUG_SYNC= "now WAIT_FOR t1_ready2";
+connection server_2;
+SET DEBUG_SYNC= "now SIGNAL prep_cont";
+SET DEBUG_SYNC= "now WAIT_FOR t3_ready";
+SET DEBUG_SYNC= "now SIGNAL t2_cont1";
+SET DEBUG_SYNC= "now WAIT_FOR t2_ready2";
+SET DEBUG_SYNC= "now SIGNAL t1_cont2";
+connection server_1;
+connection server_2;
+SELECT * FROM t2 WHERE a>=60 ORDER BY a;
+a
+60
+SELECT * FROM t1 WHERE a>=60 ORDER BY a;
+a
+60
+61
+SELECT * FROM t6 WHERE a>=60 ORDER BY a;
+a
+62
+SET DEBUG_SYNC="reset";
+include/stop_slave.inc
+SET GLOBAL debug_dbug=@old_dbug;
+SET GLOBAL slave_parallel_mode=@old_parallel_mode;
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+connection server_1;
+DROP function foo;
+DROP TABLE t1,t2,t6;
+disconnect con_temp3;
+disconnect con_temp4;
+SET DEBUG_SYNC= 'RESET';
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_retry_deadlock.test b/mysql-test/suite/binlog_encryption/rpl_parallel_retry_deadlock.test
new file mode 100644
index 00000000..04bfb2b7
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_retry_deadlock.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_retry_deadlock.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_rollback_assert.result b/mysql-test/suite/binlog_encryption/rpl_parallel_rollback_assert.result
new file mode 100644
index 00000000..af9c5f14
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_rollback_assert.result
@@ -0,0 +1,45 @@
+*** MDEV-8725: Assertion on ROLLBACK statement in the binary log ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=10;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=MyISAM;
+CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB;
+connection server_2;
+connection server_1;
+BEGIN;
+INSERT INTO t2 VALUES (2000);
+INSERT INTO t1 VALUES (2000);
+INSERT INTO t2 VALUES (2001);
+ROLLBACK;
+SELECT * FROM t1 WHERE a>=2000 ORDER BY a;
+a
+2000
+SELECT * FROM t2 WHERE a>=2000 ORDER BY a;
+a
+include/save_master_gtid.inc
+connection server_2;
+include/sync_with_master_gtid.inc
+connection server_1;
+INSERT INTO t2 VALUES (2020);
+include/save_master_gtid.inc
+connection server_2;
+include/sync_with_master_gtid.inc
+SELECT * FROM t2 WHERE a>=2000 ORDER BY a;
+a
+2020
+SELECT * FROM t1 WHERE a>=2000 ORDER BY a;
+a
+2000
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+connection server_1;
+DROP TABLE t1,t2;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_rollback_assert.test b/mysql-test/suite/binlog_encryption/rpl_parallel_rollback_assert.test
new file mode 100644
index 00000000..33b1435e
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_rollback_assert.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_rollback_assert.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.cnf b/mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.cnf
new file mode 100644
index 00000000..b8e22e97
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.cnf
@@ -0,0 +1,6 @@
+!include my.cnf
+
+[mysqld.2]
+plugin-load-add= @ENV.FILE_KEY_MANAGEMENT_SO
+loose-file-key-management-filename=@ENV.MYSQLTEST_VARDIR/std_data/keys.txt
+encrypt-binlog
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.result b/mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.result
new file mode 100644
index 00000000..204db2ba
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.result
@@ -0,0 +1,13 @@
+include/master-slave.inc
+[connection master]
+connection slave;
+SET DEBUG_SYNC= 'after_show_binlog_events SIGNAL on_show_binlog_events WAIT_FOR end';
+SHOW BINLOG EVENTS;
+connection slave1;
+SET DEBUG_SYNC= 'now WAIT_FOR on_show_binlog_events';
+FLUSH LOGS;
+SET DEBUG_SYNC= 'now SIGNAL end';
+connection slave;
+SET DEBUG_SYNC= 'RESET';
+connection master;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.test b/mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.test
new file mode 100644
index 00000000..e342e4d6
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_show_binlog_events_purge_logs.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_single_grpcmt.result b/mysql-test/suite/binlog_encryption/rpl_parallel_single_grpcmt.result
new file mode 100644
index 00000000..25fc9a18
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_single_grpcmt.result
@@ -0,0 +1,161 @@
+*** Test that group-committed transactions on the master can replicate in parallel on the slave. ***
+include/master-slave.inc
+[connection master]
+connection server_1;
+SET sql_log_bin=0;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+connection server_2;
+include/stop_slave.inc
+SET sql_log_bin=0;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+IF d1 != '' THEN
+SET debug_sync = d1;
+END IF;
+IF d2 != '' THEN
+SET debug_sync = d2;
+END IF;
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+SET GLOBAL slave_parallel_threads=10;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
+INSERT INTO t3 VALUES (1,1), (3,3), (5,5), (7,7);
+connection server_2;
+connect con_temp1,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+BEGIN;
+INSERT INTO t3 VALUES (2,102);
+connect con_temp2,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+BEGIN;
+INSERT INTO t3 VALUES (4,104);
+connect con_temp3,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1';
+SET binlog_format=statement;
+INSERT INTO t3 VALUES (2, foo(12,
+'commit_after_release_LOCK_prepare_ordered SIGNAL slave_queued1 WAIT_FOR slave_cont1',
+''));
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued1';
+connect con_temp4,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2';
+SET binlog_format=statement;
+INSERT INTO t3 VALUES (4, foo(14,
+'commit_after_release_LOCK_prepare_ordered SIGNAL slave_queued2',
+''));
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued2';
+connect con_temp5,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3';
+SET binlog_format=statement;
+INSERT INTO t3 VALUES (6, foo(16,
+'group_commit_waiting_for_prior SIGNAL slave_queued3',
+''));
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued3';
+SET debug_sync='now SIGNAL master_cont1';
+connection con_temp3;
+connection con_temp4;
+connection con_temp5;
+SET debug_sync='RESET';
+connection server_1;
+SELECT * FROM t3 ORDER BY a;
+a b
+1 1
+2 12
+3 3
+4 14
+5 5
+6 16
+7 7
+include/show_binlog_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000001 # Binlog_checkpoint # # master-bin.000001
+master-bin.000001 # Gtid # # GTID #-#-#
+master-bin.000001 # Query # # use `test`; ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB
+master-bin.000001 # Gtid # # GTID #-#-#
+master-bin.000001 # Query # # use `test`; CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB
+master-bin.000001 # Gtid # # BEGIN GTID #-#-#
+master-bin.000001 # Query # # use `test`; INSERT INTO t3 VALUES (1,1), (3,3), (5,5), (7,7)
+master-bin.000001 # Xid # # COMMIT /* XID */
+master-bin.000001 # Gtid # # BEGIN GTID #-#-# cid=#
+master-bin.000001 # Query # # use `test`; INSERT INTO t3 VALUES (2, foo(12,
+'commit_after_release_LOCK_prepare_ordered SIGNAL slave_queued1 WAIT_FOR slave_cont1',
+''))
+master-bin.000001 # Xid # # COMMIT /* XID */
+master-bin.000001 # Gtid # # BEGIN GTID #-#-# cid=#
+master-bin.000001 # Query # # use `test`; INSERT INTO t3 VALUES (4, foo(14,
+'commit_after_release_LOCK_prepare_ordered SIGNAL slave_queued2',
+''))
+master-bin.000001 # Xid # # COMMIT /* XID */
+master-bin.000001 # Gtid # # BEGIN GTID #-#-# cid=#
+master-bin.000001 # Query # # use `test`; INSERT INTO t3 VALUES (6, foo(16,
+'group_commit_waiting_for_prior SIGNAL slave_queued3',
+''))
+master-bin.000001 # Xid # # COMMIT /* XID */
+connection server_2;
+SET debug_sync='now WAIT_FOR slave_queued3';
+connection con_temp1;
+ROLLBACK;
+connection server_2;
+SET debug_sync='now WAIT_FOR slave_queued1';
+connection con_temp2;
+ROLLBACK;
+connection server_2;
+SET debug_sync='now WAIT_FOR slave_queued2';
+SET debug_sync='now SIGNAL slave_cont1';
+SELECT * FROM t3 ORDER BY a;
+a b
+1 1
+2 12
+3 3
+4 14
+5 5
+6 16
+7 7
+include/show_binlog_events.inc
+Log_name Pos Event_type Server_id End_log_pos Info
+slave-bin.000001 # Gtid # # GTID #-#-#
+slave-bin.000001 # Query # # use `test`; ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB
+slave-bin.000001 # Gtid # # GTID #-#-#
+slave-bin.000001 # Query # # use `test`; CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB
+slave-bin.000001 # Gtid # # BEGIN GTID #-#-#
+slave-bin.000001 # Query # # use `test`; INSERT INTO t3 VALUES (1,1), (3,3), (5,5), (7,7)
+slave-bin.000001 # Xid # # COMMIT /* XID */
+slave-bin.000001 # Gtid # # BEGIN GTID #-#-# cid=#
+slave-bin.000001 # Query # # use `test`; INSERT INTO t3 VALUES (2, foo(12,
+'commit_after_release_LOCK_prepare_ordered SIGNAL slave_queued1 WAIT_FOR slave_cont1',
+''))
+slave-bin.000001 # Xid # # COMMIT /* XID */
+slave-bin.000001 # Gtid # # BEGIN GTID #-#-# cid=#
+slave-bin.000001 # Query # # use `test`; INSERT INTO t3 VALUES (4, foo(14,
+'commit_after_release_LOCK_prepare_ordered SIGNAL slave_queued2',
+''))
+slave-bin.000001 # Xid # # COMMIT /* XID */
+slave-bin.000001 # Gtid # # BEGIN GTID #-#-# cid=#
+slave-bin.000001 # Query # # use `test`; INSERT INTO t3 VALUES (6, foo(16,
+'group_commit_waiting_for_prior SIGNAL slave_queued3',
+''))
+slave-bin.000001 # Xid # # COMMIT /* XID */
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+SET DEBUG_SYNC= 'RESET';
+connection server_1;
+DROP function foo;
+DROP TABLE t3;
+SET DEBUG_SYNC= 'RESET';
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_single_grpcmt.test b/mysql-test/suite/binlog_encryption/rpl_parallel_single_grpcmt.test
new file mode 100644
index 00000000..50379b89
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_single_grpcmt.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_single_grpcmt.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_slave_bgc_kill.result b/mysql-test/suite/binlog_encryption/rpl_parallel_slave_bgc_kill.result
new file mode 100644
index 00000000..ba131ea0
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_slave_bgc_kill.result
@@ -0,0 +1,333 @@
+*** Test killing slave threads at various wait points ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+SET @old_parallel_mode=@@GLOBAL.slave_parallel_mode;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=10;
+SET GLOBAL slave_parallel_mode='conservative';
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+connect con_temp3,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+connect con_temp4,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+connect con_temp5,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=MyISAM;
+CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
+INSERT INTO t2 VALUES(100);
+INSERT INTO t3 VALUES(100, 100);
+connection server_2;
+connection server_1;
+SET sql_log_bin=0;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+connection server_2;
+SET sql_log_bin=0;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+IF d1 != '' THEN
+SET debug_sync = d1;
+END IF;
+IF d2 != '' THEN
+SET debug_sync = d2;
+END IF;
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+*** 1. Test killing transaction waiting in commit for previous transaction to commit ***
+connection con_temp3;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1';
+INSERT INTO t3 VALUES (31, foo(31,
+'commit_before_prepare_ordered WAIT_FOR t2_waiting',
+'commit_after_prepare_ordered SIGNAL t1_ready WAIT_FOR t1_cont'));
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued1';
+connection con_temp4;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2';
+BEGIN;
+INSERT INTO t3 VALUES (32, foo(32,
+'ha_write_row_end SIGNAL t2_query WAIT_FOR t2_cont',
+''));
+INSERT INTO t3 VALUES (33, foo(33,
+'group_commit_waiting_for_prior SIGNAL t2_waiting',
+'group_commit_waiting_for_prior_killed SIGNAL t2_killed'));
+COMMIT;
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued2';
+connection con_temp5;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3';
+INSERT INTO t3 VALUES (34, foo(34,
+'',
+''));
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued3';
+SET debug_sync='now SIGNAL master_cont1';
+connection con_temp3;
+connection con_temp4;
+connection con_temp5;
+connection server_1;
+SELECT * FROM t3 WHERE a >= 30 ORDER BY a;
+a b
+31 31
+32 32
+33 33
+34 34
+100 100
+SET debug_sync='RESET';
+connection server_2;
+SET sql_log_bin=0;
+CALL mtr.add_suppression("Query execution was interrupted");
+CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends");
+CALL mtr.add_suppression("Slave: Connection was killed");
+SET sql_log_bin=1;
+SET debug_sync='now WAIT_FOR t2_query';
+SET debug_sync='now SIGNAL t2_cont';
+SET debug_sync='now WAIT_FOR t1_ready';
+KILL THD_ID;
+SET debug_sync='now WAIT_FOR t2_killed';
+SET debug_sync='now SIGNAL t1_cont';
+include/wait_for_slave_sql_error.inc [errno=1317,1927,1964]
+STOP SLAVE IO_THREAD;
+SELECT * FROM t3 WHERE a >= 30 ORDER BY a;
+a b
+31 31
+100 100
+SET debug_sync='RESET';
+SET GLOBAL slave_parallel_threads=0;
+SET GLOBAL slave_parallel_threads=10;
+SET sql_log_bin=0;
+DROP FUNCTION foo;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+connection server_1;
+INSERT INTO t3 VALUES (39,0);
+connection server_2;
+include/start_slave.inc
+SELECT * FROM t3 WHERE a >= 30 ORDER BY a;
+a b
+31 31
+32 32
+33 33
+34 34
+39 0
+100 100
+SET sql_log_bin=0;
+DROP FUNCTION foo;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+IF d1 != '' THEN
+SET debug_sync = d1;
+END IF;
+IF d2 != '' THEN
+SET debug_sync = d2;
+END IF;
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=0;
+SET GLOBAL slave_parallel_threads=10;
+include/start_slave.inc
+*** 2. Same as (1), but without restarting IO thread after kill of SQL threads ***
+connection con_temp3;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1';
+INSERT INTO t3 VALUES (41, foo(41,
+'commit_before_prepare_ordered WAIT_FOR t2_waiting',
+'commit_after_prepare_ordered SIGNAL t1_ready WAIT_FOR t1_cont'));
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued1';
+connection con_temp4;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2';
+BEGIN;
+INSERT INTO t3 VALUES (42, foo(42,
+'ha_write_row_end SIGNAL t2_query WAIT_FOR t2_cont',
+''));
+INSERT INTO t3 VALUES (43, foo(43,
+'group_commit_waiting_for_prior SIGNAL t2_waiting',
+'group_commit_waiting_for_prior_killed SIGNAL t2_killed'));
+COMMIT;
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued2';
+connection con_temp5;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3';
+INSERT INTO t3 VALUES (44, foo(44,
+'',
+''));
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued3';
+SET debug_sync='now SIGNAL master_cont1';
+connection con_temp3;
+connection con_temp4;
+connection con_temp5;
+connection server_1;
+SELECT * FROM t3 WHERE a >= 40 ORDER BY a;
+a b
+41 41
+42 42
+43 43
+44 44
+100 100
+SET debug_sync='RESET';
+connection server_2;
+SET debug_sync='now WAIT_FOR t2_query';
+SET debug_sync='now SIGNAL t2_cont';
+SET debug_sync='now WAIT_FOR t1_ready';
+KILL THD_ID;
+SET debug_sync='now WAIT_FOR t2_killed';
+SET debug_sync='now SIGNAL t1_cont';
+include/wait_for_slave_sql_error.inc [errno=1317,1927,1964]
+SET debug_sync='RESET';
+SET GLOBAL slave_parallel_threads=0;
+SET GLOBAL slave_parallel_threads=10;
+SET sql_log_bin=0;
+DROP FUNCTION foo;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+connection server_1;
+INSERT INTO t3 VALUES (49,0);
+connection server_2;
+START SLAVE SQL_THREAD;
+SELECT * FROM t3 WHERE a >= 40 ORDER BY a;
+a b
+41 41
+42 42
+43 43
+44 44
+49 0
+100 100
+SET sql_log_bin=0;
+DROP FUNCTION foo;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+IF d1 != '' THEN
+SET debug_sync = d1;
+END IF;
+IF d2 != '' THEN
+SET debug_sync = d2;
+END IF;
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=0;
+SET GLOBAL slave_parallel_threads=10;
+include/start_slave.inc
+*** 3. Same as (2), but not using gtid mode ***
+connection server_2;
+include/stop_slave.inc
+CHANGE MASTER TO master_use_gtid=no;
+include/start_slave.inc
+connection server_1;
+connection con_temp3;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1';
+INSERT INTO t3 VALUES (51, foo(51,
+'commit_before_prepare_ordered WAIT_FOR t2_waiting',
+'commit_after_prepare_ordered SIGNAL t1_ready WAIT_FOR t1_cont'));
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued1';
+connection con_temp4;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2';
+BEGIN;
+INSERT INTO t3 VALUES (52, foo(52,
+'ha_write_row_end SIGNAL t2_query WAIT_FOR t2_cont',
+''));
+INSERT INTO t3 VALUES (53, foo(53,
+'group_commit_waiting_for_prior SIGNAL t2_waiting',
+'group_commit_waiting_for_prior_killed SIGNAL t2_killed'));
+COMMIT;
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued2';
+connection con_temp5;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3';
+INSERT INTO t3 VALUES (54, foo(54,
+'',
+''));
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued3';
+SET debug_sync='now SIGNAL master_cont1';
+connection con_temp3;
+connection con_temp4;
+connection con_temp5;
+connection server_1;
+SELECT * FROM t3 WHERE a >= 50 ORDER BY a;
+a b
+51 51
+52 52
+53 53
+54 54
+100 100
+SET debug_sync='RESET';
+connection server_2;
+SET debug_sync='now WAIT_FOR t2_query';
+SET debug_sync='now SIGNAL t2_cont';
+SET debug_sync='now WAIT_FOR t1_ready';
+KILL THD_ID;
+SET debug_sync='now WAIT_FOR t2_killed';
+SET debug_sync='now SIGNAL t1_cont';
+include/wait_for_slave_sql_error.inc [errno=1317,1927,1964]
+SELECT * FROM t3 WHERE a >= 50 ORDER BY a;
+a b
+51 51
+100 100
+SET debug_sync='RESET';
+SET GLOBAL slave_parallel_threads=0;
+SET GLOBAL slave_parallel_threads=10;
+SET sql_log_bin=0;
+DROP FUNCTION foo;
+CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500))
+RETURNS INT DETERMINISTIC
+BEGIN
+RETURN x;
+END
+||
+SET sql_log_bin=1;
+connection server_1;
+INSERT INTO t3 VALUES (59,0);
+connection server_2;
+START SLAVE SQL_THREAD;
+SELECT * FROM t3 WHERE a >= 50 ORDER BY a;
+a b
+51 51
+52 52
+53 53
+54 54
+59 0
+100 100
+connection server_2;
+include/stop_slave.inc
+CHANGE MASTER TO master_use_gtid=slave_pos;
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+SET GLOBAL slave_parallel_mode=@old_parallel_mode;
+include/start_slave.inc
+SET DEBUG_SYNC= 'RESET';
+connection server_1;
+DROP function foo;
+DROP TABLE t1,t2,t3;
+SET DEBUG_SYNC= 'RESET';
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_slave_bgc_kill.test b/mysql-test/suite/binlog_encryption/rpl_parallel_slave_bgc_kill.test
new file mode 100644
index 00000000..c291d607
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_slave_bgc_kill.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_slave_bgc_kill.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_stop_on_con_kill.result b/mysql-test/suite/binlog_encryption/rpl_parallel_stop_on_con_kill.result
new file mode 100644
index 00000000..bf0ed9e4
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_stop_on_con_kill.result
@@ -0,0 +1,102 @@
+*** MDEV-8031: Parallel replication stops on "connection killed" error (probably incorrectly handled deadlock kill) ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=10;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
+INSERT INTO t3 VALUES (201,0), (202,0);
+include/save_master_gtid.inc
+connection server_2;
+include/sync_with_master_gtid.inc
+include/stop_slave.inc
+SET @old_dbug= @@GLOBAL.debug_dbug;
+SET GLOBAL debug_dbug= '+d,inject_mdev8031';
+connection server_1;
+SET @old_dbug= @@SESSION.debug_dbug;
+SET SESSION debug_dbug="+d,binlog_force_commit_id";
+SET @commit_id= 10200;
+INSERT INTO t3 VALUES (203, 1);
+INSERT INTO t3 VALUES (204, 1);
+INSERT INTO t3 VALUES (205, 1);
+UPDATE t3 SET b=b+1 WHERE a=201;
+UPDATE t3 SET b=b+1 WHERE a=201;
+UPDATE t3 SET b=b+1 WHERE a=201;
+UPDATE t3 SET b=b+1 WHERE a=202;
+UPDATE t3 SET b=b+1 WHERE a=202;
+UPDATE t3 SET b=b+1 WHERE a=202;
+UPDATE t3 SET b=b+1 WHERE a=202;
+UPDATE t3 SET b=b+1 WHERE a=203;
+UPDATE t3 SET b=b+1 WHERE a=203;
+UPDATE t3 SET b=b+1 WHERE a=204;
+UPDATE t3 SET b=b+1 WHERE a=204;
+UPDATE t3 SET b=b+1 WHERE a=204;
+UPDATE t3 SET b=b+1 WHERE a=203;
+UPDATE t3 SET b=b+1 WHERE a=205;
+UPDATE t3 SET b=b+1 WHERE a=205;
+SET SESSION debug_dbug=@old_dbug;
+SELECT * FROM t3 WHERE a>=200 ORDER BY a;
+a b
+201 3
+202 4
+203 4
+204 4
+205 3
+include/save_master_gtid.inc
+connection server_2;
+include/start_slave.inc
+include/sync_with_master_gtid.inc
+SELECT * FROM t3 WHERE a>=200 ORDER BY a;
+a b
+201 3
+202 4
+203 4
+204 4
+205 3
+include/stop_slave.inc
+SET GLOBAL debug_dbug= @old_dbug;
+include/start_slave.inc
+*** Check getting deadlock killed inside open_binlog() during retry. ***
+connection server_2;
+include/stop_slave.inc
+SET @old_dbug= @@GLOBAL.debug_dbug;
+SET GLOBAL debug_dbug= '+d,inject_retry_event_group_open_binlog_kill';
+SET @old_max= @@GLOBAL.max_relay_log_size;
+SET GLOBAL max_relay_log_size= 4096;
+connection server_1;
+SET @old_dbug= @@SESSION.debug_dbug;
+SET SESSION debug_dbug="+d,binlog_force_commit_id";
+SET @commit_id= 10210;
+Omit long queries that cause relaylog rotations and transaction retries...
+SET SESSION debug_dbug=@old_dbug;
+SELECT * FROM t3 WHERE a>=200 ORDER BY a;
+a b
+201 6
+202 8
+203 7
+204 7
+205 5
+include/save_master_gtid.inc
+connection server_2;
+include/start_slave.inc
+include/sync_with_master_gtid.inc
+SELECT * FROM t3 WHERE a>=200 ORDER BY a;
+a b
+201 6
+202 8
+203 7
+204 7
+205 5
+include/stop_slave.inc
+SET GLOBAL debug_dbug= @old_debg;
+SET GLOBAL max_relay_log_size= @old_max;
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+connection server_1;
+DROP TABLE t3;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_stop_on_con_kill.test b/mysql-test/suite/binlog_encryption/rpl_parallel_stop_on_con_kill.test
new file mode 100644
index 00000000..b5b2a09b
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_stop_on_con_kill.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_stop_on_con_kill.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_stop_slave.result b/mysql-test/suite/binlog_encryption/rpl_parallel_stop_slave.result
new file mode 100644
index 00000000..0c810d2a
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_stop_slave.result
@@ -0,0 +1,91 @@
+*** Test STOP SLAVE in parallel mode ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+SET @old_parallel_mode=@@GLOBAL.slave_parallel_mode;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=10;
+SET GLOBAL slave_parallel_mode='conservative';
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connect con_temp1,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+connect con_temp2,127.0.0.1,root,,test,$SERVER_MYPORT_2,;
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=MyISAM;
+CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
+INSERT INTO t2 VALUES(100);
+INSERT INTO t3 VALUES(100, 100);
+connection server_2;
+include/stop_slave.inc
+connection server_1;
+SET binlog_direct_non_transactional_updates=0;
+SET sql_log_bin=0;
+CALL mtr.add_suppression("Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction");
+SET sql_log_bin=1;
+BEGIN;
+INSERT INTO t2 VALUES (20);
+INSERT INTO t1 VALUES (20);
+INSERT INTO t2 VALUES (21);
+INSERT INTO t3 VALUES (20, 20);
+COMMIT;
+INSERT INTO t3 VALUES(21, 21);
+INSERT INTO t3 VALUES(22, 22);
+connection con_temp1;
+BEGIN;
+INSERT INTO t2 VALUES (21);
+connection server_2;
+START SLAVE;
+connection con_temp2;
+SET @old_dbug= @@GLOBAL.debug_dbug;
+SET GLOBAL debug_dbug="+d,rpl_parallel_wait_for_done_trigger";
+STOP SLAVE;
+connection con_temp1;
+SET debug_sync='now WAIT_FOR wait_for_done_waiting';
+ROLLBACK;
+connection con_temp2;
+SET GLOBAL debug_dbug=@old_dbug;
+SET debug_sync='RESET';
+connection server_2;
+include/wait_for_slave_to_stop.inc
+SELECT * FROM t1 WHERE a >= 20 ORDER BY a;
+a
+20
+SELECT * FROM t2 WHERE a >= 20 ORDER BY a;
+a
+20
+21
+100
+SELECT * FROM t3 WHERE a >= 20 ORDER BY a;
+a b
+20 20
+100 100
+include/start_slave.inc
+SELECT * FROM t1 WHERE a >= 20 ORDER BY a;
+a
+20
+SELECT * FROM t2 WHERE a >= 20 ORDER BY a;
+a
+20
+21
+100
+SELECT * FROM t3 WHERE a >= 20 ORDER BY a;
+a b
+20 20
+21 21
+22 22
+100 100
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_mode=@old_parallel_mode;
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+SET DEBUG_SYNC= 'RESET';
+disconnect con_temp1;
+disconnect con_temp2;
+connection server_1;
+DROP TABLE t1,t2,t3;
+SET DEBUG_SYNC= 'RESET';
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_stop_slave.test b/mysql-test/suite/binlog_encryption/rpl_parallel_stop_slave.test
new file mode 100644
index 00000000..a7a9c3b9
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_stop_slave.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_stop_slave.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_wrong_binlog_order.result b/mysql-test/suite/binlog_encryption/rpl_parallel_wrong_binlog_order.result
new file mode 100644
index 00000000..f6781f64
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_wrong_binlog_order.result
@@ -0,0 +1,75 @@
+*** MDEV-6775: Wrong binlog order in parallel replication ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=10;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t4 (a INT PRIMARY KEY, b INT, KEY b_idx(b)) ENGINE=InnoDB;
+INSERT INTO t4 VALUES (1,NULL), (3,NULL), (4,4), (5, NULL), (6, 6);
+connect con1,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+connect con2,127.0.0.1,root,,test,$SERVER_MYPORT_1,;
+include/save_master_gtid.inc
+connection server_2;
+include/sync_with_master_gtid.inc
+include/stop_slave.inc
+SET @old_dbug= @@GLOBAL.debug_dbug;
+SET GLOBAL debug_dbug="+d,inject_binlog_commit_before_get_LOCK_log";
+SET @old_format=@@GLOBAL.binlog_format;
+SET GLOBAL binlog_format=ROW;
+SET GLOBAL slave_parallel_threads=0;
+SET GLOBAL slave_parallel_threads=10;
+connection con1;
+SET @old_format= @@binlog_format;
+SET binlog_format= statement;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1';
+UPDATE t4 SET b=NULL WHERE a=6;
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued1';
+connection con2;
+SET @old_format= @@binlog_format;
+SET binlog_format= statement;
+SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2';
+DELETE FROM t4 WHERE b <= 3;
+connection server_1;
+SET debug_sync='now WAIT_FOR master_queued2';
+SET debug_sync='now SIGNAL master_cont1';
+connection con1;
+SET binlog_format= @old_format;
+connection con2;
+SET binlog_format= @old_format;
+SET debug_sync='RESET';
+SELECT * FROM t4 ORDER BY a;
+a b
+1 NULL
+3 NULL
+4 4
+5 NULL
+6 NULL
+connection server_2;
+include/start_slave.inc
+SET debug_sync= 'now WAIT_FOR waiting';
+SELECT * FROM t4 ORDER BY a;
+a b
+1 NULL
+3 NULL
+4 4
+5 NULL
+6 NULL
+SET debug_sync= 'now SIGNAL cont';
+include/stop_slave.inc
+SET GLOBAL debug_dbug=@old_dbug;
+SET GLOBAL binlog_format= @old_format;
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+SET DEBUG_SYNC= 'RESET';
+connection server_1;
+DROP TABLE t4;
+SET DEBUG_SYNC= 'RESET';
+disconnect con1;
+disconnect con2;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_wrong_binlog_order.test b/mysql-test/suite/binlog_encryption/rpl_parallel_wrong_binlog_order.test
new file mode 100644
index 00000000..ac683daf
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_wrong_binlog_order.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_wrong_binlog_order.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_wrong_exec_master_pos.result b/mysql-test/suite/binlog_encryption/rpl_parallel_wrong_exec_master_pos.result
new file mode 100644
index 00000000..47cfa5e0
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_wrong_exec_master_pos.result
@@ -0,0 +1,34 @@
+*** MDEV-5938: Exec_master_log_pos not updated at log rotate in parallel replication ***
+include/master-slave.inc
+[connection master]
+connection server_2;
+include/stop_slave.inc
+SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
+SET GLOBAL slave_parallel_threads=1;
+CHANGE MASTER TO master_use_gtid=slave_pos;
+include/start_slave.inc
+connection server_1;
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+CREATE TABLE t5 (a INT PRIMARY KEY, b INT);
+INSERT INTO t5 VALUES (1,1);
+INSERT INTO t5 VALUES (2,2), (3,8);
+INSERT INTO t5 VALUES (4,16);
+connection server_2;
+test_check
+OK
+test_check
+OK
+connection server_1;
+FLUSH LOGS;
+connection server_2;
+test_check
+OK
+test_check
+OK
+connection server_2;
+include/stop_slave.inc
+SET GLOBAL slave_parallel_threads=@old_parallel_threads;
+include/start_slave.inc
+connection server_1;
+DROP TABLE t5;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_wrong_exec_master_pos.test b/mysql-test/suite/binlog_encryption/rpl_parallel_wrong_exec_master_pos.test
new file mode 100644
index 00000000..ab0e1af5
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_parallel_wrong_exec_master_pos.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_parallel_wrong_exec_master_pos.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_relayrotate-slave.opt b/mysql-test/suite/binlog_encryption/rpl_relayrotate-slave.opt
new file mode 100644
index 00000000..1665aec2
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_relayrotate-slave.opt
@@ -0,0 +1,5 @@
+--max_relay_log_size=16384
+--log-warnings
+--plugin-load-add=$FILE_KEY_MANAGEMENT_SO
+--loose-file-key-management-filename=$MYSQLTEST_VARDIR/std_data/keys.txt
+--encrypt-binlog
diff --git a/mysql-test/suite/binlog_encryption/rpl_relayrotate.result b/mysql-test/suite/binlog_encryption/rpl_relayrotate.result
new file mode 100644
index 00000000..142626e3
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_relayrotate.result
@@ -0,0 +1,20 @@
+include/master-slave.inc
+[connection master]
+connection master;
+connection slave;
+connection slave;
+stop slave;
+connection master;
+create table t1 (a int) engine=innodb;
+connection slave;
+reset slave;
+start slave;
+stop slave;
+start slave;
+select max(a) from t1;
+max(a)
+8000
+connection master;
+drop table t1;
+connection slave;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_relayrotate.test b/mysql-test/suite/binlog_encryption/rpl_relayrotate.test
new file mode 100644
index 00000000..a8dabdc3
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_relayrotate.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_relayrotate.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_semi_sync.result b/mysql-test/suite/binlog_encryption/rpl_semi_sync.result
new file mode 100644
index 00000000..edd5e774
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_semi_sync.result
@@ -0,0 +1,477 @@
+include/master-slave.inc
+[connection master]
+connection master;
+call mtr.add_suppression("Timeout waiting for reply of binlog");
+call mtr.add_suppression("Read semi-sync reply");
+call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.");
+call mtr.add_suppression("mysqld: Got an error reading communication packets");
+connection slave;
+set sql_log_bin=0;
+call mtr.add_suppression("Master server does not support semi-sync");
+call mtr.add_suppression("Semi-sync slave .* reply");
+call mtr.add_suppression("Slave SQL.*Request to stop slave SQL Thread received while applying a group that has non-transactional changes; waiting for completion of the group");
+set sql_log_bin=1;
+connection master;
+#
+# Uninstall semi-sync plugins on master and slave
+#
+connection slave;
+include/stop_slave.inc
+include/reset_slave.inc
+set global rpl_semi_sync_master_enabled= 0;
+set global rpl_semi_sync_slave_enabled= 0;
+connection master;
+reset master;
+set global rpl_semi_sync_master_enabled= 0;
+set global rpl_semi_sync_slave_enabled= 0;
+#
+# Main test of semi-sync replication start here
+#
+connection master;
+set global rpl_semi_sync_master_timeout= 60000;
+[ default state of semi-sync on master should be OFF ]
+show variables like 'rpl_semi_sync_master_enabled';
+Variable_name Value
+rpl_semi_sync_master_enabled OFF
+[ enable semi-sync on master ]
+set global rpl_semi_sync_master_enabled = 1;
+show variables like 'rpl_semi_sync_master_enabled';
+Variable_name Value
+rpl_semi_sync_master_enabled ON
+[ status of semi-sync on master should be ON even without any semi-sync slaves ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name Value
+Rpl_semi_sync_master_clients 0
+show status like 'Rpl_semi_sync_master_status';
+Variable_name Value
+Rpl_semi_sync_master_status ON
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name Value
+Rpl_semi_sync_master_yes_tx 0
+#
+# BUG#45672 Semisync repl: ActiveTranx:insert_tranx_node: transaction node allocation failed
+# BUG#45673 Semisynch reports correct operation even if no slave is connected
+#
+[ status of semi-sync on master should be OFF ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name Value
+Rpl_semi_sync_master_clients 0
+show status like 'Rpl_semi_sync_master_status';
+Variable_name Value
+Rpl_semi_sync_master_status OFF
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name Value
+Rpl_semi_sync_master_yes_tx 0
+reset master;
+connection slave;
+[ default state of semi-sync on slave should be OFF ]
+show variables like 'rpl_semi_sync_slave_enabled';
+Variable_name Value
+rpl_semi_sync_slave_enabled OFF
+[ enable semi-sync on slave ]
+set global rpl_semi_sync_slave_enabled = 1;
+show variables like 'rpl_semi_sync_slave_enabled';
+Variable_name Value
+rpl_semi_sync_slave_enabled ON
+include/start_slave.inc
+connection master;
+[ initial master state after the semi-sync slave connected ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name Value
+Rpl_semi_sync_master_clients 1
+show status like 'Rpl_semi_sync_master_status';
+Variable_name Value
+Rpl_semi_sync_master_status ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name Value
+Rpl_semi_sync_master_no_tx 0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name Value
+Rpl_semi_sync_master_yes_tx 0
+create table t1(a int) engine = ENGINE_TYPE;
+[ master state after CREATE TABLE statement ]
+show status like 'Rpl_semi_sync_master_status';
+Variable_name Value
+Rpl_semi_sync_master_status ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name Value
+Rpl_semi_sync_master_no_tx 0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name Value
+Rpl_semi_sync_master_yes_tx 1
+select CONNECTIONS_NORMAL_SLAVE - CONNECTIONS_NORMAL_SLAVE as 'Should be 0';
+Should be 0
+0
+[ insert records to table ]
+insert t1 values (10);
+insert t1 values (9);
+insert t1 values (8);
+insert t1 values (7);
+insert t1 values (6);
+insert t1 values (5);
+insert t1 values (4);
+insert t1 values (3);
+insert t1 values (2);
+insert t1 values (1);
+[ master status after inserts ]
+show status like 'Rpl_semi_sync_master_status';
+Variable_name Value
+Rpl_semi_sync_master_status ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name Value
+Rpl_semi_sync_master_no_tx 0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name Value
+Rpl_semi_sync_master_yes_tx 11
+connection slave;
+[ slave status after replicated inserts ]
+show status like 'Rpl_semi_sync_slave_status';
+Variable_name Value
+Rpl_semi_sync_slave_status ON
+select count(distinct a) from t1;
+count(distinct a)
+10
+select min(a) from t1;
+min(a)
+1
+select max(a) from t1;
+max(a)
+10
+
+# BUG#50157
+# semi-sync replication crashes when replicating a transaction which
+# include 'CREATE TEMPORARY TABLE `MyISAM_t` SELECT * FROM `Innodb_t` ;
+connection master;
+SET SESSION AUTOCOMMIT= 0;
+CREATE TABLE t2(c1 INT) ENGINE=innodb;
+connection slave;
+connection master;
+BEGIN;
+
+# Even though it is in a transaction, this statement is binlogged into binlog
+# file immediately.
+CREATE TEMPORARY TABLE t3 SELECT c1 FROM t2 where 1=1;
+
+# These statements will not be binlogged until the transaction is committed
+INSERT INTO t2 VALUES(11);
+INSERT INTO t2 VALUES(22);
+COMMIT;
+DROP TABLE t2, t3;
+SET SESSION AUTOCOMMIT= 1;
+connection slave;
+#
+# Test semi-sync master will switch OFF after one transaction
+# timeout waiting for slave reply.
+#
+connection slave;
+include/stop_slave.inc
+connection master;
+include/kill_binlog_dump_threads.inc
+set global rpl_semi_sync_master_timeout= 5000;
+[ master status should be ON ]
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name Value
+Rpl_semi_sync_master_no_tx 0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name Value
+Rpl_semi_sync_master_yes_tx 14
+[ semi-sync replication of these transactions will fail ]
+insert into t1 values (500);
+[ master status should be OFF ]
+show status like 'Rpl_semi_sync_master_status';
+Variable_name Value
+Rpl_semi_sync_master_status OFF
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name Value
+Rpl_semi_sync_master_no_tx 1
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name Value
+Rpl_semi_sync_master_yes_tx 14
+delete from t1 where a=10;
+delete from t1 where a=9;
+delete from t1 where a=8;
+delete from t1 where a=7;
+delete from t1 where a=6;
+delete from t1 where a=5;
+delete from t1 where a=4;
+delete from t1 where a=3;
+delete from t1 where a=2;
+delete from t1 where a=1;
+insert into t1 values (100);
+[ master status should be OFF ]
+show status like 'Rpl_semi_sync_master_status';
+Variable_name Value
+Rpl_semi_sync_master_status OFF
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name Value
+Rpl_semi_sync_master_no_tx 12
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name Value
+Rpl_semi_sync_master_yes_tx 14
+#
+# Test semi-sync status on master will be ON again when slave catches up
+#
+connection slave;
+[ slave status should be OFF ]
+show status like 'Rpl_semi_sync_slave_status';
+Variable_name Value
+Rpl_semi_sync_slave_status OFF
+include/start_slave.inc
+[ slave status should be ON ]
+show status like 'Rpl_semi_sync_slave_status';
+Variable_name Value
+Rpl_semi_sync_slave_status ON
+select count(distinct a) from t1;
+count(distinct a)
+2
+select min(a) from t1;
+min(a)
+100
+select max(a) from t1;
+max(a)
+500
+connection master;
+[ master status should be ON again after slave catches up ]
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name Value
+Rpl_semi_sync_master_no_tx 12
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name Value
+Rpl_semi_sync_master_yes_tx 14
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name Value
+Rpl_semi_sync_master_clients 1
+#
+# Test disable/enable master semi-sync on the fly.
+#
+drop table t1;
+connection slave;
+include/stop_slave.inc
+#
+# Flush status
+#
+connection master;
+[ Semi-sync master status variables before FLUSH STATUS ]
+SHOW STATUS LIKE 'Rpl_semi_sync_master_no_tx';
+Variable_name Value
+Rpl_semi_sync_master_no_tx 12
+SHOW STATUS LIKE 'Rpl_semi_sync_master_yes_tx';
+Variable_name Value
+Rpl_semi_sync_master_yes_tx 15
+FLUSH NO_WRITE_TO_BINLOG STATUS;
+[ Semi-sync master status variables after FLUSH STATUS ]
+SHOW STATUS LIKE 'Rpl_semi_sync_master_no_tx';
+Variable_name Value
+Rpl_semi_sync_master_no_tx 0
+SHOW STATUS LIKE 'Rpl_semi_sync_master_yes_tx';
+Variable_name Value
+Rpl_semi_sync_master_yes_tx 0
+connection master;
+show master logs;
+Log_name master-bin.000001
+File_size #
+show variables like 'rpl_semi_sync_master_enabled';
+Variable_name Value
+rpl_semi_sync_master_enabled ON
+[ disable semi-sync on the fly ]
+set global rpl_semi_sync_master_enabled=0;
+show variables like 'rpl_semi_sync_master_enabled';
+Variable_name Value
+rpl_semi_sync_master_enabled OFF
+show status like 'Rpl_semi_sync_master_status';
+Variable_name Value
+Rpl_semi_sync_master_status OFF
+[ enable semi-sync on the fly ]
+set global rpl_semi_sync_master_enabled=1;
+show variables like 'rpl_semi_sync_master_enabled';
+Variable_name Value
+rpl_semi_sync_master_enabled ON
+show status like 'Rpl_semi_sync_master_status';
+Variable_name Value
+Rpl_semi_sync_master_status ON
+#
+# Test RESET MASTER/SLAVE
+#
+connection slave;
+include/start_slave.inc
+connection master;
+create table t1 (a int) engine = ENGINE_TYPE;
+drop table t1;
+connection slave;
+[ test reset master ]
+connection master;
+reset master;
+show status like 'Rpl_semi_sync_master_status';
+Variable_name Value
+Rpl_semi_sync_master_status ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name Value
+Rpl_semi_sync_master_no_tx 0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name Value
+Rpl_semi_sync_master_yes_tx 0
+connection slave;
+include/stop_slave.inc
+include/reset_slave.inc
+include/kill_binlog_dump_threads.inc
+connection slave;
+include/start_slave.inc
+connection master;
+create table t1 (a int) engine = ENGINE_TYPE;
+insert into t1 values (1);
+insert into t1 values (2), (3);
+connection slave;
+select * from t1;
+a
+1
+2
+3
+connection master;
+[ master semi-sync status should be ON ]
+show status like 'Rpl_semi_sync_master_status';
+Variable_name Value
+Rpl_semi_sync_master_status ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name Value
+Rpl_semi_sync_master_no_tx 0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name Value
+Rpl_semi_sync_master_yes_tx 3
+#
+# Start semi-sync replication without SUPER privilege
+#
+connection slave;
+include/stop_slave.inc
+include/reset_slave.inc
+connection master;
+reset master;
+include/kill_binlog_dump_threads.inc
+set sql_log_bin=0;
+grant replication slave on *.* to rpl@127.0.0.1 identified by 'rpl_password';
+flush privileges;
+set sql_log_bin=1;
+connection slave;
+grant replication slave on *.* to rpl@127.0.0.1 identified by 'rpl_password';
+flush privileges;
+change master to master_user='rpl',master_password='rpl_password';
+include/start_slave.inc
+show status like 'Rpl_semi_sync_slave_status';
+Variable_name Value
+Rpl_semi_sync_slave_status ON
+connection master;
+[ master semi-sync should be ON ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name Value
+Rpl_semi_sync_master_clients 1
+show status like 'Rpl_semi_sync_master_status';
+Variable_name Value
+Rpl_semi_sync_master_status ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name Value
+Rpl_semi_sync_master_no_tx 0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name Value
+Rpl_semi_sync_master_yes_tx 0
+insert into t1 values (4);
+insert into t1 values (5);
+[ master semi-sync should be ON ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name Value
+Rpl_semi_sync_master_clients 1
+show status like 'Rpl_semi_sync_master_status';
+Variable_name Value
+Rpl_semi_sync_master_status ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name Value
+Rpl_semi_sync_master_no_tx 0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name Value
+Rpl_semi_sync_master_yes_tx 2
+#
+# Test semi-sync slave connect to non-semi-sync master
+#
+connection slave;
+include/stop_slave.inc
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+Variable_name Value
+Rpl_semi_sync_slave_status OFF
+connection master;
+include/kill_binlog_dump_threads.inc
+[ Semi-sync status on master should be ON ]
+show status like 'Rpl_semi_sync_master_status';
+Variable_name Value
+Rpl_semi_sync_master_status ON
+set global rpl_semi_sync_master_enabled= 0;
+connection slave;
+SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
+Variable_name Value
+rpl_semi_sync_slave_enabled ON
+include/start_slave.inc
+connection master;
+insert into t1 values (8);
+[ master semi-sync clients should be 1, status should be OFF ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name Value
+Rpl_semi_sync_master_clients 1
+show status like 'Rpl_semi_sync_master_status';
+Variable_name Value
+Rpl_semi_sync_master_status OFF
+connection slave;
+show status like 'Rpl_semi_sync_slave_status';
+Variable_name Value
+Rpl_semi_sync_slave_status ON
+connection slave;
+include/stop_slave.inc
+connection master;
+set global rpl_semi_sync_master_enabled= 0;
+connection slave;
+SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
+Variable_name Value
+rpl_semi_sync_slave_enabled ON
+include/start_slave.inc
+connection master;
+insert into t1 values (10);
+connection slave;
+#
+# Test non-semi-sync slave connect to semi-sync master
+#
+connection master;
+set global rpl_semi_sync_master_timeout= 5000;
+set global rpl_semi_sync_master_enabled= 1;
+connection slave;
+include/stop_slave.inc
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+Variable_name Value
+Rpl_semi_sync_slave_status OFF
+[ uninstall semi-sync slave plugin ]
+set global rpl_semi_sync_slave_enabled= 0;
+[ reinstall semi-sync slave plugin and disable semi-sync ]
+SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
+Variable_name Value
+rpl_semi_sync_slave_enabled OFF
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+Variable_name Value
+Rpl_semi_sync_slave_status OFF
+include/start_slave.inc
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+Variable_name Value
+Rpl_semi_sync_slave_status OFF
+#
+# Clean up
+#
+connection slave;
+include/stop_slave.inc
+set global rpl_semi_sync_slave_enabled= 0;
+connection master;
+set global rpl_semi_sync_master_enabled= 0;
+connection slave;
+change master to master_user='root',master_password='';
+include/start_slave.inc
+connection master;
+drop table t1;
+connection slave;
+connection master;
+drop user rpl@127.0.0.1;
+flush privileges;
+set global rpl_semi_sync_master_timeout= default;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_semi_sync.test b/mysql-test/suite/binlog_encryption/rpl_semi_sync.test
new file mode 100644
index 00000000..2e0907cc
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_semi_sync.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_semi_sync.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_skip_replication.cnf b/mysql-test/suite/binlog_encryption/rpl_skip_replication.cnf
new file mode 100644
index 00000000..b8e22e97
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_skip_replication.cnf
@@ -0,0 +1,6 @@
+!include my.cnf
+
+[mysqld.2]
+plugin-load-add= @ENV.FILE_KEY_MANAGEMENT_SO
+loose-file-key-management-filename=@ENV.MYSQLTEST_VARDIR/std_data/keys.txt
+encrypt-binlog
diff --git a/mysql-test/suite/binlog_encryption/rpl_skip_replication.result b/mysql-test/suite/binlog_encryption/rpl_skip_replication.result
new file mode 100644
index 00000000..96e0a303
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_skip_replication.result
@@ -0,0 +1,317 @@
+include/master-slave.inc
+[connection master]
+connection slave;
+include/stop_slave.inc
+CHANGE MASTER TO MASTER_USE_GTID=NO;
+include/start_slave.inc
+connection master;
+connection slave;
+CREATE USER 'nonsuperuser'@'127.0.0.1';
+GRANT ALTER,CREATE,DELETE,DROP,EVENT,INSERT,PROCESS,REPLICATION SLAVE,
+SELECT,UPDATE ON *.* TO 'nonsuperuser'@'127.0.0.1';
+connect nonpriv, 127.0.0.1, nonsuperuser,, test, $SLAVE_MYPORT,;
+connection nonpriv;
+SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_MASTER;
+ERROR 42000: Access denied; you need (at least one of) the SUPER, REPLICATION SLAVE ADMIN privilege(s) for this operation
+disconnect nonpriv;
+connection slave;
+DROP USER'nonsuperuser'@'127.0.0.1';
+SELECT @@global.replicate_events_marked_for_skip;
+@@global.replicate_events_marked_for_skip
+REPLICATE
+SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_SLAVE;
+ERROR HY000: This operation cannot be performed as you have a running slave ''; run STOP SLAVE '' first
+SELECT @@global.replicate_events_marked_for_skip;
+@@global.replicate_events_marked_for_skip
+REPLICATE
+STOP SLAVE;
+SET SESSION replicate_events_marked_for_skip=FILTER_ON_MASTER;
+ERROR HY000: Variable 'replicate_events_marked_for_skip' is a GLOBAL variable and should be set with SET GLOBAL
+SELECT @@global.replicate_events_marked_for_skip;
+@@global.replicate_events_marked_for_skip
+REPLICATE
+SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_MASTER;
+SELECT @@global.replicate_events_marked_for_skip;
+@@global.replicate_events_marked_for_skip
+FILTER_ON_MASTER
+START SLAVE;
+connection master;
+SELECT @@skip_replication;
+@@skip_replication
+0
+SET GLOBAL skip_replication=1;
+ERROR HY000: Variable 'skip_replication' is a SESSION variable and can't be used with SET GLOBAL
+SELECT @@skip_replication;
+@@skip_replication
+0
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=myisam;
+CREATE TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=innodb;
+INSERT INTO t1(a) VALUES (1);
+INSERT INTO t2(a) VALUES (1);
+SET skip_replication=1;
+CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=myisam;
+INSERT INTO t1(a) VALUES (2);
+INSERT INTO t2(a) VALUES (2);
+FLUSH NO_WRITE_TO_BINLOG LOGS;
+connection slave;
+connection slave;
+SHOW TABLES;
+Tables_in_test
+t1
+t2
+SELECT * FROM t1;
+a b
+1 NULL
+SELECT * FROM t2;
+a b
+1 NULL
+connection master;
+DROP TABLE t3;
+FLUSH NO_WRITE_TO_BINLOG LOGS;
+connection slave;
+connection slave;
+STOP SLAVE;
+SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_SLAVE;
+START SLAVE;
+connection master;
+SET skip_replication=1;
+CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=myisam;
+INSERT INTO t1(a) VALUES (3);
+INSERT INTO t2(a) VALUES (3);
+FLUSH NO_WRITE_TO_BINLOG LOGS;
+connection slave;
+connection slave;
+SHOW TABLES;
+Tables_in_test
+t1
+t2
+SELECT * FROM t1;
+a b
+1 NULL
+SELECT * FROM t2;
+a b
+1 NULL
+connection master;
+DROP TABLE t3;
+FLUSH NO_WRITE_TO_BINLOG LOGS;
+connection slave;
+connection slave;
+STOP SLAVE;
+SET GLOBAL replicate_events_marked_for_skip=REPLICATE;
+START SLAVE;
+connection master;
+SET skip_replication=1;
+CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=myisam;
+INSERT INTO t3(a) VALUES(2);
+connection slave;
+connection slave;
+SELECT * FROM t3;
+a b
+2 NULL
+connection master;
+DROP TABLE t3;
+TRUNCATE t1;
+connection slave;
+connection slave;
+RESET MASTER;
+connection master;
+SET skip_replication=0;
+INSERT INTO t1 VALUES (1,0);
+SET skip_replication=1;
+INSERT INTO t1 VALUES (2,0);
+SET skip_replication=0;
+INSERT INTO t1 VALUES (3,0);
+connection slave;
+connection slave;
+SELECT * FROM t1 ORDER by a;
+a b
+1 0
+2 0
+3 0
+STOP SLAVE;
+SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_MASTER;
+connection master;
+TRUNCATE t1;
+SELECT * FROM t1 ORDER by a;
+a b
+1 0
+2 0
+3 0
+connection slave;
+START SLAVE;
+connection master;
+connection slave;
+connection slave;
+SELECT * FROM t1 ORDER by a;
+a b
+1 0
+3 0
+connection master;
+TRUNCATE t1;
+connection slave;
+connection slave;
+STOP SLAVE;
+SET GLOBAL sql_slave_skip_counter=6;
+SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_SLAVE;
+START SLAVE;
+connection master;
+SET @old_binlog_format= @@binlog_format;
+SET binlog_format= statement;
+SET skip_replication=0;
+INSERT INTO t1 VALUES (1,5);
+SET skip_replication=1;
+INSERT INTO t1 VALUES (2,5);
+SET skip_replication=0;
+INSERT INTO t1 VALUES (3,5);
+INSERT INTO t1 VALUES (4,5);
+SET binlog_format= @old_binlog_format;
+connection slave;
+connection slave;
+SELECT * FROM t1;
+a b
+4 5
+connection slave;
+include/stop_slave.inc
+SET @old_slave_binlog_format= @@global.binlog_format;
+SET GLOBAL binlog_format= row;
+include/start_slave.inc
+connection master;
+TRUNCATE t1;
+SET @old_binlog_format= @@binlog_format;
+SET binlog_format= row;
+BINLOG 'wlZOTw8BAAAA8QAAAPUAAAAAAAQANS41LjIxLU1hcmlhREItZGVidWctbG9nAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAA2QAEGggAAAAICAgCAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAA371saA==';
+BINLOG 'wlZOTxMBAAAAKgAAAGMBAAAAgCkAAAAAAAEABHRlc3QAAnQxAAIDAwAC
+wlZOTxcBAAAAJgAAAIkBAAAAgCkAAAAAAAEAAv/8AQAAAAgAAAA=';
+BINLOG 'wlZOTxMBAAAAKgAAADwCAAAAACkAAAAAAAEABHRlc3QAAnQxAAIDAwAC
+wlZOTxcBAAAAJgAAAGICAAAAACkAAAAAAAEAAv/8AgAAAAgAAAA=';
+SET binlog_format= @old_binlog_format;
+SELECT * FROM t1 ORDER BY a;
+a b
+1 8
+2 8
+connection slave;
+connection slave;
+SELECT * FROM t1 ORDER by a;
+a b
+2 8
+include/stop_slave.inc
+SET GLOBAL binlog_format= @old_slave_binlog_format;
+include/start_slave.inc
+connection master;
+SET skip_replication=0;
+BEGIN;
+SET skip_replication=0;
+ERROR HY000: Cannot modify @@session.skip_replication inside a transaction
+SET skip_replication=1;
+ERROR HY000: Cannot modify @@session.skip_replication inside a transaction
+ROLLBACK;
+SET skip_replication=1;
+BEGIN;
+SET skip_replication=0;
+ERROR HY000: Cannot modify @@session.skip_replication inside a transaction
+SET skip_replication=1;
+ERROR HY000: Cannot modify @@session.skip_replication inside a transaction
+COMMIT;
+SET autocommit=0;
+INSERT INTO t2(a) VALUES(100);
+SET skip_replication=1;
+ERROR HY000: Cannot modify @@session.skip_replication inside a transaction
+ROLLBACK;
+SET autocommit=1;
+SET skip_replication=1;
+CREATE FUNCTION foo (x INT) RETURNS INT BEGIN SET SESSION skip_replication=x; RETURN x; END|
+CREATE PROCEDURE bar(x INT) BEGIN SET SESSION skip_replication=x; END|
+CREATE FUNCTION baz (x INT) RETURNS INT BEGIN CALL bar(x); RETURN x; END|
+SELECT foo(0);
+ERROR HY000: Cannot modify @@session.skip_replication inside a stored function or trigger
+SELECT baz(0);
+ERROR HY000: Cannot modify @@session.skip_replication inside a stored function or trigger
+SET @a= foo(1);
+ERROR HY000: Cannot modify @@session.skip_replication inside a stored function or trigger
+SET @a= baz(1);
+ERROR HY000: Cannot modify @@session.skip_replication inside a stored function or trigger
+UPDATE t2 SET b=foo(0);
+ERROR HY000: Cannot modify @@session.skip_replication inside a stored function or trigger
+UPDATE t2 SET b=baz(0);
+ERROR HY000: Cannot modify @@session.skip_replication inside a stored function or trigger
+INSERT INTO t1 VALUES (101, foo(1));
+ERROR HY000: Cannot modify @@session.skip_replication inside a stored function or trigger
+INSERT INTO t1 VALUES (101, baz(0));
+ERROR HY000: Cannot modify @@session.skip_replication inside a stored function or trigger
+SELECT @@skip_replication;
+@@skip_replication
+1
+CALL bar(0);
+SELECT @@skip_replication;
+@@skip_replication
+0
+CALL bar(1);
+SELECT @@skip_replication;
+@@skip_replication
+1
+DROP FUNCTION foo;
+DROP PROCEDURE bar;
+DROP FUNCTION baz;
+connection master;
+SET skip_replication= 0;
+TRUNCATE t1;
+connection slave;
+connection slave;
+STOP SLAVE;
+SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_MASTER;
+START SLAVE IO_THREAD;
+connection master;
+SET skip_replication= 1;
+INSERT INTO t1(a) VALUES (1);
+SET skip_replication= 0;
+INSERT INTO t1(a) VALUES (2);
+include/save_master_pos.inc
+connection slave;
+include/sync_io_with_master.inc
+STOP SLAVE IO_THREAD;
+SET GLOBAL replicate_events_marked_for_skip=REPLICATE;
+START SLAVE;
+connection master;
+connection slave;
+connection slave;
+SELECT * FROM t1;
+a b
+2 NULL
+connection master;
+SET skip_replication= 0;
+TRUNCATE t1;
+connection slave;
+connection slave;
+STOP SLAVE;
+SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_SLAVE;
+START SLAVE IO_THREAD;
+connection master;
+SET skip_replication= 1;
+INSERT INTO t1(a) VALUES (1);
+SET skip_replication= 0;
+INSERT INTO t1(a) VALUES (2);
+include/save_master_pos.inc
+connection slave;
+include/sync_io_with_master.inc
+STOP SLAVE IO_THREAD;
+SET GLOBAL replicate_events_marked_for_skip=REPLICATE;
+START SLAVE;
+connection master;
+connection slave;
+connection slave;
+SELECT * FROM t1 ORDER BY a;
+a b
+1 NULL
+2 NULL
+connection master;
+SET skip_replication=0;
+DROP TABLE t1,t2;
+connection slave;
+STOP SLAVE;
+SET GLOBAL replicate_events_marked_for_skip=REPLICATE;
+START SLAVE;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_skip_replication.test b/mysql-test/suite/binlog_encryption/rpl_skip_replication.test
new file mode 100644
index 00000000..11c5b33b
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_skip_replication.test
@@ -0,0 +1,2 @@
+--let $use_remote_mysqlbinlog= 1
+--source suite/rpl/t/rpl_skip_replication.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_special_charset.opt b/mysql-test/suite/binlog_encryption/rpl_special_charset.opt
new file mode 100644
index 00000000..b071fb20
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_special_charset.opt
@@ -0,0 +1 @@
+--character-set-server=utf16
diff --git a/mysql-test/suite/binlog_encryption/rpl_special_charset.result b/mysql-test/suite/binlog_encryption/rpl_special_charset.result
new file mode 100644
index 00000000..b947cf34
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_special_charset.result
@@ -0,0 +1,10 @@
+include/master-slave.inc
+[connection master]
+call mtr.add_suppression("'utf16' can not be used as client character set");
+CREATE TABLE t1(i VARCHAR(20));
+INSERT INTO t1 VALUES (0xFFFF);
+connection slave;
+include/diff_tables.inc [master:t1, slave:t1]
+connection master;
+DROP TABLE t1;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_special_charset.test b/mysql-test/suite/binlog_encryption/rpl_special_charset.test
new file mode 100644
index 00000000..c74f8915
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_special_charset.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_special_charset.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_sporadic_master-master.opt b/mysql-test/suite/binlog_encryption/rpl_sporadic_master-master.opt
new file mode 100644
index 00000000..5f038b69
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_sporadic_master-master.opt
@@ -0,0 +1 @@
+--debug-sporadic-binlog-dump-fail --debug-max-binlog-dump-events=2
diff --git a/mysql-test/suite/binlog_encryption/rpl_sporadic_master.result b/mysql-test/suite/binlog_encryption/rpl_sporadic_master.result
new file mode 100644
index 00000000..32ae6375
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_sporadic_master.result
@@ -0,0 +1,28 @@
+include/master-slave.inc
+[connection master]
+create table t2(n int);
+create table t1(n int not null auto_increment primary key);
+insert into t1 values (NULL),(NULL);
+truncate table t1;
+insert into t1 values (4),(NULL);
+connection slave;
+include/stop_slave.inc
+include/start_slave.inc
+connection master;
+insert into t1 values (NULL),(NULL);
+flush logs;
+truncate table t1;
+insert into t1 values (10),(NULL),(NULL),(NULL),(NULL),(NULL);
+connection slave;
+select * from t1 ORDER BY n;
+n
+10
+11
+12
+13
+14
+15
+connection master;
+drop table t1,t2;
+connection slave;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_sporadic_master.test b/mysql-test/suite/binlog_encryption/rpl_sporadic_master.test
new file mode 100644
index 00000000..1e3992dc
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_sporadic_master.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_sporadic_master.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_ssl.result b/mysql-test/suite/binlog_encryption/rpl_ssl.result
new file mode 100644
index 00000000..ce9e4d48
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_ssl.result
@@ -0,0 +1,59 @@
+include/master-slave.inc
+[connection master]
+connection master;
+create user replssl@localhost;
+grant replication slave on *.* to replssl@localhost require ssl;
+create table t1 (t int auto_increment, KEY(t));
+connection slave;
+stop slave;
+change master to
+master_user='replssl',
+master_password='',
+master_ssl=1,
+master_ssl_ca ='MYSQL_TEST_DIR/std_data/cacert.pem',
+master_ssl_cert='MYSQL_TEST_DIR/std_data/client-cert.pem',
+master_ssl_key='MYSQL_TEST_DIR/std_data/client-key.pem';
+start slave;
+connection master;
+insert into t1 values(1);
+connection slave;
+select * from t1;
+t
+1
+Master_SSL_Allowed = 'Yes'
+Master_SSL_CA_Path = ''
+Master_SSL_CA_File = 'MYSQL_TEST_DIR/std_data/cacert.pem'
+Master_SSL_Crl = ''
+Master_SSL_Crlpath = ''
+Master_SSL_Cert = 'MYSQL_TEST_DIR/std_data/client-cert.pem'
+Master_SSL_Key = 'MYSQL_TEST_DIR/std_data/client-key.pem'
+include/check_slave_is_running.inc
+STOP SLAVE;
+select * from t1;
+t
+1
+connection master;
+insert into t1 values (NULL);
+connection slave;
+include/wait_for_slave_to_start.inc
+Master_SSL_Allowed = 'Yes'
+Master_SSL_CA_Path = ''
+Master_SSL_CA_File = 'MYSQL_TEST_DIR/std_data/cacert.pem'
+Master_SSL_Crl = ''
+Master_SSL_Crlpath = ''
+Master_SSL_Cert = 'MYSQL_TEST_DIR/std_data/client-cert.pem'
+Master_SSL_Key = 'MYSQL_TEST_DIR/std_data/client-key.pem'
+include/check_slave_is_running.inc
+connection master;
+drop user replssl@localhost;
+drop table t1;
+connection slave;
+include/stop_slave.inc
+CHANGE MASTER TO
+master_user = 'root',
+master_ssl = 0,
+master_ssl_ca = '',
+master_ssl_cert = '',
+master_ssl_key = '';
+End of 5.0 tests
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_ssl.test b/mysql-test/suite/binlog_encryption/rpl_ssl.test
new file mode 100644
index 00000000..fb30d83a
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_ssl.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_ssl.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space-slave.opt b/mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space-slave.opt
new file mode 100644
index 00000000..f780540a
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space-slave.opt
@@ -0,0 +1 @@
+--relay-log-space-limit=8192 --relay-log-purge --max-relay-log-size=4096
diff --git a/mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space.result b/mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space.result
new file mode 100644
index 00000000..3113eec9
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space.result
@@ -0,0 +1,6 @@
+include/master-slave.inc
+[connection master]
+include/assert.inc [Assert that relay log space is close to the limit]
+include/diff_tables.inc [master:test.t1,slave:test.t1]
+connection slave;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space.test b/mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space.test
new file mode 100644
index 00000000..d5a08bde
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_stm_relay_ign_space.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.result b/mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.result
new file mode 100644
index 00000000..71332034
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.result
@@ -0,0 +1,460 @@
+include/master-slave.inc
+[connection master]
+connection slave;
+connection master;
+drop database if exists mysqltest1;
+create database mysqltest1;
+use mysqltest1;
+set @my_binlog_format= @@global.binlog_format;
+set session binlog_format=mixed;
+show session variables like "binlog_format%";
+Variable_name Value
+binlog_format MIXED
+set session binlog_format=statement;
+show session variables like "binlog_format%";
+Variable_name Value
+binlog_format STATEMENT
+set session binlog_format=row;
+show session variables like "binlog_format%";
+Variable_name Value
+binlog_format ROW
+set global binlog_format=DEFAULT;
+show global variables like "binlog_format%";
+Variable_name Value
+binlog_format MIXED
+set global binlog_format=MIXED;
+show global variables like "binlog_format%";
+Variable_name Value
+binlog_format MIXED
+set global binlog_format=STATEMENT;
+show global variables like "binlog_format%";
+Variable_name Value
+binlog_format STATEMENT
+set global binlog_format=ROW;
+show global variables like "binlog_format%";
+Variable_name Value
+binlog_format ROW
+show session variables like "binlog_format%";
+Variable_name Value
+binlog_format ROW
+select @@global.binlog_format, @@session.binlog_format;
+@@global.binlog_format @@session.binlog_format
+ROW ROW
+CREATE TABLE t1 (a varchar(100));
+prepare stmt1 from 'insert into t1 select concat(SYS_GUID(),?)';
+set @string="emergency_1_";
+insert into t1 values("work_2_");
+execute stmt1 using @string;
+deallocate prepare stmt1;
+prepare stmt1 from 'insert into t1 select ?';
+insert into t1 values(concat(SYS_GUID(),"work_3_"));
+execute stmt1 using @string;
+deallocate prepare stmt1;
+insert into t1 values(concat("for_4_",SYS_GUID()));
+insert into t1 select "yesterday_5_";
+create temporary table tmp(a char(100));
+insert into tmp values("see_6_");
+set binlog_format=statement;
+ERROR HY000: Cannot switch out of the row-based binary log format when the session has open temporary tables
+insert into t1 select * from tmp;
+drop temporary table tmp;
+set binlog_format=statement;
+show global variables like "binlog_format%";
+Variable_name Value
+binlog_format ROW
+show session variables like "binlog_format%";
+Variable_name Value
+binlog_format STATEMENT
+select @@global.binlog_format, @@session.binlog_format;
+@@global.binlog_format @@session.binlog_format
+ROW STATEMENT
+set global binlog_format=statement;
+show global variables like "binlog_format%";
+Variable_name Value
+binlog_format STATEMENT
+show session variables like "binlog_format%";
+Variable_name Value
+binlog_format STATEMENT
+select @@global.binlog_format, @@session.binlog_format;
+@@global.binlog_format @@session.binlog_format
+STATEMENT STATEMENT
+prepare stmt1 from 'insert into t1 select ?';
+set @string="emergency_7_";
+insert into t1 values("work_8_");
+execute stmt1 using @string;
+deallocate prepare stmt1;
+prepare stmt1 from 'insert into t1 select ?';
+insert into t1 values("work_9_");
+execute stmt1 using @string;
+deallocate prepare stmt1;
+insert into t1 values("for_10_");
+insert into t1 select "yesterday_11_";
+set binlog_format=statement;
+select @@global.binlog_format, @@session.binlog_format;
+@@global.binlog_format @@session.binlog_format
+STATEMENT STATEMENT
+set global binlog_format=statement;
+select @@global.binlog_format, @@session.binlog_format;
+@@global.binlog_format @@session.binlog_format
+STATEMENT STATEMENT
+prepare stmt1 from 'insert into t1 select ?';
+set @string="emergency_12_";
+insert into t1 values("work_13_");
+execute stmt1 using @string;
+deallocate prepare stmt1;
+prepare stmt1 from 'insert into t1 select ?';
+insert into t1 values("work_14_");
+execute stmt1 using @string;
+deallocate prepare stmt1;
+insert into t1 values("for_15_");
+insert into t1 select "yesterday_16_";
+set global binlog_format=mixed;
+select @@global.binlog_format, @@session.binlog_format;
+@@global.binlog_format @@session.binlog_format
+MIXED STATEMENT
+set binlog_format=default;
+select @@global.binlog_format, @@session.binlog_format;
+@@global.binlog_format @@session.binlog_format
+MIXED MIXED
+prepare stmt1 from 'insert into t1 select concat(SYS_GUID(),?)';
+set @string="emergency_17_";
+insert into t1 values("work_18_");
+execute stmt1 using @string;
+deallocate prepare stmt1;
+prepare stmt1 from 'insert into t1 select ?';
+insert into t1 values(concat(SYS_GUID(),"work_19_"));
+execute stmt1 using @string;
+deallocate prepare stmt1;
+insert into t1 values(concat("for_20_",SYS_GUID()));
+insert into t1 select "yesterday_21_";
+prepare stmt1 from 'insert into t1 select ?';
+insert into t1 values(concat(SYS_GUID(),"work_22_"));
+execute stmt1 using @string;
+deallocate prepare stmt1;
+insert into t1 values(concat("for_23_",SYS_GUID()));
+insert into t1 select "yesterday_24_";
+create table t2 ENGINE=MyISAM select rpad(SYS_GUID(),100,' ');
+create table t3 select 1 union select SYS_GUID();
+SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
+create table t4 select * from t1 where 3 in (select 1 union select 2 union select SYS_GUID() union select 3);
+SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
+create table t5 select * from t1 where 3 in (select 1 union select 2 union select curdate() union select 3);
+Warnings:
+Warning 1292 Truncated incorrect datetime value: '3'
+insert ignore into t5 select SYS_GUID() from t1 where 3 in (select 1 union select 2 union select 3 union select * from t4);
+create procedure foo()
+begin
+insert into t1 values("work_25_");
+insert into t1 values(concat("for_26_",SYS_GUID()));
+insert into t1 select "yesterday_27_";
+end|
+create procedure foo2()
+begin
+insert into t1 values(concat("emergency_28_",SYS_GUID()));
+insert into t1 values("work_29_");
+insert into t1 values(concat("for_30_",SYS_GUID()));
+set session binlog_format=row; # accepted for stored procs
+insert into t1 values("more work_31_");
+set session binlog_format=mixed;
+end|
+create function foo3() returns bigint unsigned
+begin
+set session binlog_format=row; # rejected for stored funcs
+insert into t1 values("alarm");
+return 100;
+end|
+create procedure foo4(x varchar(100))
+begin
+insert into t1 values(concat("work_250_",x));
+insert into t1 select "yesterday_270_";
+end|
+call foo();
+call foo2();
+call foo4("hello");
+call foo4(SYS_GUID());
+call foo4("world");
+select foo3();
+ERROR HY000: Cannot change the binary logging format inside a stored function or trigger
+select * from t1 where a="alarm";
+a
+drop function foo3;
+create function foo3() returns bigint unsigned
+begin
+insert into t1 values("foo3_32_");
+call foo();
+return 100;
+end|
+insert into t2 select foo3();
+prepare stmt1 from 'insert into t2 select foo3()';
+execute stmt1;
+execute stmt1;
+deallocate prepare stmt1;
+create function foo4() returns bigint unsigned
+begin
+insert into t2 select foo3();
+return 100;
+end|
+select foo4();
+foo4()
+100
+prepare stmt1 from 'select foo4()';
+execute stmt1;
+foo4()
+100
+execute stmt1;
+foo4()
+100
+deallocate prepare stmt1;
+create function foo5() returns bigint unsigned
+begin
+insert into t2 select SYS_GUID();
+return 100;
+end|
+select foo5();
+foo5()
+100
+prepare stmt1 from 'select foo5()';
+execute stmt1;
+foo5()
+100
+execute stmt1;
+foo5()
+100
+deallocate prepare stmt1;
+create function foo6(x varchar(100)) returns bigint unsigned
+begin
+insert into t2 select x;
+return 100;
+end|
+select foo6("foo6_1_");
+foo6("foo6_1_")
+100
+select foo6(concat("foo6_2_",SYS_GUID()));
+foo6(concat("foo6_2_",SYS_GUID()))
+100
+prepare stmt1 from 'select foo6(concat("foo6_3_",SYS_GUID()))';
+execute stmt1;
+foo6(concat("foo6_3_",SYS_GUID()))
+100
+execute stmt1;
+foo6(concat("foo6_3_",SYS_GUID()))
+100
+deallocate prepare stmt1;
+create view v1 as select SYS_GUID();
+create table t11 (data varchar(255));
+insert into t11 select * from v1;
+insert into t11 select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='mysqltest1' and TABLE_NAME IN ('v1','t11');
+prepare stmt1 from "insert into t11 select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='mysqltest1' and TABLE_NAME IN ('v1','t11')";
+execute stmt1;
+execute stmt1;
+deallocate prepare stmt1;
+create trigger t11_bi before insert on t11 for each row
+begin
+set NEW.data = concat(NEW.data,SYS_GUID());
+end|
+insert into t11 values("try_560_");
+insert delayed into t2 values("delay_1_");
+insert delayed into t2 values(concat("delay_2_",SYS_GUID()));
+insert delayed into t2 values("delay_6_");
+insert delayed into t2 values(rand());
+set @a=2.345;
+insert delayed into t2 values(@a);
+connection slave;
+connection master;
+create table t20 select * from t1;
+create table t21 select * from t2;
+create table t22 select * from t3;
+drop table t1,t2,t3;
+create table t1 (a int primary key auto_increment, b varchar(100));
+create table t2 (a int primary key auto_increment, b varchar(100));
+create table t3 (b varchar(100));
+create function f (x varchar(100)) returns int deterministic
+begin
+insert into t1 values(null,x);
+insert into t2 values(null,x);
+return 1;
+end|
+select f("try_41_");
+f("try_41_")
+1
+connection slave;
+use mysqltest1;
+insert into t2 values(2,null),(3,null),(4,null);
+delete from t2 where a>=2;
+connection master;
+select f("try_42_");
+f("try_42_")
+1
+connection slave;
+insert into t2 values(3,null),(4,null);
+delete from t2 where a>=3;
+connection master;
+prepare stmt1 from 'select f(?)';
+set @string="try_43_";
+insert into t1 values(null,"try_44_");
+execute stmt1 using @string;
+f(?)
+1
+deallocate prepare stmt1;
+connection slave;
+connection master;
+create table t12 select * from t1;
+drop table t1;
+create table t1 (a int, b varchar(100), key(a));
+select f("try_45_");
+f("try_45_")
+1
+create table t13 select * from t1;
+drop table t1;
+create table t1 (a int primary key auto_increment, b varchar(100));
+drop function f;
+create table t14 (unique (a)) select * from t2;
+truncate table t2;
+create function f1 (x varchar(100)) returns int deterministic
+begin
+insert into t1 values(null,x);
+return 1;
+end|
+create function f2 (x varchar(100)) returns int deterministic
+begin
+insert into t2 values(null,x);
+return 1;
+end|
+select f1("try_46_"),f2("try_47_");
+f1("try_46_") f2("try_47_")
+1 1
+connection slave;
+insert into t2 values(2,null),(3,null),(4,null);
+delete from t2 where a>=2;
+connection master;
+select f1("try_48_"),f2("try_49_");
+f1("try_48_") f2("try_49_")
+1 1
+insert into t3 values(concat("try_50_",f1("try_51_"),f2("try_52_")));
+connection slave;
+connection master;
+drop function f2;
+create function f2 (x varchar(100)) returns int deterministic
+begin
+declare y int;
+insert into t1 values(null,x);
+set y = (select count(*) from t2);
+return y;
+end|
+select f1("try_53_"),f2("try_54_");
+f1("try_53_") f2("try_54_")
+1 3
+connection slave;
+connection master;
+drop function f2;
+create trigger t1_bi before insert on t1 for each row
+begin
+insert into t2 values(null,"try_55_");
+end|
+insert into t1 values(null,"try_56_");
+alter table t1 modify a int, drop primary key;
+insert into t1 values(null,"try_57_");
+connection slave;
+connection master;
+CREATE TEMPORARY TABLE t15 SELECT SYS_GUID();
+create table t16 like t15;
+INSERT INTO t16 SELECT * FROM t15;
+insert into t16 values("try_65_");
+drop table t15;
+insert into t16 values("try_66_");
+connection slave;
+connection master;
+select count(*) from t1;
+count(*)
+7
+select count(*) from t2;
+count(*)
+5
+select count(*) from t3;
+count(*)
+1
+select count(*) from t4;
+count(*)
+29
+select count(*) from t5;
+count(*)
+58
+select count(*) from t11;
+count(*)
+8
+select count(*) from t20;
+count(*)
+66
+select count(*) from t21;
+count(*)
+19
+select count(*) from t22;
+count(*)
+2
+select count(*) from t12;
+count(*)
+4
+select count(*) from t13;
+count(*)
+1
+select count(*) from t14;
+count(*)
+4
+select count(*) from t16;
+count(*)
+3
+connection slave;
+connection master;
+DROP TABLE IF EXISTS t11;
+SET SESSION BINLOG_FORMAT=STATEMENT;
+CREATE TABLE t11 (song VARCHAR(255));
+LOCK TABLES t11 WRITE;
+SET SESSION BINLOG_FORMAT=ROW;
+INSERT INTO t11 VALUES('Several Species of Small Furry Animals Gathered Together in a Cave and Grooving With a Pict');
+SET SESSION BINLOG_FORMAT=STATEMENT;
+INSERT INTO t11 VALUES('Careful With That Axe, Eugene');
+UNLOCK TABLES;
+SELECT * FROM t11;
+song Several Species of Small Furry Animals Gathered Together in a Cave and Grooving With a Pict
+song Careful With That Axe, Eugene
+connection slave;
+USE mysqltest1;
+SELECT * FROM t11;
+song Several Species of Small Furry Animals Gathered Together in a Cave and Grooving With a Pict
+song Careful With That Axe, Eugene
+connection master;
+DROP TABLE IF EXISTS t12;
+SET SESSION BINLOG_FORMAT=MIXED;
+CREATE TABLE t12 (data LONG);
+LOCK TABLES t12 WRITE;
+INSERT INTO t12 VALUES(SYS_GUID());
+UNLOCK TABLES;
+connection slave;
+connection master;
+CREATE FUNCTION my_user()
+RETURNS CHAR(64)
+BEGIN
+DECLARE user CHAR(64);
+SELECT USER() INTO user;
+RETURN user;
+END $$
+CREATE FUNCTION my_current_user()
+RETURNS CHAR(64)
+BEGIN
+DECLARE user CHAR(64);
+SELECT CURRENT_USER() INTO user;
+RETURN user;
+END $$
+DROP TABLE IF EXISTS t13;
+CREATE TABLE t13 (data CHAR(64));
+INSERT INTO t13 VALUES (USER());
+INSERT INTO t13 VALUES (my_user());
+INSERT INTO t13 VALUES (CURRENT_USER());
+INSERT INTO t13 VALUES (my_current_user());
+connection slave;
+connection master;
+drop database mysqltest1;
+connection slave;
+connection master;
+set global binlog_format =@my_binlog_format;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.test b/mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.test
new file mode 100644
index 00000000..c65cc202
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_switch_stm_row_mixed.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_sync-master.opt b/mysql-test/suite/binlog_encryption/rpl_sync-master.opt
new file mode 100644
index 00000000..04b06bfa
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_sync-master.opt
@@ -0,0 +1,2 @@
+--default-storage-engine=MyISAM
+--loose-innodb-file-per-table=0
diff --git a/mysql-test/suite/binlog_encryption/rpl_sync-slave.opt b/mysql-test/suite/binlog_encryption/rpl_sync-slave.opt
new file mode 100644
index 00000000..79533053
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_sync-slave.opt
@@ -0,0 +1,2 @@
+--sync-relay-log-info=1 --relay-log-recovery=1 --default-storage-engine=MyISAM --loose-innodb-file-per-table=0
+--skip-core-file --skip-slave-start
diff --git a/mysql-test/suite/binlog_encryption/rpl_sync.result b/mysql-test/suite/binlog_encryption/rpl_sync.result
new file mode 100644
index 00000000..5fa3a07a
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_sync.result
@@ -0,0 +1,53 @@
+=====Configuring the enviroment=======;
+include/master-slave.inc
+[connection master]
+call mtr.add_suppression('Attempting backtrace');
+call mtr.add_suppression("Recovery from master pos .* and file master-bin.000001");
+ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
+flush tables;
+CREATE TABLE t1(a INT, PRIMARY KEY(a)) engine=innodb;
+insert into t1(a) values(1);
+insert into t1(a) values(2);
+insert into t1(a) values(3);
+=====Inserting data on the master but without the SQL Thread being running=======;
+connection slave;
+connection slave;
+include/stop_slave_sql.inc
+connection master;
+insert into t1(a) values(4);
+insert into t1(a) values(5);
+insert into t1(a) values(6);
+=====Removing relay log files and crashing/recoverying the slave=======;
+connection slave;
+include/stop_slave_io.inc
+SET SESSION debug_dbug="d,crash_before_rotate_relaylog";
+FLUSH LOGS;
+ERROR HY000: Lost connection to server during query
+include/rpl_reconnect.inc
+=====Dumping and comparing tables=======;
+include/start_slave.inc
+connection master;
+connection slave;
+include/diff_tables.inc [master:t1,slave:t1]
+=====Corrupting the master.info=======;
+connection slave;
+include/stop_slave.inc
+connection master;
+FLUSH LOGS;
+insert into t1(a) values(7);
+insert into t1(a) values(8);
+insert into t1(a) values(9);
+connection slave;
+SET SESSION debug_dbug="d,crash_before_rotate_relaylog";
+FLUSH LOGS;
+ERROR HY000: Lost connection to server during query
+include/rpl_reconnect.inc
+=====Dumping and comparing tables=======;
+include/start_slave.inc
+connection master;
+connection slave;
+include/diff_tables.inc [master:t1,slave:t1]
+=====Clean up=======;
+connection master;
+drop table t1;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_sync.test b/mysql-test/suite/binlog_encryption/rpl_sync.test
new file mode 100644
index 00000000..1ff72228
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_sync.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_sync.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.cnf b/mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.cnf
new file mode 100644
index 00000000..b8e22e97
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.cnf
@@ -0,0 +1,6 @@
+!include my.cnf
+
+[mysqld.2]
+plugin-load-add= @ENV.FILE_KEY_MANAGEMENT_SO
+loose-file-key-management-filename=@ENV.MYSQLTEST_VARDIR/std_data/keys.txt
+encrypt-binlog
diff --git a/mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.result b/mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.result
new file mode 100644
index 00000000..d61255c0
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.result
@@ -0,0 +1,91 @@
+include/master-slave.inc
+[connection master]
+connection master;
+SELECT @@global.mysql56_temporal_format AS on_master;
+on_master
+1
+connection slave;
+SELECT @@global.mysql56_temporal_format AS on_slave;
+on_slave
+1
+connection master;
+CREATE TABLE t1
+(
+c0 TIME(0),
+c1 TIME(1),
+c2 TIME(2),
+c3 TIME(3),
+c4 TIME(4),
+c5 TIME(5),
+c6 TIME(6)
+);
+CREATE TABLE t2
+(
+c0 TIMESTAMP(0),
+c1 TIMESTAMP(1),
+c2 TIMESTAMP(2),
+c3 TIMESTAMP(3),
+c4 TIMESTAMP(4),
+c5 TIMESTAMP(5),
+c6 TIMESTAMP(6)
+);
+CREATE TABLE t3
+(
+c0 DATETIME(0),
+c1 DATETIME(1),
+c2 DATETIME(2),
+c3 DATETIME(3),
+c4 DATETIME(4),
+c5 DATETIME(5),
+c6 DATETIME(6)
+);
+INSERT INTO t1 VALUES ('01:01:01','01:01:01.1','01:01:01.11','01:01:01.111','01:01:01.1111','01:01:01.11111','01:01:01.111111');
+INSERT INTO t2 VALUES ('2001-01-01 01:01:01','2001-01-01 01:01:01.1','2001-01-01 01:01:01.11','2001-01-01 01:01:01.111','2001-01-01 01:01:01.1111','2001-01-01 01:01:01.11111','2001-01-01 01:01:01.111111');
+INSERT INTO t3 VALUES ('2001-01-01 01:01:01','2001-01-01 01:01:01.1','2001-01-01 01:01:01.11','2001-01-01 01:01:01.111','2001-01-01 01:01:01.1111','2001-01-01 01:01:01.11111','2001-01-01 01:01:01.111111');
+SELECT TABLE_NAME, TABLE_ROWS, AVG_ROW_LENGTH,DATA_LENGTH FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_NAME RLIKE 't[1-3]' ORDER BY TABLE_NAME;
+TABLE_NAME TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH
+t1 1 34 34
+t2 1 41 41
+t3 1 48 48
+connection slave;
+connection slave;
+SELECT * FROM t1;;
+c0 01:01:01
+c1 01:01:01.1
+c2 01:01:01.11
+c3 01:01:01.111
+c4 01:01:01.1111
+c5 01:01:01.11111
+c6 01:01:01.111111
+SELECT * FROM t2;;
+c0 2001-01-01 01:01:01
+c1 2001-01-01 01:01:01.1
+c2 2001-01-01 01:01:01.11
+c3 2001-01-01 01:01:01.111
+c4 2001-01-01 01:01:01.1111
+c5 2001-01-01 01:01:01.11111
+c6 2001-01-01 01:01:01.111111
+SELECT * FROM t3;;
+c0 2001-01-01 01:01:01
+c1 2001-01-01 01:01:01.1
+c2 2001-01-01 01:01:01.11
+c3 2001-01-01 01:01:01.111
+c4 2001-01-01 01:01:01.1111
+c5 2001-01-01 01:01:01.11111
+c6 2001-01-01 01:01:01.111111
+SELECT TABLE_NAME, TABLE_ROWS, AVG_ROW_LENGTH,DATA_LENGTH FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_NAME RLIKE 't[1-3]' ORDER BY TABLE_NAME;
+TABLE_NAME TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH
+t1 1 34 34
+t2 1 41 41
+t3 1 48 48
+connection master;
+DROP TABLE t1;
+DROP TABLE t2;
+DROP TABLE t3;
+connection slave;
+SET @@global.mysql56_temporal_format=DEFAULT;
+connection master;
+SET @@global.mysql56_temporal_format=DEFAULT;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.test b/mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.test
new file mode 100644
index 00000000..5a9a79ba
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_temporal_format_default_to_default.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.cnf b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.cnf
new file mode 100644
index 00000000..b8e22e97
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.cnf
@@ -0,0 +1,6 @@
+!include my.cnf
+
+[mysqld.2]
+plugin-load-add= @ENV.FILE_KEY_MANAGEMENT_SO
+loose-file-key-management-filename=@ENV.MYSQLTEST_VARDIR/std_data/keys.txt
+encrypt-binlog
diff --git a/mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.result b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.result
new file mode 100644
index 00000000..5c518163
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.result
@@ -0,0 +1,95 @@
+include/master-slave.inc
+[connection master]
+connection master;
+SET @@global.mysql56_temporal_format=false;;
+connection slave;
+SET @@global.mysql56_temporal_format=true;;
+connection master;
+SELECT @@global.mysql56_temporal_format AS on_master;
+on_master
+0
+connection slave;
+SELECT @@global.mysql56_temporal_format AS on_slave;
+on_slave
+1
+connection master;
+CREATE TABLE t1
+(
+c0 TIME(0),
+c1 TIME(1),
+c2 TIME(2),
+c3 TIME(3),
+c4 TIME(4),
+c5 TIME(5),
+c6 TIME(6)
+);
+CREATE TABLE t2
+(
+c0 TIMESTAMP(0),
+c1 TIMESTAMP(1),
+c2 TIMESTAMP(2),
+c3 TIMESTAMP(3),
+c4 TIMESTAMP(4),
+c5 TIMESTAMP(5),
+c6 TIMESTAMP(6)
+);
+CREATE TABLE t3
+(
+c0 DATETIME(0),
+c1 DATETIME(1),
+c2 DATETIME(2),
+c3 DATETIME(3),
+c4 DATETIME(4),
+c5 DATETIME(5),
+c6 DATETIME(6)
+);
+INSERT INTO t1 VALUES ('01:01:01','01:01:01.1','01:01:01.11','01:01:01.111','01:01:01.1111','01:01:01.11111','01:01:01.111111');
+INSERT INTO t2 VALUES ('2001-01-01 01:01:01','2001-01-01 01:01:01.1','2001-01-01 01:01:01.11','2001-01-01 01:01:01.111','2001-01-01 01:01:01.1111','2001-01-01 01:01:01.11111','2001-01-01 01:01:01.111111');
+INSERT INTO t3 VALUES ('2001-01-01 01:01:01','2001-01-01 01:01:01.1','2001-01-01 01:01:01.11','2001-01-01 01:01:01.111','2001-01-01 01:01:01.1111','2001-01-01 01:01:01.11111','2001-01-01 01:01:01.111111');
+SELECT TABLE_NAME, TABLE_ROWS, AVG_ROW_LENGTH,DATA_LENGTH FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_NAME RLIKE 't[1-3]' ORDER BY TABLE_NAME;
+TABLE_NAME TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH
+t1 1 33 33
+t2 1 41 41
+t3 1 50 50
+connection slave;
+connection slave;
+SELECT * FROM t1;;
+c0 01:01:01
+c1 01:01:01.1
+c2 01:01:01.11
+c3 01:01:01.111
+c4 01:01:01.1111
+c5 01:01:01.11111
+c6 01:01:01.111111
+SELECT * FROM t2;;
+c0 2001-01-01 01:01:01
+c1 2001-01-01 01:01:01.1
+c2 2001-01-01 01:01:01.11
+c3 2001-01-01 01:01:01.111
+c4 2001-01-01 01:01:01.1111
+c5 2001-01-01 01:01:01.11111
+c6 2001-01-01 01:01:01.111111
+SELECT * FROM t3;;
+c0 2001-01-01 01:01:01
+c1 2001-01-01 01:01:01.1
+c2 2001-01-01 01:01:01.11
+c3 2001-01-01 01:01:01.111
+c4 2001-01-01 01:01:01.1111
+c5 2001-01-01 01:01:01.11111
+c6 2001-01-01 01:01:01.111111
+SELECT TABLE_NAME, TABLE_ROWS, AVG_ROW_LENGTH,DATA_LENGTH FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_NAME RLIKE 't[1-3]' ORDER BY TABLE_NAME;
+TABLE_NAME TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH
+t1 1 34 34
+t2 1 41 41
+t3 1 48 48
+connection master;
+DROP TABLE t1;
+DROP TABLE t2;
+DROP TABLE t3;
+connection slave;
+SET @@global.mysql56_temporal_format=DEFAULT;
+connection master;
+SET @@global.mysql56_temporal_format=DEFAULT;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.test b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.test
new file mode 100644
index 00000000..b9576b30
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.test
@@ -0,0 +1,6 @@
+-- source include/have_binlog_format_mixed_or_statement.inc
+
+--let $force_master_mysql56_temporal_format=false;
+--let $force_slave_mysql56_temporal_format=true;
+
+--source suite/rpl/t/rpl_temporal_format_default_to_default.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.cnf b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.cnf
new file mode 100644
index 00000000..b8e22e97
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.cnf
@@ -0,0 +1,6 @@
+!include my.cnf
+
+[mysqld.2]
+plugin-load-add= @ENV.FILE_KEY_MANAGEMENT_SO
+loose-file-key-management-filename=@ENV.MYSQLTEST_VARDIR/std_data/keys.txt
+encrypt-binlog
diff --git a/mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.result b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.result
new file mode 100644
index 00000000..9d086d34
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.result
@@ -0,0 +1,95 @@
+include/master-slave.inc
+[connection master]
+connection master;
+SET @@global.mysql56_temporal_format=true;;
+connection slave;
+SET @@global.mysql56_temporal_format=false;;
+connection master;
+SELECT @@global.mysql56_temporal_format AS on_master;
+on_master
+1
+connection slave;
+SELECT @@global.mysql56_temporal_format AS on_slave;
+on_slave
+0
+connection master;
+CREATE TABLE t1
+(
+c0 TIME(0),
+c1 TIME(1),
+c2 TIME(2),
+c3 TIME(3),
+c4 TIME(4),
+c5 TIME(5),
+c6 TIME(6)
+);
+CREATE TABLE t2
+(
+c0 TIMESTAMP(0),
+c1 TIMESTAMP(1),
+c2 TIMESTAMP(2),
+c3 TIMESTAMP(3),
+c4 TIMESTAMP(4),
+c5 TIMESTAMP(5),
+c6 TIMESTAMP(6)
+);
+CREATE TABLE t3
+(
+c0 DATETIME(0),
+c1 DATETIME(1),
+c2 DATETIME(2),
+c3 DATETIME(3),
+c4 DATETIME(4),
+c5 DATETIME(5),
+c6 DATETIME(6)
+);
+INSERT INTO t1 VALUES ('01:01:01','01:01:01.1','01:01:01.11','01:01:01.111','01:01:01.1111','01:01:01.11111','01:01:01.111111');
+INSERT INTO t2 VALUES ('2001-01-01 01:01:01','2001-01-01 01:01:01.1','2001-01-01 01:01:01.11','2001-01-01 01:01:01.111','2001-01-01 01:01:01.1111','2001-01-01 01:01:01.11111','2001-01-01 01:01:01.111111');
+INSERT INTO t3 VALUES ('2001-01-01 01:01:01','2001-01-01 01:01:01.1','2001-01-01 01:01:01.11','2001-01-01 01:01:01.111','2001-01-01 01:01:01.1111','2001-01-01 01:01:01.11111','2001-01-01 01:01:01.111111');
+SELECT TABLE_NAME, TABLE_ROWS, AVG_ROW_LENGTH,DATA_LENGTH FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_NAME RLIKE 't[1-3]' ORDER BY TABLE_NAME;
+TABLE_NAME TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH
+t1 1 34 34
+t2 1 41 41
+t3 1 48 48
+connection slave;
+connection slave;
+SELECT * FROM t1;;
+c0 01:01:01
+c1 01:01:01.1
+c2 01:01:01.11
+c3 01:01:01.111
+c4 01:01:01.1111
+c5 01:01:01.11111
+c6 01:01:01.111111
+SELECT * FROM t2;;
+c0 2001-01-01 01:01:01
+c1 2001-01-01 01:01:01.1
+c2 2001-01-01 01:01:01.11
+c3 2001-01-01 01:01:01.111
+c4 2001-01-01 01:01:01.1111
+c5 2001-01-01 01:01:01.11111
+c6 2001-01-01 01:01:01.111111
+SELECT * FROM t3;;
+c0 2001-01-01 01:01:01
+c1 2001-01-01 01:01:01.1
+c2 2001-01-01 01:01:01.11
+c3 2001-01-01 01:01:01.111
+c4 2001-01-01 01:01:01.1111
+c5 2001-01-01 01:01:01.11111
+c6 2001-01-01 01:01:01.111111
+SELECT TABLE_NAME, TABLE_ROWS, AVG_ROW_LENGTH,DATA_LENGTH FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_NAME RLIKE 't[1-3]' ORDER BY TABLE_NAME;
+TABLE_NAME TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH
+t1 1 33 33
+t2 1 41 41
+t3 1 50 50
+connection master;
+DROP TABLE t1;
+DROP TABLE t2;
+DROP TABLE t3;
+connection slave;
+SET @@global.mysql56_temporal_format=DEFAULT;
+connection master;
+SET @@global.mysql56_temporal_format=DEFAULT;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.test b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.test
new file mode 100644
index 00000000..7d099428
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.test
@@ -0,0 +1,4 @@
+--let $force_master_mysql56_temporal_format=true;
+--let $force_slave_mysql56_temporal_format=false;
+
+--source suite/rpl/t/rpl_temporal_format_default_to_default.test
diff --git a/mysql-test/suite/binlog_encryption/rpl_typeconv.result b/mysql-test/suite/binlog_encryption/rpl_typeconv.result
new file mode 100644
index 00000000..1ba259ed
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_typeconv.result
@@ -0,0 +1,768 @@
+include/master-slave.inc
+[connection master]
+connection slave;
+set @saved_slave_type_conversions = @@global.slave_type_conversions;
+CREATE TABLE type_conversions (
+TestNo INT AUTO_INCREMENT PRIMARY KEY,
+Source TEXT,
+Target TEXT,
+Flags TEXT,
+On_Master LONGTEXT,
+On_Slave LONGTEXT,
+Expected LONGTEXT,
+Compare INT,
+Error TEXT);
+SELECT @@global.slave_type_conversions;
+@@global.slave_type_conversions
+
+SET GLOBAL SLAVE_TYPE_CONVERSIONS='';
+SELECT @@global.slave_type_conversions;
+@@global.slave_type_conversions
+
+SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_NON_LOSSY';
+SELECT @@global.slave_type_conversions;
+@@global.slave_type_conversions
+ALL_NON_LOSSY
+SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY';
+SELECT @@global.slave_type_conversions;
+@@global.slave_type_conversions
+ALL_LOSSY
+SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY,ALL_NON_LOSSY';
+SELECT @@global.slave_type_conversions;
+@@global.slave_type_conversions
+ALL_LOSSY,ALL_NON_LOSSY
+SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY,ALL_NON_LOSSY,NONEXISTING_BIT';
+ERROR 42000: Variable 'slave_type_conversions' can't be set to the value of 'NONEXISTING_BIT'
+SELECT @@global.slave_type_conversions;
+@@global.slave_type_conversions
+ALL_LOSSY,ALL_NON_LOSSY
+connection slave;
+SET GLOBAL SLAVE_TYPE_CONVERSIONS='';
+**** Running tests with @@SLAVE_TYPE_CONVERSIONS = '' ****
+#
+# MDEV-15821 Row format replication from LONGBLOB COMPRESSED to LONGBLOB does not work
+#
+# End of MDEV-15821
+#
+# MDEV-15833 Row format replication between LONGBLOB and MEDIUMBLOB does not work for long values
+#
+# End of MDEV-15833
+#
+# MDEV-17098 DATE <-> DATETIME
+#
+# End of MDEV-17098
+include/rpl_reset.inc
+connection slave;
+SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_NON_LOSSY';
+**** Running tests with @@SLAVE_TYPE_CONVERSIONS = 'ALL_NON_LOSSY' ****
+#
+# MDEV-15821 Row format replication from LONGBLOB COMPRESSED to LONGBLOB does not work
+#
+# End of MDEV-15821
+#
+# MDEV-15833 Row format replication between LONGBLOB and MEDIUMBLOB does not work for long values
+#
+# End of MDEV-15833
+#
+# MDEV-17098 DATE <-> DATETIME
+#
+# End of MDEV-17098
+include/rpl_reset.inc
+connection slave;
+SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY';
+**** Running tests with @@SLAVE_TYPE_CONVERSIONS = 'ALL_LOSSY' ****
+#
+# MDEV-15821 Row format replication from LONGBLOB COMPRESSED to LONGBLOB does not work
+#
+# End of MDEV-15821
+#
+# MDEV-15833 Row format replication between LONGBLOB and MEDIUMBLOB does not work for long values
+#
+# End of MDEV-15833
+#
+# MDEV-17098 DATE <-> DATETIME
+#
+# End of MDEV-17098
+include/rpl_reset.inc
+connection slave;
+SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY,ALL_NON_LOSSY';
+**** Running tests with @@SLAVE_TYPE_CONVERSIONS = 'ALL_LOSSY,ALL_NON_LOSSY' ****
+#
+# MDEV-15821 Row format replication from LONGBLOB COMPRESSED to LONGBLOB does not work
+#
+# End of MDEV-15821
+#
+# MDEV-15833 Row format replication between LONGBLOB and MEDIUMBLOB does not work for long values
+#
+# End of MDEV-15833
+#
+# MDEV-17098 DATE <-> DATETIME
+#
+# End of MDEV-17098
+include/rpl_reset.inc
+connection slave;
+**** Result of conversions ****
+Source_Type Target_Type All_Type_Conversion_Flags Value_On_Slave
+TINYBLOB TINYBLOB <Correct value>
+TINYBLOB BLOB <Correct error>
+TINYBLOB MEDIUMBLOB <Correct error>
+TINYBLOB LONGBLOB <Correct error>
+BLOB TINYBLOB <Correct error>
+BLOB BLOB <Correct value>
+BLOB MEDIUMBLOB <Correct error>
+BLOB LONGBLOB <Correct error>
+MEDIUMBLOB TINYBLOB <Correct error>
+MEDIUMBLOB BLOB <Correct error>
+MEDIUMBLOB MEDIUMBLOB <Correct value>
+MEDIUMBLOB LONGBLOB <Correct error>
+LONGBLOB TINYBLOB <Correct error>
+LONGBLOB BLOB <Correct error>
+LONGBLOB MEDIUMBLOB <Correct error>
+LONGBLOB LONGBLOB <Correct value>
+GEOMETRY BLOB <Correct error>
+BLOB GEOMETRY <Correct error>
+GEOMETRY GEOMETRY <Correct value>
+BIT(1) BIT(1) <Correct value>
+DATE DATE <Correct value>
+ENUM('master',' ENUM('master',' <Correct value>
+CHAR(10) ENUM('master',' <Correct error>
+CHAR(10) SET('master','s <Correct error>
+ENUM('master',' CHAR(10) <Correct error>
+SET('master','s CHAR(10) <Correct error>
+SET('master','s SET('master','s <Correct value>
+SET('master','s SET('master','s <Correct value>
+SET('0','1','2' SET('0','1','2' <Correct value>
+SET('0','1','2' SET('0','1','2' <Correct error>
+SET('0','1','2' SET('0','1','2' <Correct error>
+SET('0','1','2' SET('0','1','2' <Correct error>
+TINYINT TINYINT <Correct value>
+TINYINT SMALLINT <Correct error>
+TINYINT MEDIUMINT <Correct error>
+TINYINT INT <Correct error>
+TINYINT BIGINT <Correct error>
+SMALLINT TINYINT <Correct error>
+SMALLINT TINYINT <Correct error>
+SMALLINT TINYINT UNSIGNE <Correct error>
+SMALLINT SMALLINT <Correct value>
+SMALLINT MEDIUMINT <Correct error>
+SMALLINT INT <Correct error>
+SMALLINT BIGINT <Correct error>
+MEDIUMINT TINYINT <Correct error>
+MEDIUMINT TINYINT <Correct error>
+MEDIUMINT TINYINT UNSIGNE <Correct error>
+MEDIUMINT SMALLINT <Correct error>
+MEDIUMINT MEDIUMINT <Correct value>
+MEDIUMINT INT <Correct error>
+MEDIUMINT BIGINT <Correct error>
+INT TINYINT <Correct error>
+INT TINYINT <Correct error>
+INT TINYINT UNSIGNE <Correct error>
+INT SMALLINT <Correct error>
+INT MEDIUMINT <Correct error>
+INT INT <Correct value>
+INT BIGINT <Correct error>
+BIGINT TINYINT <Correct error>
+BIGINT SMALLINT <Correct error>
+BIGINT MEDIUMINT <Correct error>
+BIGINT INT <Correct error>
+BIGINT BIGINT <Correct value>
+CHAR(20) CHAR(20) <Correct value>
+CHAR(20) CHAR(30) <Correct error>
+CHAR(20) CHAR(10) <Correct error>
+CHAR(20) VARCHAR(20) <Correct error>
+CHAR(20) VARCHAR(30) <Correct error>
+CHAR(20) VARCHAR(10) <Correct error>
+CHAR(20) TINYTEXT <Correct error>
+CHAR(20) TEXT <Correct error>
+CHAR(20) MEDIUMTEXT <Correct error>
+CHAR(20) LONGTEXT <Correct error>
+VARCHAR(20) VARCHAR(20) <Correct value>
+VARCHAR(20) VARCHAR(30) <Correct error>
+VARCHAR(20) VARCHAR(10) <Correct error>
+VARCHAR(20) CHAR(30) <Correct error>
+VARCHAR(20) CHAR(10) <Correct error>
+VARCHAR(20) TINYTEXT <Correct error>
+VARCHAR(20) TEXT <Correct error>
+VARCHAR(20) MEDIUMTEXT <Correct error>
+VARCHAR(20) LONGTEXT <Correct error>
+VARCHAR(500) VARCHAR(500) <Correct value>
+VARCHAR(500) VARCHAR(510) <Correct error>
+VARCHAR(500) VARCHAR(255) <Correct error>
+VARCHAR(500) TINYTEXT <Correct error>
+VARCHAR(500) TEXT <Correct error>
+VARCHAR(500) MEDIUMTEXT <Correct error>
+VARCHAR(500) LONGTEXT <Correct error>
+TINYTEXT VARCHAR(500) <Correct error>
+TEXT VARCHAR(500) <Correct error>
+MEDIUMTEXT VARCHAR(500) <Correct error>
+LONGTEXT VARCHAR(500) <Correct error>
+TINYTEXT CHAR(255) <Correct error>
+TINYTEXT CHAR(250) <Correct error>
+TEXT CHAR(255) <Correct error>
+MEDIUMTEXT CHAR(255) <Correct error>
+LONGTEXT CHAR(255) <Correct error>
+TINYTEXT TINYTEXT <Correct value>
+TINYTEXT TEXT <Correct error>
+TEXT TINYTEXT <Correct error>
+DECIMAL(10,5) DECIMAL(10,5) <Correct value>
+DECIMAL(10,5) DECIMAL(10,6) <Correct error>
+DECIMAL(10,5) DECIMAL(11,5) <Correct error>
+DECIMAL(10,5) DECIMAL(11,6) <Correct error>
+DECIMAL(10,5) DECIMAL(10,4) <Correct error>
+DECIMAL(10,5) DECIMAL(9,5) <Correct error>
+DECIMAL(10,5) DECIMAL(9,4) <Correct error>
+FLOAT DECIMAL(10,5) <Correct error>
+DOUBLE DECIMAL(10,5) <Correct error>
+DECIMAL(10,5) FLOAT <Correct error>
+DECIMAL(10,5) DOUBLE <Correct error>
+FLOAT FLOAT <Correct value>
+DOUBLE DOUBLE <Correct value>
+FLOAT DOUBLE <Correct error>
+DOUBLE FLOAT <Correct error>
+BIT(5) BIT(5) <Correct value>
+BIT(5) BIT(6) <Correct error>
+BIT(6) BIT(5) <Correct error>
+BIT(5) BIT(12) <Correct error>
+BIT(12) BIT(5) <Correct error>
+TINYBLOB COMPRE TINYBLOB <Correct error>
+TINYBLOB COMPRE BLOB <Correct error>
+TINYBLOB COMPRE MEDIUMBLOB <Correct error>
+TINYBLOB COMPRE LONGBLOB <Correct error>
+TINYBLOB COMPRE VARBINARY(255) <Correct error>
+BLOB COMPRESSED TINYBLOB <Correct error>
+BLOB COMPRESSED BLOB <Correct error>
+BLOB COMPRESSED MEDIUMBLOB <Correct error>
+BLOB COMPRESSED LONGBLOB <Correct error>
+BLOB COMPRESSED VARBINARY(65500 <Correct error>
+MEDIUMBLOB COMP TINYBLOB <Correct error>
+MEDIUMBLOB COMP BLOB <Correct error>
+MEDIUMBLOB COMP MEDIUMBLOB <Correct error>
+MEDIUMBLOB COMP LONGBLOB <Correct error>
+MEDIUMBLOB COMP VARBINARY(65500 <Correct error>
+LONGBLOB COMPRE TINYBLOB <Correct error>
+LONGBLOB COMPRE BLOB <Correct error>
+LONGBLOB COMPRE MEDIUMBLOB <Correct error>
+LONGBLOB COMPRE LONGBLOB <Correct error>
+LONGBLOB COMPRE VARBINARY(65500 <Correct error>
+TINYBLOB BLOB <Correct error>
+TINYBLOB MEDIUMBLOB <Correct error>
+TINYBLOB LONGBLOB <Correct error>
+TINYBLOB VARBINARY(255) <Correct error>
+BLOB TINYBLOB <Correct error>
+BLOB MEDIUMBLOB <Correct error>
+BLOB LONGBLOB <Correct error>
+BLOB VARBINARY(65500 <Correct error>
+MEDIUMBLOB TINYBLOB <Correct error>
+MEDIUMBLOB BLOB <Correct error>
+MEDIUMBLOB LONGBLOB <Correct error>
+MEDIUMBLOB VARBINARY(65500 <Correct error>
+LONGBLOB TINYBLOB <Correct error>
+LONGBLOB BLOB <Correct error>
+LONGBLOB MEDIUMBLOB <Correct error>
+LONGBLOB VARBINARY(65500 <Correct error>
+DATE DATETIME(6) <Correct error>
+DATE DATETIME(6) <Correct error>
+DATE DATETIME(6) <Correct error>
+DATE DATETIME(0) <Correct error>
+DATETIME(6) DATE <Correct error>
+DATETIME(6) DATE <Correct error>
+DATETIME(0) DATE <Correct error>
+TINYBLOB TINYBLOB ALL_NON_LOSSY <Correct value>
+TINYBLOB BLOB ALL_NON_LOSSY <Correct value>
+TINYBLOB MEDIUMBLOB ALL_NON_LOSSY <Correct value>
+TINYBLOB LONGBLOB ALL_NON_LOSSY <Correct value>
+BLOB TINYBLOB ALL_NON_LOSSY <Correct error>
+BLOB BLOB ALL_NON_LOSSY <Correct value>
+BLOB MEDIUMBLOB ALL_NON_LOSSY <Correct value>
+BLOB LONGBLOB ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB TINYBLOB ALL_NON_LOSSY <Correct error>
+MEDIUMBLOB BLOB ALL_NON_LOSSY <Correct error>
+MEDIUMBLOB MEDIUMBLOB ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB LONGBLOB ALL_NON_LOSSY <Correct value>
+LONGBLOB TINYBLOB ALL_NON_LOSSY <Correct error>
+LONGBLOB BLOB ALL_NON_LOSSY <Correct error>
+LONGBLOB MEDIUMBLOB ALL_NON_LOSSY <Correct error>
+LONGBLOB LONGBLOB ALL_NON_LOSSY <Correct value>
+GEOMETRY BLOB ALL_NON_LOSSY <Correct error>
+BLOB GEOMETRY ALL_NON_LOSSY <Correct error>
+GEOMETRY GEOMETRY ALL_NON_LOSSY <Correct value>
+BIT(1) BIT(1) ALL_NON_LOSSY <Correct value>
+DATE DATE ALL_NON_LOSSY <Correct value>
+ENUM('master',' ENUM('master',' ALL_NON_LOSSY <Correct value>
+CHAR(10) ENUM('master',' ALL_NON_LOSSY <Correct error>
+CHAR(10) SET('master','s ALL_NON_LOSSY <Correct error>
+ENUM('master',' CHAR(10) ALL_NON_LOSSY <Correct error>
+SET('master','s CHAR(10) ALL_NON_LOSSY <Correct error>
+SET('master','s SET('master','s ALL_NON_LOSSY <Correct value>
+SET('master','s SET('master','s ALL_NON_LOSSY <Correct value>
+SET('0','1','2' SET('0','1','2' ALL_NON_LOSSY <Correct value>
+SET('0','1','2' SET('0','1','2' ALL_NON_LOSSY <Correct value>
+SET('0','1','2' SET('0','1','2' ALL_NON_LOSSY <Correct error>
+SET('0','1','2' SET('0','1','2' ALL_NON_LOSSY <Correct error>
+TINYINT TINYINT ALL_NON_LOSSY <Correct value>
+TINYINT SMALLINT ALL_NON_LOSSY <Correct value>
+TINYINT MEDIUMINT ALL_NON_LOSSY <Correct value>
+TINYINT INT ALL_NON_LOSSY <Correct value>
+TINYINT BIGINT ALL_NON_LOSSY <Correct value>
+SMALLINT TINYINT ALL_NON_LOSSY <Correct error>
+SMALLINT TINYINT ALL_NON_LOSSY <Correct error>
+SMALLINT TINYINT UNSIGNE ALL_NON_LOSSY <Correct error>
+SMALLINT SMALLINT ALL_NON_LOSSY <Correct value>
+SMALLINT MEDIUMINT ALL_NON_LOSSY <Correct value>
+SMALLINT INT ALL_NON_LOSSY <Correct value>
+SMALLINT BIGINT ALL_NON_LOSSY <Correct value>
+MEDIUMINT TINYINT ALL_NON_LOSSY <Correct error>
+MEDIUMINT TINYINT ALL_NON_LOSSY <Correct error>
+MEDIUMINT TINYINT UNSIGNE ALL_NON_LOSSY <Correct error>
+MEDIUMINT SMALLINT ALL_NON_LOSSY <Correct error>
+MEDIUMINT MEDIUMINT ALL_NON_LOSSY <Correct value>
+MEDIUMINT INT ALL_NON_LOSSY <Correct value>
+MEDIUMINT BIGINT ALL_NON_LOSSY <Correct value>
+INT TINYINT ALL_NON_LOSSY <Correct error>
+INT TINYINT ALL_NON_LOSSY <Correct error>
+INT TINYINT UNSIGNE ALL_NON_LOSSY <Correct error>
+INT SMALLINT ALL_NON_LOSSY <Correct error>
+INT MEDIUMINT ALL_NON_LOSSY <Correct error>
+INT INT ALL_NON_LOSSY <Correct value>
+INT BIGINT ALL_NON_LOSSY <Correct value>
+BIGINT TINYINT ALL_NON_LOSSY <Correct error>
+BIGINT SMALLINT ALL_NON_LOSSY <Correct error>
+BIGINT MEDIUMINT ALL_NON_LOSSY <Correct error>
+BIGINT INT ALL_NON_LOSSY <Correct error>
+BIGINT BIGINT ALL_NON_LOSSY <Correct value>
+CHAR(20) CHAR(20) ALL_NON_LOSSY <Correct value>
+CHAR(20) CHAR(30) ALL_NON_LOSSY <Correct value>
+CHAR(20) CHAR(10) ALL_NON_LOSSY <Correct error>
+CHAR(20) VARCHAR(20) ALL_NON_LOSSY <Correct value>
+CHAR(20) VARCHAR(30) ALL_NON_LOSSY <Correct value>
+CHAR(20) VARCHAR(10) ALL_NON_LOSSY <Correct error>
+CHAR(20) TINYTEXT ALL_NON_LOSSY <Correct value>
+CHAR(20) TEXT ALL_NON_LOSSY <Correct value>
+CHAR(20) MEDIUMTEXT ALL_NON_LOSSY <Correct value>
+CHAR(20) LONGTEXT ALL_NON_LOSSY <Correct value>
+VARCHAR(20) VARCHAR(20) ALL_NON_LOSSY <Correct value>
+VARCHAR(20) VARCHAR(30) ALL_NON_LOSSY <Correct value>
+VARCHAR(20) VARCHAR(10) ALL_NON_LOSSY <Correct error>
+VARCHAR(20) CHAR(30) ALL_NON_LOSSY <Correct value>
+VARCHAR(20) CHAR(10) ALL_NON_LOSSY <Correct error>
+VARCHAR(20) TINYTEXT ALL_NON_LOSSY <Correct value>
+VARCHAR(20) TEXT ALL_NON_LOSSY <Correct value>
+VARCHAR(20) MEDIUMTEXT ALL_NON_LOSSY <Correct value>
+VARCHAR(20) LONGTEXT ALL_NON_LOSSY <Correct value>
+VARCHAR(500) VARCHAR(500) ALL_NON_LOSSY <Correct value>
+VARCHAR(500) VARCHAR(510) ALL_NON_LOSSY <Correct value>
+VARCHAR(500) VARCHAR(255) ALL_NON_LOSSY <Correct error>
+VARCHAR(500) TINYTEXT ALL_NON_LOSSY <Correct error>
+VARCHAR(500) TEXT ALL_NON_LOSSY <Correct value>
+VARCHAR(500) MEDIUMTEXT ALL_NON_LOSSY <Correct value>
+VARCHAR(500) LONGTEXT ALL_NON_LOSSY <Correct value>
+TINYTEXT VARCHAR(500) ALL_NON_LOSSY <Correct value>
+TEXT VARCHAR(500) ALL_NON_LOSSY <Correct error>
+MEDIUMTEXT VARCHAR(500) ALL_NON_LOSSY <Correct error>
+LONGTEXT VARCHAR(500) ALL_NON_LOSSY <Correct error>
+TINYTEXT CHAR(255) ALL_NON_LOSSY <Correct value>
+TINYTEXT CHAR(250) ALL_NON_LOSSY <Correct error>
+TEXT CHAR(255) ALL_NON_LOSSY <Correct error>
+MEDIUMTEXT CHAR(255) ALL_NON_LOSSY <Correct error>
+LONGTEXT CHAR(255) ALL_NON_LOSSY <Correct error>
+TINYTEXT TINYTEXT ALL_NON_LOSSY <Correct value>
+TINYTEXT TEXT ALL_NON_LOSSY <Correct value>
+TEXT TINYTEXT ALL_NON_LOSSY <Correct error>
+DECIMAL(10,5) DECIMAL(10,5) ALL_NON_LOSSY <Correct value>
+DECIMAL(10,5) DECIMAL(10,6) ALL_NON_LOSSY <Correct value>
+DECIMAL(10,5) DECIMAL(11,5) ALL_NON_LOSSY <Correct value>
+DECIMAL(10,5) DECIMAL(11,6) ALL_NON_LOSSY <Correct value>
+DECIMAL(10,5) DECIMAL(10,4) ALL_NON_LOSSY <Correct error>
+DECIMAL(10,5) DECIMAL(9,5) ALL_NON_LOSSY <Correct error>
+DECIMAL(10,5) DECIMAL(9,4) ALL_NON_LOSSY <Correct error>
+FLOAT DECIMAL(10,5) ALL_NON_LOSSY <Correct error>
+DOUBLE DECIMAL(10,5) ALL_NON_LOSSY <Correct error>
+DECIMAL(10,5) FLOAT ALL_NON_LOSSY <Correct error>
+DECIMAL(10,5) DOUBLE ALL_NON_LOSSY <Correct error>
+FLOAT FLOAT ALL_NON_LOSSY <Correct value>
+DOUBLE DOUBLE ALL_NON_LOSSY <Correct value>
+FLOAT DOUBLE ALL_NON_LOSSY <Correct value>
+DOUBLE FLOAT ALL_NON_LOSSY <Correct error>
+BIT(5) BIT(5) ALL_NON_LOSSY <Correct value>
+BIT(5) BIT(6) ALL_NON_LOSSY <Correct value>
+BIT(6) BIT(5) ALL_NON_LOSSY <Correct error>
+BIT(5) BIT(12) ALL_NON_LOSSY <Correct value>
+BIT(12) BIT(5) ALL_NON_LOSSY <Correct error>
+TINYBLOB COMPRE TINYBLOB ALL_NON_LOSSY <Correct value>
+TINYBLOB COMPRE BLOB ALL_NON_LOSSY <Correct value>
+TINYBLOB COMPRE MEDIUMBLOB ALL_NON_LOSSY <Correct value>
+TINYBLOB COMPRE LONGBLOB ALL_NON_LOSSY <Correct value>
+TINYBLOB COMPRE VARBINARY(255) ALL_NON_LOSSY <Correct value>
+BLOB COMPRESSED TINYBLOB ALL_NON_LOSSY <Correct error>
+BLOB COMPRESSED BLOB ALL_NON_LOSSY <Correct value>
+BLOB COMPRESSED MEDIUMBLOB ALL_NON_LOSSY <Correct value>
+BLOB COMPRESSED LONGBLOB ALL_NON_LOSSY <Correct value>
+BLOB COMPRESSED VARBINARY(65500 ALL_NON_LOSSY <Correct error>
+MEDIUMBLOB COMP TINYBLOB ALL_NON_LOSSY <Correct error>
+MEDIUMBLOB COMP BLOB ALL_NON_LOSSY <Correct error>
+MEDIUMBLOB COMP MEDIUMBLOB ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB COMP LONGBLOB ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB COMP VARBINARY(65500 ALL_NON_LOSSY <Correct error>
+LONGBLOB COMPRE TINYBLOB ALL_NON_LOSSY <Correct error>
+LONGBLOB COMPRE BLOB ALL_NON_LOSSY <Correct error>
+LONGBLOB COMPRE MEDIUMBLOB ALL_NON_LOSSY <Correct error>
+LONGBLOB COMPRE LONGBLOB ALL_NON_LOSSY <Correct value>
+LONGBLOB COMPRE VARBINARY(65500 ALL_NON_LOSSY <Correct error>
+TINYBLOB BLOB ALL_NON_LOSSY <Correct value>
+TINYBLOB MEDIUMBLOB ALL_NON_LOSSY <Correct value>
+TINYBLOB LONGBLOB ALL_NON_LOSSY <Correct value>
+TINYBLOB VARBINARY(255) ALL_NON_LOSSY <Correct value>
+BLOB TINYBLOB ALL_NON_LOSSY <Correct error>
+BLOB MEDIUMBLOB ALL_NON_LOSSY <Correct value>
+BLOB LONGBLOB ALL_NON_LOSSY <Correct value>
+BLOB VARBINARY(65500 ALL_NON_LOSSY <Correct error>
+MEDIUMBLOB TINYBLOB ALL_NON_LOSSY <Correct error>
+MEDIUMBLOB BLOB ALL_NON_LOSSY <Correct error>
+MEDIUMBLOB LONGBLOB ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB VARBINARY(65500 ALL_NON_LOSSY <Correct error>
+LONGBLOB TINYBLOB ALL_NON_LOSSY <Correct error>
+LONGBLOB BLOB ALL_NON_LOSSY <Correct error>
+LONGBLOB MEDIUMBLOB ALL_NON_LOSSY <Correct error>
+LONGBLOB VARBINARY(65500 ALL_NON_LOSSY <Correct error>
+DATE DATETIME(6) ALL_NON_LOSSY <Correct value>
+DATE DATETIME(6) ALL_NON_LOSSY <Correct value>
+DATE DATETIME(6) ALL_NON_LOSSY <Correct value>
+DATE DATETIME(0) ALL_NON_LOSSY <Correct value>
+DATETIME(6) DATE ALL_NON_LOSSY <Correct error>
+DATETIME(6) DATE ALL_NON_LOSSY <Correct error>
+DATETIME(0) DATE ALL_NON_LOSSY <Correct error>
+TINYBLOB TINYBLOB ALL_LOSSY <Correct value>
+TINYBLOB BLOB ALL_LOSSY <Correct error>
+TINYBLOB MEDIUMBLOB ALL_LOSSY <Correct error>
+TINYBLOB LONGBLOB ALL_LOSSY <Correct error>
+BLOB TINYBLOB ALL_LOSSY <Correct value>
+BLOB BLOB ALL_LOSSY <Correct value>
+BLOB MEDIUMBLOB ALL_LOSSY <Correct error>
+BLOB LONGBLOB ALL_LOSSY <Correct error>
+MEDIUMBLOB TINYBLOB ALL_LOSSY <Correct value>
+MEDIUMBLOB BLOB ALL_LOSSY <Correct value>
+MEDIUMBLOB MEDIUMBLOB ALL_LOSSY <Correct value>
+MEDIUMBLOB LONGBLOB ALL_LOSSY <Correct error>
+LONGBLOB TINYBLOB ALL_LOSSY <Correct value>
+LONGBLOB BLOB ALL_LOSSY <Correct value>
+LONGBLOB MEDIUMBLOB ALL_LOSSY <Correct value>
+LONGBLOB LONGBLOB ALL_LOSSY <Correct value>
+GEOMETRY BLOB ALL_LOSSY <Correct error>
+BLOB GEOMETRY ALL_LOSSY <Correct error>
+GEOMETRY GEOMETRY ALL_LOSSY <Correct value>
+BIT(1) BIT(1) ALL_LOSSY <Correct value>
+DATE DATE ALL_LOSSY <Correct value>
+ENUM('master',' ENUM('master',' ALL_LOSSY <Correct value>
+CHAR(10) ENUM('master',' ALL_LOSSY <Correct error>
+CHAR(10) SET('master','s ALL_LOSSY <Correct error>
+ENUM('master',' CHAR(10) ALL_LOSSY <Correct error>
+SET('master','s CHAR(10) ALL_LOSSY <Correct error>
+SET('master','s SET('master','s ALL_LOSSY <Correct value>
+SET('master','s SET('master','s ALL_LOSSY <Correct value>
+SET('0','1','2' SET('0','1','2' ALL_LOSSY <Correct value>
+SET('0','1','2' SET('0','1','2' ALL_LOSSY <Correct error>
+SET('0','1','2' SET('0','1','2' ALL_LOSSY <Correct value>
+SET('0','1','2' SET('0','1','2' ALL_LOSSY <Correct value>
+TINYINT TINYINT ALL_LOSSY <Correct value>
+TINYINT SMALLINT ALL_LOSSY <Correct error>
+TINYINT MEDIUMINT ALL_LOSSY <Correct error>
+TINYINT INT ALL_LOSSY <Correct error>
+TINYINT BIGINT ALL_LOSSY <Correct error>
+SMALLINT TINYINT ALL_LOSSY <Correct value>
+SMALLINT TINYINT ALL_LOSSY <Correct value>
+SMALLINT TINYINT UNSIGNE ALL_LOSSY <Correct value>
+SMALLINT SMALLINT ALL_LOSSY <Correct value>
+SMALLINT MEDIUMINT ALL_LOSSY <Correct error>
+SMALLINT INT ALL_LOSSY <Correct error>
+SMALLINT BIGINT ALL_LOSSY <Correct error>
+MEDIUMINT TINYINT ALL_LOSSY <Correct value>
+MEDIUMINT TINYINT ALL_LOSSY <Correct value>
+MEDIUMINT TINYINT UNSIGNE ALL_LOSSY <Correct value>
+MEDIUMINT SMALLINT ALL_LOSSY <Correct value>
+MEDIUMINT MEDIUMINT ALL_LOSSY <Correct value>
+MEDIUMINT INT ALL_LOSSY <Correct error>
+MEDIUMINT BIGINT ALL_LOSSY <Correct error>
+INT TINYINT ALL_LOSSY <Correct value>
+INT TINYINT ALL_LOSSY <Correct value>
+INT TINYINT UNSIGNE ALL_LOSSY <Correct value>
+INT SMALLINT ALL_LOSSY <Correct value>
+INT MEDIUMINT ALL_LOSSY <Correct value>
+INT INT ALL_LOSSY <Correct value>
+INT BIGINT ALL_LOSSY <Correct error>
+BIGINT TINYINT ALL_LOSSY <Correct value>
+BIGINT SMALLINT ALL_LOSSY <Correct value>
+BIGINT MEDIUMINT ALL_LOSSY <Correct value>
+BIGINT INT ALL_LOSSY <Correct value>
+BIGINT BIGINT ALL_LOSSY <Correct value>
+CHAR(20) CHAR(20) ALL_LOSSY <Correct value>
+CHAR(20) CHAR(30) ALL_LOSSY <Correct error>
+CHAR(20) CHAR(10) ALL_LOSSY <Correct value>
+CHAR(20) VARCHAR(20) ALL_LOSSY <Correct error>
+CHAR(20) VARCHAR(30) ALL_LOSSY <Correct error>
+CHAR(20) VARCHAR(10) ALL_LOSSY <Correct value>
+CHAR(20) TINYTEXT ALL_LOSSY <Correct error>
+CHAR(20) TEXT ALL_LOSSY <Correct error>
+CHAR(20) MEDIUMTEXT ALL_LOSSY <Correct error>
+CHAR(20) LONGTEXT ALL_LOSSY <Correct error>
+VARCHAR(20) VARCHAR(20) ALL_LOSSY <Correct value>
+VARCHAR(20) VARCHAR(30) ALL_LOSSY <Correct error>
+VARCHAR(20) VARCHAR(10) ALL_LOSSY <Correct value>
+VARCHAR(20) CHAR(30) ALL_LOSSY <Correct error>
+VARCHAR(20) CHAR(10) ALL_LOSSY <Correct value>
+VARCHAR(20) TINYTEXT ALL_LOSSY <Correct error>
+VARCHAR(20) TEXT ALL_LOSSY <Correct error>
+VARCHAR(20) MEDIUMTEXT ALL_LOSSY <Correct error>
+VARCHAR(20) LONGTEXT ALL_LOSSY <Correct error>
+VARCHAR(500) VARCHAR(500) ALL_LOSSY <Correct value>
+VARCHAR(500) VARCHAR(510) ALL_LOSSY <Correct error>
+VARCHAR(500) VARCHAR(255) ALL_LOSSY <Correct value>
+VARCHAR(500) TINYTEXT ALL_LOSSY <Correct value>
+VARCHAR(500) TEXT ALL_LOSSY <Correct error>
+VARCHAR(500) MEDIUMTEXT ALL_LOSSY <Correct error>
+VARCHAR(500) LONGTEXT ALL_LOSSY <Correct error>
+TINYTEXT VARCHAR(500) ALL_LOSSY <Correct error>
+TEXT VARCHAR(500) ALL_LOSSY <Correct value>
+MEDIUMTEXT VARCHAR(500) ALL_LOSSY <Correct value>
+LONGTEXT VARCHAR(500) ALL_LOSSY <Correct value>
+TINYTEXT CHAR(255) ALL_LOSSY <Correct error>
+TINYTEXT CHAR(250) ALL_LOSSY <Correct value>
+TEXT CHAR(255) ALL_LOSSY <Correct value>
+MEDIUMTEXT CHAR(255) ALL_LOSSY <Correct value>
+LONGTEXT CHAR(255) ALL_LOSSY <Correct value>
+TINYTEXT TINYTEXT ALL_LOSSY <Correct value>
+TINYTEXT TEXT ALL_LOSSY <Correct error>
+TEXT TINYTEXT ALL_LOSSY <Correct value>
+DECIMAL(10,5) DECIMAL(10,5) ALL_LOSSY <Correct value>
+DECIMAL(10,5) DECIMAL(10,6) ALL_LOSSY <Correct error>
+DECIMAL(10,5) DECIMAL(11,5) ALL_LOSSY <Correct error>
+DECIMAL(10,5) DECIMAL(11,6) ALL_LOSSY <Correct error>
+DECIMAL(10,5) DECIMAL(10,4) ALL_LOSSY <Correct value>
+DECIMAL(10,5) DECIMAL(9,5) ALL_LOSSY <Correct value>
+DECIMAL(10,5) DECIMAL(9,4) ALL_LOSSY <Correct value>
+FLOAT DECIMAL(10,5) ALL_LOSSY <Correct value>
+DOUBLE DECIMAL(10,5) ALL_LOSSY <Correct value>
+DECIMAL(10,5) FLOAT ALL_LOSSY <Correct value>
+DECIMAL(10,5) DOUBLE ALL_LOSSY <Correct value>
+FLOAT FLOAT ALL_LOSSY <Correct value>
+DOUBLE DOUBLE ALL_LOSSY <Correct value>
+FLOAT DOUBLE ALL_LOSSY <Correct error>
+DOUBLE FLOAT ALL_LOSSY <Correct value>
+BIT(5) BIT(5) ALL_LOSSY <Correct value>
+BIT(5) BIT(6) ALL_LOSSY <Correct error>
+BIT(6) BIT(5) ALL_LOSSY <Correct value>
+BIT(5) BIT(12) ALL_LOSSY <Correct error>
+BIT(12) BIT(5) ALL_LOSSY <Correct value>
+TINYBLOB COMPRE TINYBLOB ALL_LOSSY <Correct error>
+TINYBLOB COMPRE BLOB ALL_LOSSY <Correct error>
+TINYBLOB COMPRE MEDIUMBLOB ALL_LOSSY <Correct error>
+TINYBLOB COMPRE LONGBLOB ALL_LOSSY <Correct error>
+TINYBLOB COMPRE VARBINARY(255) ALL_LOSSY <Correct error>
+BLOB COMPRESSED TINYBLOB ALL_LOSSY <Correct value>
+BLOB COMPRESSED BLOB ALL_LOSSY <Correct error>
+BLOB COMPRESSED MEDIUMBLOB ALL_LOSSY <Correct error>
+BLOB COMPRESSED LONGBLOB ALL_LOSSY <Correct error>
+BLOB COMPRESSED VARBINARY(65500 ALL_LOSSY <Correct value>
+MEDIUMBLOB COMP TINYBLOB ALL_LOSSY <Correct value>
+MEDIUMBLOB COMP BLOB ALL_LOSSY <Correct value>
+MEDIUMBLOB COMP MEDIUMBLOB ALL_LOSSY <Correct error>
+MEDIUMBLOB COMP LONGBLOB ALL_LOSSY <Correct error>
+MEDIUMBLOB COMP VARBINARY(65500 ALL_LOSSY <Correct value>
+LONGBLOB COMPRE TINYBLOB ALL_LOSSY <Correct value>
+LONGBLOB COMPRE BLOB ALL_LOSSY <Correct value>
+LONGBLOB COMPRE MEDIUMBLOB ALL_LOSSY <Correct value>
+LONGBLOB COMPRE LONGBLOB ALL_LOSSY <Correct error>
+LONGBLOB COMPRE VARBINARY(65500 ALL_LOSSY <Correct value>
+TINYBLOB BLOB ALL_LOSSY <Correct error>
+TINYBLOB MEDIUMBLOB ALL_LOSSY <Correct error>
+TINYBLOB LONGBLOB ALL_LOSSY <Correct error>
+TINYBLOB VARBINARY(255) ALL_LOSSY <Correct error>
+BLOB TINYBLOB ALL_LOSSY <Correct value>
+BLOB MEDIUMBLOB ALL_LOSSY <Correct error>
+BLOB LONGBLOB ALL_LOSSY <Correct error>
+BLOB VARBINARY(65500 ALL_LOSSY <Correct value>
+MEDIUMBLOB TINYBLOB ALL_LOSSY <Correct value>
+MEDIUMBLOB BLOB ALL_LOSSY <Correct value>
+MEDIUMBLOB LONGBLOB ALL_LOSSY <Correct error>
+MEDIUMBLOB VARBINARY(65500 ALL_LOSSY <Correct value>
+LONGBLOB TINYBLOB ALL_LOSSY <Correct value>
+LONGBLOB BLOB ALL_LOSSY <Correct value>
+LONGBLOB MEDIUMBLOB ALL_LOSSY <Correct value>
+LONGBLOB VARBINARY(65500 ALL_LOSSY <Correct value>
+DATE DATETIME(6) ALL_LOSSY <Correct error>
+DATE DATETIME(6) ALL_LOSSY <Correct error>
+DATE DATETIME(6) ALL_LOSSY <Correct error>
+DATE DATETIME(0) ALL_LOSSY <Correct error>
+DATETIME(6) DATE ALL_LOSSY <Correct value>
+DATETIME(6) DATE ALL_LOSSY <Correct value>
+DATETIME(0) DATE ALL_LOSSY <Correct value>
+TINYBLOB TINYBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYBLOB BLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYBLOB MEDIUMBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYBLOB LONGBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BLOB TINYBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BLOB BLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BLOB MEDIUMBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BLOB LONGBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB TINYBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB BLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB MEDIUMBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB LONGBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+LONGBLOB TINYBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+LONGBLOB BLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+LONGBLOB MEDIUMBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+LONGBLOB LONGBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+GEOMETRY BLOB ALL_LOSSY,ALL_NON_LOSSY <Correct error>
+BLOB GEOMETRY ALL_LOSSY,ALL_NON_LOSSY <Correct error>
+GEOMETRY GEOMETRY ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BIT(1) BIT(1) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DATE DATE ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+ENUM('master',' ENUM('master',' ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+CHAR(10) ENUM('master',' ALL_LOSSY,ALL_NON_LOSSY <Correct error>
+CHAR(10) SET('master','s ALL_LOSSY,ALL_NON_LOSSY <Correct error>
+ENUM('master',' CHAR(10) ALL_LOSSY,ALL_NON_LOSSY <Correct error>
+SET('master','s CHAR(10) ALL_LOSSY,ALL_NON_LOSSY <Correct error>
+SET('master','s SET('master','s ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+SET('master','s SET('master','s ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+SET('0','1','2' SET('0','1','2' ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+SET('0','1','2' SET('0','1','2' ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+SET('0','1','2' SET('0','1','2' ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+SET('0','1','2' SET('0','1','2' ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYINT TINYINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYINT SMALLINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYINT MEDIUMINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYINT INT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYINT BIGINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+SMALLINT TINYINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+SMALLINT TINYINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+SMALLINT TINYINT UNSIGNE ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+SMALLINT SMALLINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+SMALLINT MEDIUMINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+SMALLINT INT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+SMALLINT BIGINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMINT TINYINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMINT TINYINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMINT TINYINT UNSIGNE ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMINT SMALLINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMINT MEDIUMINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMINT INT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMINT BIGINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+INT TINYINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+INT TINYINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+INT TINYINT UNSIGNE ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+INT SMALLINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+INT MEDIUMINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+INT INT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+INT BIGINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BIGINT TINYINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BIGINT SMALLINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BIGINT MEDIUMINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BIGINT INT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BIGINT BIGINT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+CHAR(20) CHAR(20) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+CHAR(20) CHAR(30) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+CHAR(20) CHAR(10) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+CHAR(20) VARCHAR(20) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+CHAR(20) VARCHAR(30) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+CHAR(20) VARCHAR(10) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+CHAR(20) TINYTEXT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+CHAR(20) TEXT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+CHAR(20) MEDIUMTEXT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+CHAR(20) LONGTEXT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(20) VARCHAR(20) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(20) VARCHAR(30) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(20) VARCHAR(10) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(20) CHAR(30) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(20) CHAR(10) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(20) TINYTEXT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(20) TEXT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(20) MEDIUMTEXT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(20) LONGTEXT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(500) VARCHAR(500) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(500) VARCHAR(510) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(500) VARCHAR(255) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(500) TINYTEXT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(500) TEXT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(500) MEDIUMTEXT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+VARCHAR(500) LONGTEXT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYTEXT VARCHAR(500) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TEXT VARCHAR(500) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMTEXT VARCHAR(500) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+LONGTEXT VARCHAR(500) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYTEXT CHAR(255) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYTEXT CHAR(250) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TEXT CHAR(255) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMTEXT CHAR(255) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+LONGTEXT CHAR(255) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYTEXT TINYTEXT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYTEXT TEXT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TEXT TINYTEXT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DECIMAL(10,5) DECIMAL(10,5) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DECIMAL(10,5) DECIMAL(10,6) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DECIMAL(10,5) DECIMAL(11,5) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DECIMAL(10,5) DECIMAL(11,6) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DECIMAL(10,5) DECIMAL(10,4) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DECIMAL(10,5) DECIMAL(9,5) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DECIMAL(10,5) DECIMAL(9,4) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+FLOAT DECIMAL(10,5) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DOUBLE DECIMAL(10,5) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DECIMAL(10,5) FLOAT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DECIMAL(10,5) DOUBLE ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+FLOAT FLOAT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DOUBLE DOUBLE ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+FLOAT DOUBLE ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DOUBLE FLOAT ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BIT(5) BIT(5) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BIT(5) BIT(6) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BIT(6) BIT(5) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BIT(5) BIT(12) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BIT(12) BIT(5) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYBLOB COMPRE TINYBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYBLOB COMPRE BLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYBLOB COMPRE MEDIUMBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYBLOB COMPRE LONGBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYBLOB COMPRE VARBINARY(255) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BLOB COMPRESSED TINYBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BLOB COMPRESSED BLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BLOB COMPRESSED MEDIUMBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BLOB COMPRESSED LONGBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BLOB COMPRESSED VARBINARY(65500 ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB COMP TINYBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB COMP BLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB COMP MEDIUMBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB COMP LONGBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB COMP VARBINARY(65500 ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+LONGBLOB COMPRE TINYBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+LONGBLOB COMPRE BLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+LONGBLOB COMPRE MEDIUMBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+LONGBLOB COMPRE LONGBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+LONGBLOB COMPRE VARBINARY(65500 ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYBLOB BLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYBLOB MEDIUMBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYBLOB LONGBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+TINYBLOB VARBINARY(255) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BLOB TINYBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BLOB MEDIUMBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BLOB LONGBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+BLOB VARBINARY(65500 ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB TINYBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB BLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB LONGBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+MEDIUMBLOB VARBINARY(65500 ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+LONGBLOB TINYBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+LONGBLOB BLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+LONGBLOB MEDIUMBLOB ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+LONGBLOB VARBINARY(65500 ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DATE DATETIME(6) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DATE DATETIME(6) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DATE DATETIME(6) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DATE DATETIME(0) ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DATETIME(6) DATE ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DATETIME(6) DATE ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DATETIME(0) DATE ALL_LOSSY,ALL_NON_LOSSY <Correct value>
+DROP TABLE type_conversions;
+call mtr.add_suppression("Slave SQL.*Column 1 of table .test.t1. cannot be converted from type.* error.* 1677");
+connection master;
+DROP TABLE t1;
+connection slave;
+set global slave_type_conversions = @saved_slave_type_conversions;
+include/rpl_end.inc
diff --git a/mysql-test/suite/binlog_encryption/rpl_typeconv.test b/mysql-test/suite/binlog_encryption/rpl_typeconv.test
new file mode 100644
index 00000000..6761cddf
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/rpl_typeconv.test
@@ -0,0 +1 @@
+--source suite/rpl/t/rpl_typeconv.test
diff --git a/mysql-test/suite/binlog_encryption/suite.pm b/mysql-test/suite/binlog_encryption/suite.pm
new file mode 100644
index 00000000..f1d5e3aa
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/suite.pm
@@ -0,0 +1,18 @@
+package My::Suite::BinlogEncryption;
+
+@ISA = qw(My::Suite);
+
+return "No file key management plugin" unless defined $ENV{FILE_KEY_MANAGEMENT_SO};
+
+sub skip_combinations {
+ my @combinations;
+
+ $skip{'encryption_algorithms.combinations'} = [ 'ctr' ]
+ unless $::mysqld_variables{'version-ssl-library'} =~ /OpenSSL (\S+)/
+ and $1 ge "1.0.1";
+
+ %skip;
+}
+
+bless { };
+
diff --git a/mysql-test/suite/binlog_encryption/testdata.inc b/mysql-test/suite/binlog_encryption/testdata.inc
new file mode 100644
index 00000000..7f2b0505
--- /dev/null
+++ b/mysql-test/suite/binlog_encryption/testdata.inc
@@ -0,0 +1,208 @@
+#
+# This include file creates some basic events which should go to the binary log.
+# What happens to the binary log depends on the test which calls the file,
+# and should be checked from the test.
+#
+# Names are intentionally long and ugly, to make grepping more reliable.
+#
+# Some of events are considered unsafe for SBR (not necessarily correctly,
+# but here isn't the place to check the logic), so we just suppress the warning.
+#
+# For those few queries which produce result sets (e.g. ANALYZE, CHECKSUM etc.),
+# we don't care about the result, so it will not be printed to the output.
+
+call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
+
+#
+# Some DDL
+#
+
+CREATE DATABASE database_name_to_encrypt;
+USE database_name_to_encrypt;
+
+CREATE USER user_name_to_encrypt;
+GRANT ALL ON database_name_to_encrypt.* TO user_name_to_encrypt;
+SET PASSWORD FOR user_name_to_encrypt = PASSWORD('password_to_encrypt');
+
+CREATE TABLE innodb_table_name_to_encrypt (
+ int_column_name_to_encrypt INT PRIMARY KEY,
+ timestamp_column_name_to_encrypt TIMESTAMP(6) NULL,
+ blob_column_name_to_encrypt BLOB,
+ virt_column_name_to_encrypt INT AS (int_column_name_to_encrypt % 10) VIRTUAL,
+ pers_column_name_to_encrypt INT AS (int_column_name_to_encrypt) PERSISTENT,
+ INDEX `index_name_to_encrypt`(`timestamp_column_name_to_encrypt`)
+) ENGINE=InnoDB
+ PARTITION BY RANGE (int_column_name_to_encrypt)
+ SUBPARTITION BY KEY (int_column_name_to_encrypt)
+ SUBPARTITIONS 2 (
+ PARTITION partition0_name_to_encrypt VALUES LESS THAN (100),
+ PARTITION partition1_name_to_encrypt VALUES LESS THAN (MAXVALUE)
+ )
+;
+
+CREATE TABLE myisam_table_name_to_encrypt (
+ int_column_name_to_encrypt INT AUTO_INCREMENT PRIMARY KEY,
+ char_column_name_to_encrypt VARCHAR(255),
+ datetime_column_name_to_encrypt DATETIME,
+ text_column_name_to_encrypt TEXT
+) ENGINE=MyISAM;
+
+CREATE TABLE aria_table_name_to_encrypt (
+ int_column_name_to_encrypt INT AUTO_INCREMENT PRIMARY KEY,
+ varchar_column_name_to_encrypt VARCHAR(1024),
+ enum_column_name_to_encrypt ENUM(
+ 'enum_value1_to_encrypt',
+ 'enum_value2_to_encrypt'
+ ),
+ timestamp_column_name_to_encrypt TIMESTAMP(6) NULL,
+ blob_column_name_to_encrypt BLOB
+) ENGINE=Aria;
+
+CREATE TRIGGER trigger_name_to_encrypt
+ AFTER INSERT ON myisam_table_name_to_encrypt FOR EACH ROW
+ INSERT INTO aria_table_name_to_encrypt (varchar_column_name_to_encrypt)
+ VALUES (NEW.char_column_name_to_encrypt);
+
+CREATE DEFINER=user_name_to_encrypt VIEW view_name_to_encrypt
+ AS SELECT * FROM innodb_table_name_to_encrypt;
+
+CREATE FUNCTION func_name_to_encrypt (func_parameter_to_encrypt INT)
+ RETURNS VARCHAR(64)
+ RETURN 'func_result_to_encrypt';
+
+--delimiter $$
+CREATE PROCEDURE proc_name_to_encrypt (
+ IN proc_in_parameter_to_encrypt CHAR(32),
+ OUT proc_out_parameter_to_encrypt INT
+)
+BEGIN
+ DECLARE procvar_name_to_encrypt CHAR(64) DEFAULT 'procvar_val_to_encrypt';
+ DECLARE cursor_name_to_encrypt CURSOR FOR
+ SELECT virt_column_name_to_encrypt FROM innodb_table_name_to_encrypt;
+ DECLARE EXIT HANDLER FOR NOT FOUND
+ BEGIN
+ SET @stmt_var_to_encrypt = CONCAT(
+ "SELECT
+ IF (RAND()>0.5,'enum_value2_to_encrypt','enum_value1_to_encrypt')
+ FROM innodb_table_name_to_encrypt
+ INTO OUTFILE '", proc_in_parameter_to_encrypt, "'");
+ PREPARE stmt_to_encrypt FROM @stmt_var_to_encrypt;
+ EXECUTE stmt_to_encrypt;
+ DEALLOCATE PREPARE stmt_to_encrypt;
+ END;
+ OPEN cursor_name_to_encrypt;
+ proc_label_to_encrypt: LOOP
+ FETCH cursor_name_to_encrypt INTO procvar_name_to_encrypt;
+ END LOOP;
+ CLOSE cursor_name_to_encrypt;
+END $$
+--delimiter ;
+
+CREATE SERVER server_name_to_encrypt
+ FOREIGN DATA WRAPPER mysql
+ OPTIONS (HOST 'host_name_to_encrypt');
+
+--let $_cur_con= $CURRENT_CONNECTION
+--connect (con1,localhost,user_name_to_encrypt,password_to_encrypt,database_name_to_encrypt)
+CREATE TEMPORARY TABLE tmp_table_name_to_encrypt (
+ float_column_name_to_encrypt FLOAT,
+ binary_column_name_to_encrypt BINARY(64)
+);
+--disconnect con1
+--connection $_cur_con
+
+CREATE INDEX index_name_to_encrypt
+ ON myisam_table_name_to_encrypt (datetime_column_name_to_encrypt);
+
+ALTER DATABASE database_name_to_encrypt CHARACTER SET utf8;
+
+ALTER TABLE innodb_table_name_to_encrypt
+ MODIFY timestamp_column_name_to_encrypt TIMESTAMP NOT NULL
+ DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
+;
+
+ALTER ALGORITHM=MERGE VIEW view_name_to_encrypt
+ AS SELECT * FROM innodb_table_name_to_encrypt;
+
+RENAME TABLE innodb_table_name_to_encrypt TO new_table_name_to_encrypt;
+ALTER TABLE new_table_name_to_encrypt RENAME TO innodb_table_name_to_encrypt;
+
+#
+# Some DML
+#
+
+--disable_warnings
+
+set @user_var1_to_encrypt= 'dyncol1_val_to_encrypt';
+set @user_var2_to_encrypt= 'dyncol2_name_to_encrypt';
+
+INSERT INTO view_name_to_encrypt VALUES
+ (1, NOW(6), COLUMN_CREATE('dyncol1_name_to_encrypt',@user_var1_to_encrypt), NULL, NULL),
+ (2, NOW(6), COLUMN_CREATE(@user_var2_to_encrypt,'dyncol2_val_to_encrypt'), NULL, NULL)
+;
+--delimiter $$
+BEGIN NOT ATOMIC
+ DECLARE counter_name_to_encrypt INT DEFAULT 0;
+ START TRANSACTION;
+ WHILE counter_name_to_encrypt<12 DO
+ SELECT COUNT(*) INTO @cnt FROM innodb_table_name_to_encrypt;
+ INSERT INTO innodb_table_name_to_encrypt
+ SELECT int_column_name_to_encrypt+@cnt, NOW(6), blob_column_name_to_encrypt, NULL, NULL
+ FROM innodb_table_name_to_encrypt
+ ORDER BY int_column_name_to_encrypt;
+ SET counter_name_to_encrypt = counter_name_to_encrypt+1;
+ END WHILE;
+ COMMIT;
+ END
+$$
+--delimiter ;
+
+INSERT INTO myisam_table_name_to_encrypt
+ SELECT NULL, 'char_literal_to_encrypt', NULL, 'text_to_encrypt';
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+ SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+ SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+INSERT INTO myisam_table_name_to_encrypt (char_column_name_to_encrypt)
+ SELECT char_column_name_to_encrypt FROM myisam_table_name_to_encrypt;
+
+CALL proc_name_to_encrypt('file_name_to_encrypt',@useless_var_to_encrypt);
+
+TRUNCATE TABLE aria_table_name_to_encrypt;
+
+LOAD DATA INFILE 'file_name_to_encrypt' INTO TABLE aria_table_name_to_encrypt
+ (enum_column_name_to_encrypt);
+
+--let datadir= `SELECT @@datadir`
+--replace_result $datadir <DATADIR>
+eval LOAD DATA LOCAL INFILE '$datadir/database_name_to_encrypt/file_name_to_encrypt'
+ INTO TABLE aria_table_name_to_encrypt (enum_column_name_to_encrypt);
+--remove_file $datadir/database_name_to_encrypt/file_name_to_encrypt
+
+UPDATE view_name_to_encrypt SET blob_column_name_to_encrypt =
+ COLUMN_CREATE('dyncol1_name_to_encrypt',func_name_to_encrypt(0))
+;
+
+DELETE FROM aria_table_name_to_encrypt ORDER BY int_column_name_to_encrypt LIMIT 10;
+
+--enable_warnings
+
+#
+# Other statements
+#
+
+--disable_result_log
+ANALYZE TABLE myisam_table_name_to_encrypt;
+CHECK TABLE aria_table_name_to_encrypt;
+CHECKSUM TABLE innodb_table_name_to_encrypt, myisam_table_name_to_encrypt;
+--enable_result_log
+RENAME USER user_name_to_encrypt to new_user_name_to_encrypt;
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM new_user_name_to_encrypt;
+
+#
+# Cleanup
+#
+
+DROP DATABASE database_name_to_encrypt;
+DROP USER new_user_name_to_encrypt;
+DROP SERVER server_name_to_encrypt;