summaryrefslogtreecommitdiff
path: root/mysql-test/suite/encryption
diff options
context:
space:
mode:
Diffstat (limited to 'mysql-test/suite/encryption')
-rw-r--r--mysql-test/suite/encryption/disabled.def2
-rw-r--r--mysql-test/suite/encryption/include/innodb-util.pl126
-rw-r--r--mysql-test/suite/encryption/r/filekeys_tooshort.result10
-rw-r--r--mysql-test/suite/encryption/r/innodb-bad-key-change.result9
-rw-r--r--mysql-test/suite/encryption/r/innodb-missing-key.result54
-rw-r--r--mysql-test/suite/encryption/r/innodb_encryption_discard_import.result47
-rw-r--r--mysql-test/suite/encryption/r/innodb_lotoftables.result154
-rw-r--r--mysql-test/suite/encryption/t/filekeys-tooshort.enc1
-rw-r--r--mysql-test/suite/encryption/t/filekeys_tooshort.opt3
-rw-r--r--mysql-test/suite/encryption/t/filekeys_tooshort.test4
-rw-r--r--mysql-test/suite/encryption/t/innodb-bad-key-change.test32
-rw-r--r--mysql-test/suite/encryption/t/innodb-missing-key.opt5
-rw-r--r--mysql-test/suite/encryption/t/innodb-missing-key.test68
-rw-r--r--mysql-test/suite/encryption/t/innodb-page_encryption_compression.test3
-rw-r--r--mysql-test/suite/encryption/t/innodb_encryption_discard_import.test98
-rw-r--r--mysql-test/suite/encryption/t/innodb_lotoftables.opt3
-rw-r--r--mysql-test/suite/encryption/t/innodb_lotoftables.test274
17 files changed, 757 insertions, 136 deletions
diff --git a/mysql-test/suite/encryption/disabled.def b/mysql-test/suite/encryption/disabled.def
index 26540e18f06..f8d7fb51865 100644
--- a/mysql-test/suite/encryption/disabled.def
+++ b/mysql-test/suite/encryption/disabled.def
@@ -13,4 +13,4 @@
innodb_scrub : MDEV-8139
innodb_scrub_compressed : MDEV-8139
innodb_scrub_background : MDEV-8139
-innodb_encryption_discard_import : MDEV-9099
+innochecksum: see buf_page_is_corrupted()
diff --git a/mysql-test/suite/encryption/include/innodb-util.pl b/mysql-test/suite/encryption/include/innodb-util.pl
new file mode 100644
index 00000000000..241545dac18
--- /dev/null
+++ b/mysql-test/suite/encryption/include/innodb-util.pl
@@ -0,0 +1,126 @@
+#
+# Utility functions to copy files for WL#5522
+#
+# All the tables must be in the same database, you can call it like so:
+# ib_backup_tablespaces("test", "t1", "blah", ...).
+
+use File::Copy;
+use File::Spec;
+
+sub ib_normalize_path {
+ my ($path) = @_;
+}
+
+sub ib_backup_tablespace {
+ my ($db, $table) = @_;
+ my $datadir = $ENV{'MYSQLD_DATADIR'};
+ my $cfg_file = sprintf("%s.cfg", $table);
+ my $ibd_file = sprintf("%s.ibd", $table);
+ my $tmpd = $ENV{'MYSQLTEST_VARDIR'} . "/tmp";
+
+ my @args = (File::Spec->catfile($datadir, $db, $ibd_file),
+ File::Spec->catfile($tmpd, $ibd_file));
+
+ copy(@args) or die "copy @args failed: $!";
+
+ my @args = (File::Spec->catfile($datadir, $db, $cfg_file),
+ File::Spec->catfile($tmpd, $cfg_file));
+
+ copy(@args) or die "copy @args failed: $!";
+}
+
+sub ib_cleanup {
+ my ($db, $table) = @_;
+ my $datadir = $ENV{'MYSQLD_DATADIR'};
+ my $cfg_file = sprintf("%s.cfg", $table);
+
+ print "unlink: $cfg_file\n";
+
+ # These may or may not exist
+ unlink(File::Spec->catfile($datadir, $db, $cfg_file));
+}
+
+sub ib_unlink_tablespace {
+ my ($db, $table) = @_;
+ my $datadir = $ENV{'MYSQLD_DATADIR'};
+ my $ibd_file = sprintf("%s.ibd", $table);
+
+ print "unlink: $ibd_file\n";
+ # This may or may not exist
+ unlink(File::Spec->catfile($datadir, $db, $ibd_file));
+
+ ib_cleanup($db, $table);
+}
+
+sub ib_backup_tablespaces {
+ my ($db, @tables) = @_;
+
+ foreach my $table (@tables) {
+ print "backup: $table\n";
+ ib_backup_tablespace($db, $table);
+ }
+}
+
+sub ib_discard_tablespace { }
+
+sub ib_discard_tablespaces { }
+
+sub ib_restore_cfg_file {
+ my ($tmpd, $datadir, $db, $table) = @_;
+ my $cfg_file = sprintf("%s.cfg", $table);
+
+ my @args = (File::Spec->catfile($tmpd, $cfg_file),
+ File::Spec->catfile($datadir, "$db", $cfg_file));
+
+ copy(@args) or die "copy @args failed: $!";
+}
+
+sub ib_restore_ibd_file {
+ my ($tmpd, $datadir, $db, $table) = @_;
+ my $ibd_file = sprintf("%s.ibd", $table);
+
+ my @args = (File::Spec->catfile($tmpd, $ibd_file),
+ File::Spec->catfile($datadir, $db, $ibd_file));
+
+ copy(@args) or die "copy @args failed: $!";
+}
+
+sub ib_restore_tablespace {
+ my ($db, $table) = @_;
+ my $datadir = $ENV{'MYSQLD_DATADIR'};
+ my $tmpd = $ENV{'MYSQLTEST_VARDIR'} . "/tmp";
+
+ ib_restore_cfg_file($tmpd, $datadir, $db, $table);
+ ib_restore_ibd_file($tmpd, $datadir, $db, $table);
+}
+
+sub ib_restore_tablespaces {
+ my ($db, @tables) = @_;
+
+ foreach my $table (@tables) {
+ print "restore: $table .ibd and .cfg files\n";
+ ib_restore_tablespace($db, $table);
+ }
+}
+
+sub ib_restore_cfg_files {
+ my ($db, @tables) = @_;
+ my $datadir = $ENV{'MYSQLD_DATADIR'};
+ my $tmpd = $ENV{'MYSQLTEST_VARDIR'} . "/tmp";
+
+ foreach my $table (@tables) {
+ print "restore: $table .cfg file\n";
+ ib_restore_cfg_file($tmpd, $datadir, $db, $table);
+ }
+}
+
+sub ib_restore_ibd_files {
+ my ($db, @tables) = @_;
+ my $datadir = $ENV{'MYSQLD_DATADIR'};
+ my $tmpd = $ENV{'MYSQLTEST_VARDIR'} . "/tmp";
+
+ foreach my $table (@tables) {
+ print "restore: $table .ibd file\n";
+ ib_restore_ibd_file($tmpd, $datadir, $db, $table);
+ }
+}
diff --git a/mysql-test/suite/encryption/r/filekeys_tooshort.result b/mysql-test/suite/encryption/r/filekeys_tooshort.result
new file mode 100644
index 00000000000..efa66097563
--- /dev/null
+++ b/mysql-test/suite/encryption/r/filekeys_tooshort.result
@@ -0,0 +1,10 @@
+call mtr.add_suppression("Cannot decrypt .*tooshort.enc. Not encrypted");
+call mtr.add_suppression("Plugin 'file_key_management' init function returned error");
+call mtr.add_suppression("Plugin 'file_key_management' registration.*failed");
+FOUND /Cannot decrypt .*tooshort.enc. Not encrypted/ in mysqld.1.err
+create table t1(c1 bigint not null, b char(200)) engine=innodb encrypted=yes encryption_key_id=1;
+ERROR HY000: Can't create table `test`.`t1` (errno: 140 "Wrong create options")
+select plugin_status from information_schema.plugins
+where plugin_name = 'file_key_management';
+plugin_status
+# Test checks if opening an too short filekeys does not crash the server.
diff --git a/mysql-test/suite/encryption/r/innodb-bad-key-change.result b/mysql-test/suite/encryption/r/innodb-bad-key-change.result
index ef5b726d4cb..7c6a9d2ba83 100644
--- a/mysql-test/suite/encryption/r/innodb-bad-key-change.result
+++ b/mysql-test/suite/encryption/r/innodb-bad-key-change.result
@@ -39,12 +39,15 @@ SELECT * FROM t1;
ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
SHOW WARNINGS;
Level Code Message
-Warning 192 Table test/t1 in tablespace # is encrypted but encryption service or used key_id is not available. Can't continue reading table.
+Warning 192 Table test/t1 in tablespace is encrypted but encryption service or used key_id is not available. Can't continue reading table.
Warning 192 Table test/t1 is encrypted but encryption service or used key_id 2 is not available. Can't continue reading table.
Error 1296 Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
DROP TABLE t1;
Warnings:
-Warning 192 Table in tablespace # encrypted.However key management plugin or used key_id 1 is not found or used encryption algorithm or method does not match. Can't continue opening the table.
+Warning 192 Table in tablespace encrypted.However key management plugin or used key_id 1 is not found or used encryption algorithm or method does not match. Can't continue opening the table.
+SHOW WARNINGS;
+Level Code Message
+Warning 192 Table in tablespace encrypted.However key management plugin or used key_id 1 is not found or used encryption algorithm or method does not match. Can't continue opening the table.
# Start server with keys.txt
CREATE TABLE t2 (c VARCHAR(8), id int not null primary key, b int, key(b)) ENGINE=InnoDB ENCRYPTED=YES;
INSERT INTO t2 VALUES ('foobar',1,2);
@@ -54,7 +57,7 @@ SELECT * FROM t2;
ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
SHOW WARNINGS;
Level Code Message
-Warning 192 is encrypted but encryption service or used key_id is not available. Can't continue reading table.
+Warning 192 Table test/t2 in tablespace is encrypted but encryption service or used key_id is not available. Can't continue reading table.
Warning 192 Table test/t2 is encrypted but encryption service or used key_id is not available. Can't continue reading table.
Error 1296 Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
SELECT * FROM t2 where id = 1;
diff --git a/mysql-test/suite/encryption/r/innodb-missing-key.result b/mysql-test/suite/encryption/r/innodb-missing-key.result
new file mode 100644
index 00000000000..b59ec158273
--- /dev/null
+++ b/mysql-test/suite/encryption/r/innodb-missing-key.result
@@ -0,0 +1,54 @@
+call mtr.add_suppression("InnoDB: Block in space_id .* in file test/.* encrypted");
+call mtr.add_suppression("InnoDB: However key management plugin or used key_id .* is not found or used encryption algorithm or method does not match.");
+call mtr.add_suppression("InnoDB: Marking tablespace as missing. You may drop this table or install correct key management plugin and key file.");
+
+# Start server with keys2.txt
+CREATE TABLE t1(a int not null primary key auto_increment, b varchar(128)) engine=innodb ENCRYPTED=YES ENCRYPTION_KEY_ID=19;
+CREATE TABLE t2(a int not null primary key auto_increment, b varchar(128)) engine=innodb ENCRYPTED=YES ENCRYPTION_KEY_ID=1;
+CREATE TABLE t3(a int not null primary key auto_increment, b varchar(128)) engine=innodb ENCRYPTED=NO;
+INSERT INTO t1(b) VALUES ('thisissecredmessage');
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t2 SELECT * FROM t1;
+INSERT INTO t3 SELECT * FROM t1;
+
+# Restart server with keys3.txt
+set global innodb_encryption_rotate_key_age = 1;
+use test;
+CREATE TABLE t4(a int not null primary key auto_increment, b varchar(128)) engine=innodb ENCRYPTED=YES ENCRYPTION_KEY_ID=1;
+SELECT SLEEP(5);
+SLEEP(5)
+0
+SELECT COUNT(1) FROM t3;
+COUNT(1)
+2048
+SELECT COUNT(1) FROM t2;
+COUNT(1)
+2048
+SELECT COUNT(1) FROM t2,t1 where t2.a = t1.a;
+ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
+SELECT COUNT(1) FROM t1 where b = 'ab';
+ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
+SELECT COUNT(1) FROM t1;
+ERROR HY000: Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB
+
+# Start server with keys2.txt
+SELECT COUNT(1) FROM t1;
+COUNT(1)
+2048
+SELECT COUNT(1) FROM t2;
+COUNT(1)
+2048
+SELECT COUNT(1) FROM t3;
+COUNT(1)
+2048
+DROP TABLE t1, t2, t3;
diff --git a/mysql-test/suite/encryption/r/innodb_encryption_discard_import.result b/mysql-test/suite/encryption/r/innodb_encryption_discard_import.result
index 5bb3b2bc41e..2764d7262d9 100644
--- a/mysql-test/suite/encryption/r/innodb_encryption_discard_import.result
+++ b/mysql-test/suite/encryption/r/innodb_encryption_discard_import.result
@@ -31,66 +31,41 @@ NOT FOUND /foobar/ in t1.ibd
NOT FOUND /temp/ in t2.ibd
# t3 ... on expecting NOT FOUND
NOT FOUND /barfoo/ in t3.ibd
-FLUSH TABLE t1, t2, t3 FOR EXPORT;
-# List before copying files
-t1.cfg
t1.frm
t1.ibd
-t2.cfg
t2.frm
t2.ibd
-t3.cfg
t3.frm
t3.ibd
-UNLOCK TABLES;
-# Restarting server
-# Done restarting server
-# List before t1 DISCARD
+FLUSH TABLES t1, t2, t3 FOR EXPORT;
+backup: t1
+backup: t2
+backup: t3
+t1.cfg
t1.frm
t1.ibd
+t2.cfg
t2.frm
t2.ibd
+t3.cfg
t3.frm
t3.ibd
-SET GLOBAL innodb_file_format = `Barracuda`;
-Warnings:
-Warning 131 Using innodb_file_format is deprecated and the parameter may be removed in future releases. See http://dev.mysql.com/doc/refman/5.7/en/innodb-file-format.html
-SET GLOBAL innodb_file_per_table = ON;
+UNLOCK TABLES;
ALTER TABLE t1 DISCARD TABLESPACE;
ALTER TABLE t2 DISCARD TABLESPACE;
ALTER TABLE t3 DISCARD TABLESPACE;
-# List after t1 DISCARD
-t1.frm
-t2.frm
-t3.frm
-# Restarting server
-# Done restarting server
-SET GLOBAL innodb_file_format = `Barracuda`;
-Warnings:
-Warning 131 Using innodb_file_format is deprecated and the parameter may be removed in future releases. See http://dev.mysql.com/doc/refman/5.7/en/innodb-file-format.html
-SET GLOBAL innodb_file_per_table = ON;
-# Tablespaces should be still encrypted
-# t1 yes on expecting NOT FOUND
-NOT FOUND /foobar/ in t1.ibd
-# t2 ... on expecting NOT FOUND
-NOT FOUND /temp/ in t2.ibd
-# t3 ... on expecting NOT FOUND
-NOT FOUND /barfoo/ in t3.ibd
+restore: t1 .ibd and .cfg files
+restore: t2 .ibd and .cfg files
+restore: t3 .ibd and .cfg files
ALTER TABLE t1 IMPORT TABLESPACE;
-Warnings:
-Warning 1814 Tablespace has been discarded for table 't1'
SELECT COUNT(1) FROM t1;
COUNT(1)
10000
ALTER TABLE t2 IMPORT TABLESPACE;
-Warnings:
-Warning 1814 Tablespace has been discarded for table 't2'
SELECT COUNT(1) FROM t2;
COUNT(1)
10000
ALTER TABLE t3 IMPORT TABLESPACE;
-Warnings:
-Warning 1814 Tablespace has been discarded for table 't3'
SELECT COUNT(1) FROM t3;
COUNT(1)
10000
diff --git a/mysql-test/suite/encryption/r/innodb_lotoftables.result b/mysql-test/suite/encryption/r/innodb_lotoftables.result
new file mode 100644
index 00000000000..34f2684253e
--- /dev/null
+++ b/mysql-test/suite/encryption/r/innodb_lotoftables.result
@@ -0,0 +1,154 @@
+SET GLOBAL innodb_file_format = `Barracuda`;
+SET GLOBAL innodb_file_per_table = ON;
+SHOW VARIABLES LIKE 'innodb_encrypt%';
+Variable_name Value
+innodb_encrypt_log OFF
+innodb_encrypt_tables OFF
+innodb_encryption_rotate_key_age 1
+innodb_encryption_rotation_iops 100
+innodb_encryption_threads 0
+create database innodb_encrypted_1;
+use innodb_encrypted_1;
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 3
+set autocommit=0;
+set autocommit=1;
+commit work;
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 3
+# should be 100
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE NAME LIKE 'innodb_encrypted%';
+COUNT(*)
+100
+create database innodb_encrypted_2;
+use innodb_encrypted_2;
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 3
+set autocommit=0;
+commit work;
+set autocommit=1;
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 3
+# should be 100
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 AND NAME LIKE 'innodb_encrypted%';
+COUNT(*)
+100
+# should be 100
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 AND NAME LIKE 'innodb_encrypted%';
+COUNT(*)
+100
+create database innodb_encrypted_3;
+use innodb_encrypted_3;
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 3
+set autocommit=0;
+commit work;
+set autocommit=1;
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 3
+# should be 100
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 AND NAME LIKE 'innodb_encrypted%';
+COUNT(*)
+100
+# should be 200
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 AND NAME LIKE 'innodb_encrypted%';
+COUNT(*)
+200
+use test;
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 3
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 AND NAME LIKE 'innodb_encrypted%';
+COUNT(*)
+100
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 AND NAME LIKE 'innodb_encrypted%';
+COUNT(*)
+200
+SET GLOBAL innodb_encrypt_tables = on;
+SET GLOBAL innodb_encryption_threads=4;
+# Wait until all encrypted tables have been encrypted
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 AND NAME LIKE 'innodb_encrypted%';
+COUNT(*)
+200
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 AND NAME LIKE 'innodb_encrypted%';
+COUNT(*)
+100
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 3
+# Success!
+# Restart mysqld --innodb_encrypt_tables=0 --innodb_encryption_threads=0
+# Restart Success!
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 3
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 3
+use test;
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 3
+use innodb_encrypted_1;
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 3
+use innodb_encrypted_2;
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 3
+use innodb_encrypted_3;
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 3
+use innodb_encrypted_1;
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 3
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 103
+use innodb_encrypted_2;
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 103
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 203
+use innodb_encrypted_3;
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 203
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 303
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 AND NAME LIKE 'innodb_encrypted%';
+COUNT(*)
+100
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 AND NAME LIKE 'innodb_encrypted%';
+COUNT(*)
+200
+SET GLOBAL innodb_encrypt_tables = off;
+SET GLOBAL innodb_encryption_threads=4;
+# Wait until all default encrypted tables have been decrypted
+# should be 100
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 AND NAME LIKE 'innodb_encrypted%';
+COUNT(*)
+100
+# should be 200
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 AND NAME LIKE 'innodb_encrypted%';
+COUNT(*)
+200
+show status like 'innodb_pages0_read%';
+Variable_name Value
+Innodb_pages0_read 303
+use test;
+drop database innodb_encrypted_1;
+drop database innodb_encrypted_2;
+drop database innodb_encrypted_3;
diff --git a/mysql-test/suite/encryption/t/filekeys-tooshort.enc b/mysql-test/suite/encryption/t/filekeys-tooshort.enc
new file mode 100644
index 00000000000..9849236c7f4
--- /dev/null
+++ b/mysql-test/suite/encryption/t/filekeys-tooshort.enc
@@ -0,0 +1 @@
+Salted__ \ No newline at end of file
diff --git a/mysql-test/suite/encryption/t/filekeys_tooshort.opt b/mysql-test/suite/encryption/t/filekeys_tooshort.opt
new file mode 100644
index 00000000000..8999becc78d
--- /dev/null
+++ b/mysql-test/suite/encryption/t/filekeys_tooshort.opt
@@ -0,0 +1,3 @@
+--loose-file-key-management-filekey=secret
+--loose-file-key-management-filename=$MTR_SUITE_DIR/t/filekeys-tooshort.enc
+
diff --git a/mysql-test/suite/encryption/t/filekeys_tooshort.test b/mysql-test/suite/encryption/t/filekeys_tooshort.test
new file mode 100644
index 00000000000..b0e89675100
--- /dev/null
+++ b/mysql-test/suite/encryption/t/filekeys_tooshort.test
@@ -0,0 +1,4 @@
+let SEARCH_PATTERN=Cannot decrypt .*tooshort.enc. Not encrypted;
+source filekeys_badtest.inc;
+
+--echo # Test checks if opening an too short filekeys does not crash the server.
diff --git a/mysql-test/suite/encryption/t/innodb-bad-key-change.test b/mysql-test/suite/encryption/t/innodb-bad-key-change.test
index 49e0fc8ee48..3bcce90b01a 100644
--- a/mysql-test/suite/encryption/t/innodb-bad-key-change.test
+++ b/mysql-test/suite/encryption/t/innodb-bad-key-change.test
@@ -56,13 +56,15 @@ SELECT * FROM t1;
--error ER_GET_ERRMSG
SELECT * FROM t1;
---replace_regex /tablespace [0-9]*/tablespace #/
+--replace_regex /tablespace [0-9]*/tablespace /
SHOW WARNINGS;
-- let $restart_parameters=--file-key-management-filename=$MYSQL_TEST_DIR/std_data/keysbad3.txt
-- source include/restart_mysqld.inc
---replace_regex /tablespace [0-9]*/tablespace #/
+--replace_regex /tablespace [0-9]*/tablespace /
DROP TABLE t1;
+--replace_regex /tablespace [0-9]*/tablespace /
+SHOW WARNINGS;
#
# MDEV-8591: Database page corruption on disk or a failed space, Assertion failure in file buf0buf.cc
@@ -83,50 +85,50 @@ INSERT INTO t2 VALUES ('foobar',1,2);
--error ER_GET_ERRMSG
SELECT * FROM t2;
---replace_regex /.*tablespace [0-9]*//
+--replace_regex /tablespace [0-9]*/tablespace /
SHOW WARNINGS;
--error ER_GET_ERRMSG
SELECT * FROM t2 where id = 1;
---replace_regex /.*tablespace [0-9]*//
+--replace_regex /tablespace [0-9]*/tablespace /
SHOW WARNINGS;
--error ER_GET_ERRMSG
SELECT * FROM t2 where b = 1;
---replace_regex /.*tablespace [0-9]*//
+--replace_regex /tablespace [0-9]*/tablespace /
SHOW WARNINGS;
--error ER_GET_ERRMSG
INSERT INTO t2 VALUES ('tmp',3,3);
---replace_regex /.*tablespace [0-9]*//
+--replace_regex /tablespace [0-9]*/tablespace /
SHOW WARNINGS;
--error ER_GET_ERRMSG
DELETE FROM t2 where b = 3;
---replace_regex /.*tablespace [0-9]*//
+--replace_regex /tablespace [0-9]*/tablespace /
SHOW WARNINGS;
--error ER_GET_ERRMSG
DELETE FROM t2 where id = 3;
---replace_regex /.*tablespace [0-9]*//
+--replace_regex /tablespace [0-9]*/tablespace /
SHOW WARNINGS;
--error ER_GET_ERRMSG
UPDATE t2 set b = b +1;
---replace_regex /.*tablespace [0-9]*//
+--replace_regex /tablespace [0-9]*/tablespace /
SHOW WARNINGS;
OPTIMIZE TABLE t2;
---replace_regex /.*tablespace [0-9]*//
+--replace_regex /tablespace [0-9]*/tablespace /
SHOW WARNINGS;
--error ER_GET_ERRMSG
ALTER TABLE t2 ADD COLUMN c INT;
---replace_regex /.*tablespace [0-9]*//
+--replace_regex /tablespace [0-9]*/tablespace /
SHOW WARNINGS;
ANALYZE TABLE t2;
---replace_regex /.*tablespace [0-9]*//
+--replace_regex /tablespace [0-9]*/tablespace /
SHOW WARNINGS;
--error ER_GET_ERRMSG
TRUNCATE TABLE t2;
---replace_regex /.*tablespace [0-9]*//
+--replace_regex /tablespace [0-9]*/tablespace /
SHOW WARNINGS;
--replace_regex /.*tablespace [0-9]*//
--error ER_GET_ERRMSG
DROP TABLE t2;
---replace_regex /.*tablespace [0-9]*//
+--replace_regex /tablespace [0-9]*/tablespace /
SHOW WARNINGS;
--echo
@@ -136,5 +138,5 @@ SHOW WARNINGS;
--replace_regex /.*tablespace [0-9]*//
DROP TABLE t2;
---replace_regex /.*tablespace [0-9]*//
+--replace_regex /tablespace [0-9]*/tablespace /
SHOW WARNINGS;
diff --git a/mysql-test/suite/encryption/t/innodb-missing-key.opt b/mysql-test/suite/encryption/t/innodb-missing-key.opt
new file mode 100644
index 00000000000..02691695cbd
--- /dev/null
+++ b/mysql-test/suite/encryption/t/innodb-missing-key.opt
@@ -0,0 +1,5 @@
+--innodb-encrypt-tables
+--innodb-encryption-rotate-key-age=15
+--innodb-encryption-threads=4
+--innodb-tablespaces-encryption
+
diff --git a/mysql-test/suite/encryption/t/innodb-missing-key.test b/mysql-test/suite/encryption/t/innodb-missing-key.test
new file mode 100644
index 00000000000..8fcfb766117
--- /dev/null
+++ b/mysql-test/suite/encryption/t/innodb-missing-key.test
@@ -0,0 +1,68 @@
+--source include/have_innodb.inc
+-- source include/have_file_key_management_plugin.inc
+# embedded does not support restart
+-- source include/not_embedded.inc
+-- source include/not_valgrind.inc
+# Avoid CrashReporter popup on Mac
+-- source include/not_crashrep.inc
+
+#
+# MDEV-11004: Unable to start (Segfault or os error 2) when encryption key missing
+#
+call mtr.add_suppression("InnoDB: Block in space_id .* in file test/.* encrypted");
+call mtr.add_suppression("InnoDB: However key management plugin or used key_id .* is not found or used encryption algorithm or method does not match.");
+call mtr.add_suppression("InnoDB: Marking tablespace as missing. You may drop this table or install correct key management plugin and key file.");
+
+--echo
+--echo # Start server with keys2.txt
+-- let $restart_parameters=--file-key-management-filename=$MYSQL_TEST_DIR/std_data/keys2.txt
+-- source include/restart_mysqld.inc
+
+CREATE TABLE t1(a int not null primary key auto_increment, b varchar(128)) engine=innodb ENCRYPTED=YES ENCRYPTION_KEY_ID=19;
+CREATE TABLE t2(a int not null primary key auto_increment, b varchar(128)) engine=innodb ENCRYPTED=YES ENCRYPTION_KEY_ID=1;
+CREATE TABLE t3(a int not null primary key auto_increment, b varchar(128)) engine=innodb ENCRYPTED=NO;
+INSERT INTO t1(b) VALUES ('thisissecredmessage');
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t1(b) SELECT b FROM t1;
+INSERT INTO t2 SELECT * FROM t1;
+INSERT INTO t3 SELECT * FROM t1;
+
+--echo
+--echo # Restart server with keys3.txt
+-- let $restart_parameters=--file-key-management-filename=$MYSQL_TEST_DIR/std_data/keys3.txt
+-- source include/restart_mysqld.inc
+
+set global innodb_encryption_rotate_key_age = 1;
+use test;
+CREATE TABLE t4(a int not null primary key auto_increment, b varchar(128)) engine=innodb ENCRYPTED=YES ENCRYPTION_KEY_ID=1;
+SELECT SLEEP(5);
+SELECT COUNT(1) FROM t3;
+SELECT COUNT(1) FROM t2;
+--error 1296
+SELECT COUNT(1) FROM t2,t1 where t2.a = t1.a;
+--error 1296
+SELECT COUNT(1) FROM t1 where b = 'ab';
+--error 1296
+SELECT COUNT(1) FROM t1;
+
+--echo
+--echo # Start server with keys2.txt
+-- let $restart_parameters=--file-key-management-filename=$MYSQL_TEST_DIR/std_data/keys2.txt
+-- source include/restart_mysqld.inc
+
+SELECT COUNT(1) FROM t1;
+SELECT COUNT(1) FROM t2;
+SELECT COUNT(1) FROM t3;
+
+DROP TABLE t1, t2, t3;
+
+
diff --git a/mysql-test/suite/encryption/t/innodb-page_encryption_compression.test b/mysql-test/suite/encryption/t/innodb-page_encryption_compression.test
index 1d59c39d637..eb293e97693 100644
--- a/mysql-test/suite/encryption/t/innodb-page_encryption_compression.test
+++ b/mysql-test/suite/encryption/t/innodb-page_encryption_compression.test
@@ -1,6 +1,9 @@
-- source include/have_innodb.inc
-- source include/not_embedded.inc
-- source include/have_file_key_management_plugin.inc
+-- source include/big_test.inc
+# Test heavy not tested on valgrind
+-- source include/not_valgrind.inc
--disable_query_log
let $innodb_compression_algorithm_orig=`SELECT @@innodb_compression_algorithm`;
diff --git a/mysql-test/suite/encryption/t/innodb_encryption_discard_import.test b/mysql-test/suite/encryption/t/innodb_encryption_discard_import.test
index 0361fddecff..a713cdf9986 100644
--- a/mysql-test/suite/encryption/t/innodb_encryption_discard_import.test
+++ b/mysql-test/suite/encryption/t/innodb_encryption_discard_import.test
@@ -2,13 +2,13 @@
-- source include/have_example_key_management_plugin.inc
-- source include/not_valgrind.inc
-- source include/not_embedded.inc
--- source include/not_windows.inc
call mtr.add_suppression("InnoDB: Tablespace for table .* is set as discarded.");
call mtr.add_suppression("InnoDB: Cannot calculate statistics for table .* because the .ibd file is missing. Please refer to .* for how to resolve the issue.");
---let $MYSQLD_TMPDIR = `SELECT @@tmpdir`
---let $MYSQLD_DATADIR = `SELECT @@datadir`
+let $MYSQLD_TMPDIR = `SELECT @@tmpdir`;
+let $MYSQLD_DATADIR = `SELECT @@datadir`;
+
--let SEARCH_RANGE = 10000000
--let $id = `SELECT RAND()`
--let t1_IBD = $MYSQLD_DATADIR/test/t1.ibd
@@ -67,89 +67,25 @@ set autocommit=1;
-- let SEARCH_FILE=$t3_IBD
-- source include/search_pattern_in_file.inc
-FLUSH TABLE t1, t2, t3 FOR EXPORT;
-
---echo # List before copying files
+let MYSQLD_DATADIR =`SELECT @@datadir`;
--list_files $MYSQLD_DATADIR/test
---disable_result_log
---error 0,1,2
---remove_file $MYSQLD_TMPDIR/t1.cfg
---error 0,1,2
---remove_file $MYSQLD_TMPDIR/t1.ibd
---error 0,1,2
---remove_file $MYSQLD_TMPDIR/t2.cfg
---error 0,1,2
---remove_file $MYSQLD_TMPDIR/t2.ibd
---error 0,1,2
---remove_file $MYSQLD_TMPDIR/t3.cfg
---error 0,1,2
---remove_file $MYSQLD_TMPDIR/t3.ibd
---enable_result_log
---copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_TMPDIR/t1$id.cfg
---copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_TMPDIR/t1$id.ibd
---copy_file $MYSQLD_DATADIR/test/t2.cfg $MYSQLD_TMPDIR/t2$id.cfg
---copy_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_TMPDIR/t2$id.ibd
---copy_file $MYSQLD_DATADIR/test/t3.cfg $MYSQLD_TMPDIR/t3$id.cfg
---copy_file $MYSQLD_DATADIR/test/t3.ibd $MYSQLD_TMPDIR/t3$id.ibd
-UNLOCK TABLES;
-
---echo # Restarting server
--- source include/restart_mysqld.inc
---echo # Done restarting server
---echo # List before t1 DISCARD
+FLUSH TABLES t1, t2, t3 FOR EXPORT;
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1","t2","t3");
+EOF
--list_files $MYSQLD_DATADIR/test
-
-SET GLOBAL innodb_file_format = `Barracuda`;
-SET GLOBAL innodb_file_per_table = ON;
+UNLOCK TABLES;
ALTER TABLE t1 DISCARD TABLESPACE;
ALTER TABLE t2 DISCARD TABLESPACE;
ALTER TABLE t3 DISCARD TABLESPACE;
---echo # List after t1 DISCARD
---list_files $MYSQLD_DATADIR/test
---disable_result_log
---error 0,1,2
---remove_file $MYSQLD_DATADIR/test/t1.cfg
---error 0,1,2
---remove_file $MYSQLD_DATADIR/test/t1.ibd
---error 0,1,2
---remove_file $MYSQLD_DATADIR/test/t2.cfg
---error 0,1,2
---remove_file $MYSQLD_DATADIR/test/t2.ibd
---error 0,1,2
---remove_file $MYSQLD_DATADIR/test/t3.cfg
---error 0,1,2
---remove_file $MYSQLD_DATADIR/test/t3.ibd
---enable_result_log
---echo # Restarting server
--- source include/restart_mysqld.inc
---echo # Done restarting server
-
-SET GLOBAL innodb_file_format = `Barracuda`;
-SET GLOBAL innodb_file_per_table = ON;
-
---copy_file $MYSQLD_TMPDIR/t1$id.cfg $MYSQLD_DATADIR/test/t1.cfg
---copy_file $MYSQLD_TMPDIR/t1$id.ibd $MYSQLD_DATADIR/test/t1.ibd
---copy_file $MYSQLD_TMPDIR/t2$id.cfg $MYSQLD_DATADIR/test/t2.cfg
---copy_file $MYSQLD_TMPDIR/t2$id.ibd $MYSQLD_DATADIR/test/t2.ibd
---copy_file $MYSQLD_TMPDIR/t3$id.cfg $MYSQLD_DATADIR/test/t3.cfg
---copy_file $MYSQLD_TMPDIR/t3$id.ibd $MYSQLD_DATADIR/test/t3.ibd
-
---sleep 5
---echo # Tablespaces should be still encrypted
---let SEARCH_PATTERN=foobar
---echo # t1 yes on expecting NOT FOUND
--- let SEARCH_FILE=$t1_IBD
--- source include/search_pattern_in_file.inc
---let SEARCH_PATTERN=temp
---echo # t2 ... on expecting NOT FOUND
--- let SEARCH_FILE=$t2_IBD
--- source include/search_pattern_in_file.inc
---echo # t3 ... on expecting NOT FOUND
---let SEARCH_PATTERN=barfoo
--- let SEARCH_FILE=$t3_IBD
--- source include/search_pattern_in_file.inc
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1","t2","t3");
+ib_restore_tablespaces("test", "t1","t2","t3");
+EOF
ALTER TABLE t1 IMPORT TABLESPACE;
SELECT COUNT(1) FROM t1;
@@ -230,6 +166,6 @@ DROP TABLE t1, t2, t3;
# reset system
--disable_query_log
-EVAL SET GLOBAL innodb_file_per_table = $innodb_file_per_table_orig;
-EVAL SET GLOBAL innodb_file_format = $innodb_file_format_orig;
+eval SET GLOBAL innodb_file_per_table = $innodb_file_per_table_orig;
+eval SET GLOBAL innodb_file_format = $innodb_file_format_orig;
--enable_query_log
diff --git a/mysql-test/suite/encryption/t/innodb_lotoftables.opt b/mysql-test/suite/encryption/t/innodb_lotoftables.opt
new file mode 100644
index 00000000000..ffb5a2957f8
--- /dev/null
+++ b/mysql-test/suite/encryption/t/innodb_lotoftables.opt
@@ -0,0 +1,3 @@
+--innodb-tablespaces-encryption
+--innodb-encrypt-tables=off
+--innodb-encryption-threads=0
diff --git a/mysql-test/suite/encryption/t/innodb_lotoftables.test b/mysql-test/suite/encryption/t/innodb_lotoftables.test
new file mode 100644
index 00000000000..cad3cb54326
--- /dev/null
+++ b/mysql-test/suite/encryption/t/innodb_lotoftables.test
@@ -0,0 +1,274 @@
+-- source include/have_innodb.inc
+-- source include/have_example_key_management_plugin.inc
+-- source include/big_test.inc
+
+# embedded does not support restart
+-- source include/not_embedded.inc
+
+--disable_query_log
+let $innodb_file_format_orig = `SELECT @@innodb_file_format`;
+let $innodb_file_per_table_orig = `SELECT @@innodb_file_per_table`;
+let $innodb_encryption_threads_orig = `SELECT @@global.innodb_encryption_threads`;
+--enable_query_log
+
+SET GLOBAL innodb_file_format = `Barracuda`;
+SET GLOBAL innodb_file_per_table = ON;
+
+SHOW VARIABLES LIKE 'innodb_encrypt%';
+
+#
+# This will create 100 tables where that could be
+# encrypted an unencrypt
+#
+create database innodb_encrypted_1;
+use innodb_encrypted_1;
+show status like 'innodb_pages0_read%';
+set autocommit=0;
+let $tables = 100;
+
+--disable_query_log
+while ($tables)
+{
+ eval create table t_$tables (a int not null primary key, b varchar(200)) engine=innodb;
+ commit;
+ let $rows = 100;
+ while($rows)
+ {
+ eval insert into t_$tables values ($rows, substring(MD5(RAND()), -64));
+ dec $rows;
+ }
+ commit;
+ dec $tables;
+}
+--enable_query_log
+
+set autocommit=1;
+commit work;
+show status like 'innodb_pages0_read%';
+#
+# Verify
+#
+--echo # should be 100
+
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE NAME LIKE 'innodb_encrypted%';
+
+#
+# This will create 100 tables that are encrypted always
+#
+create database innodb_encrypted_2;
+use innodb_encrypted_2;
+show status like 'innodb_pages0_read%';
+set autocommit=0;
+
+--disable_query_log
+let $tables = 100;
+while ($tables)
+{
+ eval create table t_$tables (a int not null primary key, b varchar(200)) engine=innodb encrypted=yes;
+ commit;
+ let $rows = 100;
+ while($rows)
+ {
+ eval insert into t_$tables values ($rows, substring(MD5(RAND()), -64));
+ dec $rows;
+ }
+ commit;
+ dec $tables;
+}
+--enable_query_log
+
+commit work;
+set autocommit=1;
+show status like 'innodb_pages0_read%';
+#
+# Verify
+#
+--echo # should be 100
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 AND NAME LIKE 'innodb_encrypted%';
+--echo # should be 100
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 AND NAME LIKE 'innodb_encrypted%';
+
+#
+# This will create 100 tables that are not encrypted
+#
+create database innodb_encrypted_3;
+use innodb_encrypted_3;
+show status like 'innodb_pages0_read%';
+set autocommit=0;
+
+--disable_query_log
+let $tables = 100;
+while ($tables)
+{
+ eval create table t_$tables (a int not null primary key, b varchar(200)) engine=innodb encrypted=no;
+ commit;
+ let $rows = 100;
+ while($rows)
+ {
+ eval insert into t_$tables values ($rows, substring(MD5(RAND()), -64));
+ dec $rows;
+ }
+ commit;
+ dec $tables;
+}
+--enable_query_log
+
+commit work;
+set autocommit=1;
+show status like 'innodb_pages0_read%';
+#
+# Verify
+#
+--echo # should be 100
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 AND NAME LIKE 'innodb_encrypted%';
+--echo # should be 200
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 AND NAME LIKE 'innodb_encrypted%';
+
+use test;
+show status like 'innodb_pages0_read%';
+
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 AND NAME LIKE 'innodb_encrypted%';
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 AND NAME LIKE 'innodb_encrypted%';
+
+SET GLOBAL innodb_encrypt_tables = on;
+SET GLOBAL innodb_encryption_threads=4;
+
+--echo # Wait until all encrypted tables have been encrypted
+let $cnt=600;
+while ($cnt)
+{
+ let $success=`SELECT COUNT(*) = 100 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0`;
+ if ($success)
+ {
+ let $cnt=0;
+ }
+ if (!$success)
+ {
+ real_sleep 1;
+ dec $cnt;
+ }
+}
+if (!$success)
+{
+ SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0;
+ SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0;
+ SHOW STATUS LIKE 'innodb_encryption%';
+ -- die Timeout waiting for encryption threads
+}
+
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 AND NAME LIKE 'innodb_encrypted%';
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 AND NAME LIKE 'innodb_encrypted%';
+show status like 'innodb_pages0_read%';
+
+--echo # Success!
+--echo # Restart mysqld --innodb_encrypt_tables=0 --innodb_encryption_threads=0
+-- let $restart_parameters=--innodb_encrypt_tables=0 --innodb_encryption_threads=0
+-- source include/restart_mysqld.inc
+
+--echo # Restart Success!
+show status like 'innodb_pages0_read%';
+
+show status like 'innodb_pages0_read%';
+use test;
+show status like 'innodb_pages0_read%';
+use innodb_encrypted_1;
+show status like 'innodb_pages0_read%';
+use innodb_encrypted_2;
+show status like 'innodb_pages0_read%';
+use innodb_encrypted_3;
+show status like 'innodb_pages0_read%';
+
+use innodb_encrypted_1;
+show status like 'innodb_pages0_read%';
+--disable_result_log
+--disable_query_log
+let $tables = 100;
+while ($tables)
+{
+ eval select * from t_$tables;
+ dec $tables;
+}
+--enable_query_log
+--enable_result_log
+
+show status like 'innodb_pages0_read%';
+
+use innodb_encrypted_2;
+show status like 'innodb_pages0_read%';
+
+--disable_result_log
+--disable_query_log
+let $tables = 100;
+while ($tables)
+{
+ eval select * from t_$tables;
+ dec $tables;
+}
+--enable_query_log
+--enable_result_log
+
+show status like 'innodb_pages0_read%';
+
+use innodb_encrypted_3;
+show status like 'innodb_pages0_read%';
+--disable_result_log
+--disable_query_log
+let $tables = 100;
+while ($tables)
+{
+ eval select * from t_$tables;
+ dec $tables;
+}
+--enable_query_log
+--enable_result_log
+
+show status like 'innodb_pages0_read%';
+
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 AND NAME LIKE 'innodb_encrypted%';
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 AND NAME LIKE 'innodb_encrypted%';
+
+SET GLOBAL innodb_encrypt_tables = off;
+SET GLOBAL innodb_encryption_threads=4;
+
+--echo # Wait until all default encrypted tables have been decrypted
+let $cnt=600;
+while ($cnt)
+{
+ let $success=`SELECT COUNT(*) = 100 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0`;
+ if ($success)
+ {
+ let $cnt=0;
+ }
+ if (!$success)
+ {
+ real_sleep 1;
+ dec $cnt;
+ }
+}
+if (!$success)
+{
+ SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0;
+ SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0;
+ SHOW STATUS LIKE 'innodb_encryption%';
+ -- die Timeout waiting for encryption threads
+}
+
+--echo # should be 100
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 AND NAME LIKE 'innodb_encrypted%';
+--echo # should be 200
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 AND NAME LIKE 'innodb_encrypted%';
+show status like 'innodb_pages0_read%';
+
+#
+# Cleanup
+#
+use test;
+drop database innodb_encrypted_1;
+drop database innodb_encrypted_2;
+drop database innodb_encrypted_3;
+
+--disable_query_log
+EVAL SET GLOBAL innodb_file_per_table = $innodb_file_per_table_orig;
+EVAL SET GLOBAL innodb_file_format = $innodb_file_format_orig;
+EVAL SET GLOBAL innodb_encryption_threads = $innodb_encryption_threads_orig;
+--enable_query_log