SHOW VARIABLES LIKE 'storage_engine';
Variable_name	Value
storage_engine	#

starting the test for backup

DROP DATABASE IF EXISTS `¥`;
*** The following defects were reported while executing WL#4227 ***
Bug #34391 Character sets: crash if char(), utf32, innodb
Bug #33566 Backup: crash with partitions and Falcon
Bug #37551 Junk detected in data contents sometimes when utf8mb3
character set is used.
Bug #37554 Use of character set and collate as 'filename' shows
unusual behaviour.
Bug #35499 View when created with swe7 character set fails.
Bug #38784 Mysql server crash if table is altered by partition changes.
SET NAMES utf8;
CREATE DATABASE `¥`;
USE `¥`;
*****Creating table with range partition*********
CREATE TABLE `ê`(
ID INT NOT NULL,
NAME CHAR(20),
AGE TINYINT,
DOB DATE,
SAL FLOAT,
PRIMARY KEY(DOB)) PARTITION BY RANGE(Year(DOB))(
PARTITION P0 values less than (1970),
PARTITION P1 values less than (1980),
PARTITION P2 values less than (1990),
PARTITION P3 values less than (2000),
PARTITION P4 values less than maxvalue);
loading data
INSERT INTO `ê` VALUES
(10,'aa','20','1988-12-19',2345.89),(11,'bb',31,'1977-10-19',6009.89),
(12,'cc',78,'1945-09-12',3897),(13,'dd',12,'1994-09-18',7892.78),
(14,'ee',45,'1960-12-23',7845.90),(15,'ff',25,'1984-02-07',3500.89);
select data
SELECT * FROM `ê` ORDER BY DOB;
ID	NAME	AGE	DOB	SAL
12	cc	78	1945-09-12	3897
14	ee	45	1960-12-23	7845.9
11	bb	31	1977-10-19	6009.89
15	ff	25	1984-02-07	3500.89
10	aa	20	1988-12-19	2345.89
13	dd	12	1994-09-18	7892.78
SELECT COUNT(*) FROM `ê`;
COUNT(*)
6

******Creating table partition with List**************
CREATE TABLE `cÿd`(`numeric` INT, `char` CHAR(20))
PARTITION BY LIST (`numeric`)
(
PARTITION p0 VALUES IN (1,3,5),
PARTITION p1 VALUES IN (2,4,6)
);
insert data
INSERT INTO `cÿd` VALUES(1,'a'),(6,'c'),(5,'j'),(2,'l');
selecting data
SELECT * FROM `cÿd` ORDER BY `numeric`;
numeric	char
1	a
2	l
5	j
6	c
SELECT COUNT(*) FROM `cÿd`;
COUNT(*)
4

*******Creating table partition with Hash***********
CREATE TABLE `µ`(
col1 INT,
col2 CHAR(20),
col3 DATE)
PARTITION BY HASH (YEAR(col3))
PARTITIONS 4;
Insert data
INSERT INTO `µ` VALUES
(1,'a','1942-10-09'),(2,'b','1950-08-07'),
(3,'c','1952-10-10'),(4,'d','1954-10-04');
selecting data
SELECT * FROM `µ` ORDER BY col3;
col1	col2	col3
1	a	1942-10-09
2	b	1950-08-07
3	c	1952-10-10
4	d	1954-10-04
SELECT COUNT(*) FROM `µ`;
COUNT(*)
4
********Creating table partition with keys*******
CREATE TABLE `вап` (id INT)
PARTITION BY KEY(id)
PARTITIONS 2;
insert data
INSERT INTO `вап` VALUES(1),(2),(3),(4);
selecting the data
SELECT * FROM `вап`;
id
1
3
2
4
SELECT COUNT(*) FROM `вап`;
COUNT(*)
4
***Creating views from partitoned Tables****
CREATE VIEW `ïö` AS SELECT * FROM `ê`;
Obtaining information about Partitions
SHOW FULL TABLES;
Tables_in_¥	Table_type
µ	BASE TABLE
ê	BASE TABLE
ïö	VIEW
вап	BASE TABLE
cÿd	BASE TABLE
EXPLAIN PARTITIONS SELECT * FROM `ê`;;
id	#
select_type	SIMPLE
table	ê
partitions	P0,P1,P2,P3,P4
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
EXPLAIN PARTITIONS SELECT * FROM `cÿd`;;
id	#
select_type	SIMPLE
table	cÿd
partitions	p0,p1
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
EXPLAIN PARTITIONS SELECT * FROM `µ`;;
id	#
select_type	SIMPLE
table	µ
partitions	p0,p1,p2,p3
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
EXPLAIN PARTITIONS SELECT * FROM `вап`;;
id	#
select_type	SIMPLE
table	вап
partitions	p0,p1
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
backup data
BACKUP DATABASE `¥` TO 'partitions.bak';
backup_id
#
dropping  database.
DROP DATABASE `¥`;
Restore
RESTORE FROM 'partitions.bak';
backup_id
#

