| 1 |
SET @start_encr_threads = @@global.innodb_encryption_threads; |
| 2 |
SET @start_encrypt_tables = @@global.innodb_encrypt_tables; |
| 3 |
CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, a VARCHAR(255)) ENGINE=InnoDB encrypted=yes; |
| 4 |
CREATE TABLE t2 (id INT NOT NULL PRIMARY KEY, a VARCHAR(255)) ENGINE=InnoDB; |
| 5 |
CREATE TABLE t3 (id INT NOT NULL PRIMARY KEY, a VARCHAR(255)) ENGINE=InnoDB row_format=compressed encrypted=yes; |
| 6 |
create procedure innodb_insert_proc (repeat_count int) |
| 7 |
begin |
| 8 |
declare current_num int; |
| 9 |
set current_num = 0; |
| 10 |
while current_num < repeat_count do |
| 11 |
insert into t1 values (current_num,repeat('foobar',42)); |
| 12 |
insert into t2 values (current_num,repeat('temp', 42)); |
| 13 |
insert into t3 values (current_num,repeat('barfoo',42)); |
| 14 |
set current_num = current_num + 1; |
| 15 |
end while; |
| 16 |
end// |
| 17 |
commit; |
| 18 |
begin; |
| 19 |
set statement unique_checks=0, foreign_key_checks=0 for |
| 20 |
call innodb_insert_proc(100); |
| 21 |
commit; |
| 22 |
DROP PROCEDURE innodb_insert_proc; |
| 23 |
# Wait max 10 min for key encryption threads to encrypt all spaces |
| 24 |
FLUSH TABLES t1, t2, t3 FOR EXPORT; |
| 25 |
# tablespaces should be now encrypted |
| 26 |
# t1 yes on expecting NOT FOUND |
| 27 |
NOT FOUND /foobar/ in t1.ibd |
| 28 |
# t2 ... on expecting NOT FOUND |
| 29 |
NOT FOUND /temp/ in t2.ibd |
| 30 |
# t3 ... on expecting NOT FOUND |
| 31 |
NOT FOUND /barfoo/ in t3.ibd |
| 32 |
db.opt |
| 33 |
t1.cfg |
| 34 |
t1.frm |
| 35 |
t1.ibd |
| 36 |
t2.cfg |
| 37 |
t2.frm |
| 38 |
t2.ibd |
| 39 |
t3.cfg |
| 40 |
t3.frm |
| 41 |
t3.ibd |
| 42 |
backup: t1 |
| 43 |
backup: t2 |
| 44 |
backup: t3 |
| 45 |
db.opt |
| 46 |
t1.cfg |
| 47 |
t1.frm |
| 48 |
t1.ibd |
| 49 |
t2.cfg |
| 50 |
t2.frm |
| 51 |
t2.ibd |
| 52 |
t3.cfg |
| 53 |
t3.frm |
| 54 |
t3.ibd |
| 55 |
UNLOCK TABLES; |
| 56 |
ALTER TABLE t1 DISCARD TABLESPACE; |
| 57 |
ALTER TABLE t2 DISCARD TABLESPACE; |
| 58 |
ALTER TABLE t3 DISCARD TABLESPACE; |
| 59 |
restore: t1 .ibd and .cfg files |
| 60 |
restore: t2 .ibd and .cfg files |
| 61 |
restore: t3 .ibd and .cfg files |
| 62 |
ALTER TABLE t1 IMPORT TABLESPACE; |
| 63 |
SELECT COUNT(*) FROM t1; |
| 64 |
COUNT(*) |
| 65 |
100 |
| 66 |
ALTER TABLE t2 IMPORT TABLESPACE; |
| 67 |
SELECT COUNT(*) FROM t2; |
| 68 |
COUNT(*) |
| 69 |
100 |
| 70 |
ALTER TABLE t3 IMPORT TABLESPACE; |
| 71 |
SELECT COUNT(*) FROM t3; |
| 72 |
COUNT(*) |
| 73 |
100 |
| 74 |
FLUSH TABLES t1, t2, t3 FOR EXPORT; |
| 75 |
# tablespaces should remain encrypted after import |
| 76 |
# t1 yes on expecting NOT FOUND |
| 77 |
NOT FOUND /foobar/ in t1.ibd |
| 78 |
# t2 ... on expecting NOT FOUND |
| 79 |
NOT FOUND /temp/ in t2.ibd |
| 80 |
# t3 ... on expecting NOT FOUND |
| 81 |
NOT FOUND /barfoo/ in t3.ibd |
| 82 |
UNLOCK TABLES; |
| 83 |
ALTER TABLE t1 FORCE; |
| 84 |
SHOW CREATE TABLE t1; |
| 85 |
Table Create Table |
| 86 |
t1 CREATE TABLE `t1` ( |
| 87 |
`id` int(11) NOT NULL, |
| 88 |
`a` varchar(255) DEFAULT NULL, |
| 89 |
PRIMARY KEY (`id`) |
| 90 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci `encrypted`=yes |
| 91 |
ALTER TABLE t2 FORCE; |
| 92 |
SHOW CREATE TABLE t2; |
| 93 |
Table Create Table |
| 94 |
t2 CREATE TABLE `t2` ( |
| 95 |
`id` int(11) NOT NULL, |
| 96 |
`a` varchar(255) DEFAULT NULL, |
| 97 |
PRIMARY KEY (`id`) |
| 98 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 99 |
ALTER TABLE t3 FORCE; |
| 100 |
SHOW CREATE TABLE t3; |
| 101 |
Table Create Table |
| 102 |
t3 CREATE TABLE `t3` ( |
| 103 |
`id` int(11) NOT NULL, |
| 104 |
`a` varchar(255) DEFAULT NULL, |
| 105 |
PRIMARY KEY (`id`) |
| 106 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ROW_FORMAT=COMPRESSED `encrypted`=yes |
| 107 |
# Verify that tables are still usable |
| 108 |
CHECK TABLE t1, t2, t3 EXTENDED; |
| 109 |
Table Op Msg_type Msg_text |
| 110 |
test.t1 check status OK |
| 111 |
test.t2 check status OK |
| 112 |
test.t3 check status OK |
| 113 |
FLUSH TABLES t1, t2, t3 FOR EXPORT; |
| 114 |
# t1 yes on expecting NOT FOUND |
| 115 |
NOT FOUND /foobar/ in t1.ibd |
| 116 |
# t2 ... on expecting NOT FOUND |
| 117 |
NOT FOUND /temp/ in t2.ibd |
| 118 |
# t3 ... on expecting NOT FOUND |
| 119 |
UNLOCK TABLES; |
| 120 |
DROP TABLE t1, t2, t3; |
| 121 |
# |
| 122 |
# MDEV-34670 IMPORT TABLESPACE unnecessary traverses |
| 123 |
# tablespace list |
| 124 |
# |
| 125 |
SET GLOBAL innodb_encrypt_tables= OFF; |
| 126 |
SET GLOBAL innodb_encryption_threads= 0; |
| 127 |
CREATE TABLE t1(f1 int,f2 text)ENGINE=InnoDB; |
| 128 |
INSERT INTO t1 VALUES(1, "InnoDB"); |
| 129 |
CREATE TABLE t2 LIKE t1; |
| 130 |
ALTER TABLE t2 DISCARD TABLESPACE; |
| 131 |
FLUSH TABLES t1 FOR EXPORT; |
| 132 |
UNLOCK TABLES; |
| 133 |
ALTER TABLE t2 IMPORT TABLESPACE; |
| 134 |
SET GLOBAL innodb_encryption_threads=2; |
| 135 |
SET GLOBAL innodb_encrypt_tables = ON; |
| 136 |
# Wait max 10 min for key encryption threads to encrypt all spaces |
| 137 |
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 |
| 138 |
AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry'; |
| 139 |
NAME |
| 140 |
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 |
| 141 |
AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry'; |
| 142 |
NAME |
| 143 |
innodb_system |
| 144 |
test/t1 |
| 145 |
test/t2 |
| 146 |
SET GLOBAL innodb_encrypt_tables = OFF; |
| 147 |
# Wait max 10 min for key encryption threads to decrypt all spaces |
| 148 |
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 |
| 149 |
AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry'; |
| 150 |
NAME |
| 151 |
innodb_system |
| 152 |
test/t1 |
| 153 |
test/t2 |
| 154 |
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 |
| 155 |
AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry'; |
| 156 |
NAME |
| 157 |
DROP TABLE t1, t2; |
| 158 |
SET GLOBAL innodb_encryption_threads=@start_encr_threads; |
| 159 |
SET GLOBAL innodb_encrypt_tables=@start_encrypt_tables; |