** RESULTS AFTER RESTORE **

Obtaining Information about Partitions
SHOW FULL TABLES;;
Tables_in_¥	µ
Table_type	BASE TABLE
Tables_in_¥	ê
Table_type	BASE TABLE
Tables_in_¥	ïö
Table_type	VIEW
Tables_in_¥	вап
Table_type	BASE TABLE
Tables_in_¥	cÿd
Table_type	BASE TABLE
EXPLAIN PARTITIONS SELECT * FROM `ê`;;
id	#
select_type	SIMPLE
table	ê
partitions	P0,P1,P2,P3,P4
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
EXPLAIN PARTITIONS SELECT * FROM `cÿd`;;
id	#
select_type	SIMPLE
table	cÿd
partitions	p0,p1
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
EXPLAIN PARTITIONS SELECT * FROM `µ`;;
id	#
select_type	SIMPLE
table	µ
partitions	p0,p1,p2,p3
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
EXPLAIN PARTITIONS SELECT * FROM `вап`;;
id	#
select_type	SIMPLE
table	вап
partitions	p0,p1
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
ALTER TABLE `ê` PARTITION BY KEY(DOB) PARTITIONS 2;
INSERT INTO `ïö` VALUES(17,'kk','90','2020-12-19',2000);
SELECT COUNT(*) FROM `ïö`;
COUNT(*)
7
SELECT COUNT(*) FROM `ê`;
COUNT(*)
7

**Creating table with subpartitions**
CREATE TABLE `фы` (`int` INT)
PARTITION BY range (`int`)
SUBPARTITION BY key (`int`)
(PARTITION p0 VALUES LESS THAN (2));
INSERT INTO `фы` VALUES(0),(1);
SHOW FULL TABLES;
Tables_in_¥	Table_type
µ	BASE TABLE
ê	BASE TABLE
ïö	VIEW
фы	BASE TABLE
вап	BASE TABLE
cÿd	BASE TABLE
EXPLAIN PARTITIONS SELECT * FROM `ê`;;
id	#
select_type	SIMPLE
table	ê
partitions	p0,p1
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
EXPLAIN PARTITIONS SELECT * FROM `cÿd`;;
id	#
select_type	SIMPLE
table	cÿd
partitions	p0,p1
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
EXPLAIN PARTITIONS SELECT * FROM `µ`;;
id	#
select_type	SIMPLE
table	µ
partitions	p0,p1,p2,p3
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
EXPLAIN PARTITIONS SELECT * FROM `вап`;;
id	#
select_type	SIMPLE
table	вап
partitions	p0,p1
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
BACKUP DATABASE `¥` TO 'partitions.bak';
backup_id
#
DROP DATABASE `¥`;
RESTORE FROM 'partitions.bak';
backup_id
#
showing objects and create statements
EXPLAIN PARTITIONS SELECT * FROM `ê`;;
id	#
select_type	SIMPLE
table	ê
partitions	p0,p1
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
EXPLAIN PARTITIONS SELECT * FROM `cÿd`;;
id	#
select_type	SIMPLE
table	cÿd
partitions	p0,p1
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
EXPLAIN PARTITIONS SELECT * FROM `µ`;;
id	#
select_type	SIMPLE
table	µ
partitions	p0,p1,p2,p3
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
EXPLAIN PARTITIONS SELECT * FROM `вап`;;
id	#
select_type	SIMPLE
table	вап
partitions	p0,p1
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
SELECT * FROM `cÿd` ORDER BY `numeric`;
numeric	char
1	a
2	l
5	j
6	c
SELECT * FROM `вап`;
id
1
3
2
4
SELECT * FROM `µ` ORDER BY col3;
col1	col2	col3
1	a	1942-10-09
2	b	1950-08-07
3	c	1952-10-10
4	d	1954-10-04
SELECT * FROM `ê` ORDER BY DOB;
ID	NAME	AGE	DOB	SAL
12	cc	78	1945-09-12	3897
14	ee	45	1960-12-23	7845.9
11	bb	31	1977-10-19	6009.89
15	ff	25	1984-02-07	3500.89
10	aa	20	1988-12-19	2345.89
13	dd	12	1994-09-18	7892.78
17	kk	90	2020-12-19	2000
SELECT * FROM `фы`;
int
0
1
**creating view from view***
CREATE VIEW v2 AS SELECT * FROM `ïö`;
INSERT INTO v2 VALUES(18,'pp',51,'1990-10-19',6009.89);
SELECT COUNT(*) FROM `ïö`;
COUNT(*)
8
SELECT COUNT(*) FROM `ê`;
COUNT(*)
8
Make some changes and then perform Restore.
EXPLAIN PARTITIONS SELECT * FROM `фы`;;
id	#
select_type	SIMPLE
table	фы
partitions	p0_p0sp0
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
SHOW FULL TABLES;
Tables_in_¥	Table_type
µ	BASE TABLE
ê	BASE TABLE
ïö	VIEW
фы	BASE TABLE
вап	BASE TABLE
cÿd	BASE TABLE
v2	VIEW
ALTER TABLE `фы` REMOVE PARTITIONING;
BACKUP DATABASE `¥` to 'partitions.bak';
backup_id
#
DROP DATABASE `¥`;
RESTORE FROM 'partitions.bak';
backup_id
#
SHOW FULL TABLES;
Tables_in_¥	Table_type
µ	BASE TABLE
ê	BASE TABLE
ïö	VIEW
фы	BASE TABLE
вап	BASE TABLE
cÿd	BASE TABLE
v2	VIEW
SELECT * FROM `фы`;
int
0
1
EXPLAIN PARTITIONS SELECT * FROM `фы`;;
id	#
select_type	SIMPLE
table	фы
partitions	NULL
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	#
Extra	
SELECT * FROM `ïö` ORDER BY DOB;
ID	NAME	AGE	DOB	SAL
12	cc	78	1945-09-12	3897
14	ee	45	1960-12-23	7845.9
11	bb	31	1977-10-19	6009.89
15	ff	25	1984-02-07	3500.89
10	aa	20	1988-12-19	2345.89
18	pp	51	1990-10-19	6009.89
13	dd	12	1994-09-18	7892.78
17	kk	90	2020-12-19	2000
SELECT COUNT(*) FROM `ê`;
COUNT(*)
8
Perform restore again by changing the character set
SET NAMES latin7;
**Restore**
RESTORE FROM 'partitions.bak' OVERWRITE;
backup_id
#
SHOW DATABASES;
Database
information_schema
?
mtr
mysql
test
SHOW FULL TABLES;
Tables_in_?	Table_type
�	BASE TABLE
?	BASE TABLE
?�	VIEW
??	BASE TABLE
???	BASE TABLE
c?d	BASE TABLE
v2	VIEW
** checking client character set **
SELECT @@character_set_client;
@@character_set_client
latin7
SELECT @@character_set_results;
@@character_set_results
latin7
SELECT @@character_set_connection;
@@character_set_connection
latin7
SET NAMES latin5;
RESTORE FROM 'partitions.bak' OVERWRITE;
backup_id
#
SHOW DATABASES;
Database
information_schema
�
mtr
mysql
test
SET NAMES utf8;

***  DROP `¥` DATABASE ****

DROP DATABASE `¥`;
