227 lines
5.8 KiB
Plaintext
227 lines
5.8 KiB
Plaintext
include/master-slave.inc
|
|
Warnings:
|
|
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
|
|
Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
|
|
[connection master]
|
|
CREATE PROCEDURE populate_t1(load_even INT)
|
|
BEGIN
|
|
DECLARE i int DEFAULT 1;
|
|
START TRANSACTION;
|
|
WHILE (i <= 100) DO
|
|
IF i%2 = 0 AND load_even = 1 THEN
|
|
INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
|
|
END IF;
|
|
IF i%2 != 0 AND load_even != 1 THEN
|
|
INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
|
|
END IF;
|
|
SET i = i + 1;
|
|
END WHILE;
|
|
COMMIT;
|
|
END|
|
|
CREATE TABLE t1(
|
|
class INT,
|
|
id INT,
|
|
title VARCHAR(100)
|
|
) charset latin1 ENGINE=InnoDB ;
|
|
SELECT COUNT(*) FROM t1;
|
|
COUNT(*)
|
|
50
|
|
/* Create index. */
|
|
CREATE INDEX idx_id ON t1(id);
|
|
CREATE INDEX idx_title ON t1(title);
|
|
/* Select by index. */
|
|
EXPLAIN SELECT * FROM t1 WHERE id = 10;
|
|
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
|
|
1 SIMPLE t1 NULL ref idx_id idx_id 5 const 1 100.00 NULL
|
|
Warnings:
|
|
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`id` = 10)
|
|
EXPLAIN SELECT * FROM t1 WHERE title = 'a10';
|
|
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
|
|
1 SIMPLE t1 NULL ref idx_title idx_title 103 const 1 100.00 NULL
|
|
Warnings:
|
|
Note 1003 /* select#1 */ select `test`.`t1`.`class` AS `class`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`title` AS `title` from `test`.`t1` where (`test`.`t1`.`title` = 'a10')
|
|
SELECT * FROM t1 WHERE id = 10;
|
|
class id title
|
|
10 10 a10
|
|
SELECT * FROM t1 WHERE title = 'a10';
|
|
class id title
|
|
10 10 a10
|
|
SELECT * FROM t1 WHERE id = 20;
|
|
class id title
|
|
20 20 a20
|
|
SELECT * FROM t1 WHERE title = 'a20';
|
|
class id title
|
|
20 20 a20
|
|
SELECT * FROM t1 WHERE id = 30;
|
|
class id title
|
|
30 30 a30
|
|
SELECT * FROM t1 WHERE title = 'a30';
|
|
class id title
|
|
30 30 a30
|
|
SELECT * FROM t1 WHERE id = 101;
|
|
class id title
|
|
SELECT * FROM t1 WHERE title = 'a101';
|
|
class id title
|
|
/*Insert/Update/Delete. */
|
|
DELETE FROM t1 WHERE id < 40 AND id > 30;
|
|
INSERT INTO t1 VALUES(38, 38, 'b38');
|
|
UPDATE t1 SET title = CONCAT('b', id) WHERE id < 30 AND id > 20;
|
|
SELECT * FROM t1 WHERE id = 28;
|
|
class id title
|
|
28 28 b28
|
|
SELECT * FROM t1 WHERE title = 'a28';
|
|
class id title
|
|
SELECT * FROM t1 WHERE title = 'b28';
|
|
class id title
|
|
28 28 b28
|
|
SELECT * FROM t1 WHERE id = 38;
|
|
class id title
|
|
38 38 b38
|
|
SELECT * FROM t1 WHERE title = 'a38';
|
|
class id title
|
|
SELECT * FROM t1 WHERE title = 'b38';
|
|
class id title
|
|
38 38 b38
|
|
SELECT * FROM t1 WHERE id = 101;
|
|
class id title
|
|
SELECT * FROM t1 WHERE title = 'a101';
|
|
class id title
|
|
SELECT COUNT(*) FROM t1;
|
|
COUNT(*)
|
|
97
|
|
SELECT * FROM t1 WHERE id = 10;
|
|
class id title
|
|
10 10 a10
|
|
SELECT * FROM t1 WHERE title = 'a10';
|
|
class id title
|
|
10 10 a10
|
|
SELECT * FROM t1 WHERE id = 20;
|
|
class id title
|
|
20 20 a20
|
|
SELECT * FROM t1 WHERE title = 'a20';
|
|
class id title
|
|
20 20 a20
|
|
SELECT * FROM t1 WHERE id = 30;
|
|
class id title
|
|
30 30 a30
|
|
SELECT * FROM t1 WHERE title = 'a30';
|
|
class id title
|
|
30 30 a30
|
|
SELECT * FROM t1 WHERE id = 101;
|
|
class id title
|
|
SELECT * FROM t1 WHERE title = 'a101';
|
|
class id title
|
|
CREATE TABLE t_part (
|
|
class INT ,
|
|
id INT ,
|
|
title VARCHAR(30)
|
|
) charset latin1 ENGINE=InnoDB
|
|
PARTITION BY RANGE(id)
|
|
SUBPARTITION BY KEY(id)
|
|
SUBPARTITIONS 4
|
|
(
|
|
PARTITION p0 VALUES LESS THAN (5000),
|
|
PARTITION p1 VALUES LESS THAN (MAXVALUE)
|
|
);
|
|
INSERT INTO t_part SELECT * FROM t1;
|
|
ALTER TABLE t_part ADD INDEX `idx` (class,id,title(10));
|
|
SELECT * FROM t_part WHERE id = 10;
|
|
class id title
|
|
10 10 a10
|
|
SELECT * FROM t_part WHERE title = 'a10';
|
|
class id title
|
|
10 10 a10
|
|
SELECT * FROM t_part WHERE id = 20;
|
|
class id title
|
|
20 20 a20
|
|
SELECT * FROM t_part WHERE title = 'a20';
|
|
class id title
|
|
20 20 a20
|
|
SELECT * FROM t_part WHERE id = 30;
|
|
class id title
|
|
30 30 a30
|
|
SELECT * FROM t_part WHERE title = 'a30';
|
|
class id title
|
|
30 30 a30
|
|
SELECT * FROM t_part WHERE id = 101;
|
|
class id title
|
|
SELECT * FROM t_part WHERE title = 'a101';
|
|
class id title
|
|
include/sync_slave_sql_with_master.inc
|
|
SHOW CREATE TABLE t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`class` int(11) DEFAULT NULL,
|
|
`id` int(11) DEFAULT NULL,
|
|
`title` varchar(100) DEFAULT NULL,
|
|
KEY `idx_id` (`id`),
|
|
KEY `idx_title` (`title`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1
|
|
SHOW CREATE TABLE t_part;
|
|
Table Create Table
|
|
t_part CREATE TABLE `t_part` (
|
|
`class` int(11) DEFAULT NULL,
|
|
`id` int(11) DEFAULT NULL,
|
|
`title` varchar(30) DEFAULT NULL,
|
|
KEY `idx` (`class`,`id`,`title`(10))
|
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1
|
|
/*!50100 PARTITION BY RANGE (`id`)
|
|
SUBPARTITION BY KEY (id)
|
|
SUBPARTITIONS 4
|
|
(PARTITION p0 VALUES LESS THAN (5000) ENGINE = InnoDB,
|
|
PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
|
|
SELECT COUNT(*) FROM t1;
|
|
COUNT(*)
|
|
97
|
|
SELECT COUNT(*) FROM t_part;
|
|
COUNT(*)
|
|
97
|
|
SELECT * FROM t1 WHERE id = 10;
|
|
class id title
|
|
10 10 a10
|
|
SELECT * FROM t1 WHERE title = 'a10';
|
|
class id title
|
|
10 10 a10
|
|
SELECT * FROM t1 WHERE id = 20;
|
|
class id title
|
|
20 20 a20
|
|
SELECT * FROM t1 WHERE title = 'a20';
|
|
class id title
|
|
20 20 a20
|
|
SELECT * FROM t1 WHERE id = 30;
|
|
class id title
|
|
30 30 a30
|
|
SELECT * FROM t1 WHERE title = 'a30';
|
|
class id title
|
|
30 30 a30
|
|
SELECT * FROM t1 WHERE id = 101;
|
|
class id title
|
|
SELECT * FROM t1 WHERE title = 'a101';
|
|
class id title
|
|
SELECT * FROM t_part WHERE id = 10;
|
|
class id title
|
|
10 10 a10
|
|
SELECT * FROM t_part WHERE title = 'a10';
|
|
class id title
|
|
10 10 a10
|
|
SELECT * FROM t_part WHERE id = 20;
|
|
class id title
|
|
20 20 a20
|
|
SELECT * FROM t_part WHERE title = 'a20';
|
|
class id title
|
|
20 20 a20
|
|
SELECT * FROM t_part WHERE id = 30;
|
|
class id title
|
|
30 30 a30
|
|
SELECT * FROM t_part WHERE title = 'a30';
|
|
class id title
|
|
30 30 a30
|
|
SELECT * FROM t_part WHERE id = 101;
|
|
class id title
|
|
SELECT * FROM t_part WHERE title = 'a101';
|
|
class id title
|
|
DROP PROCEDURE populate_t1;
|
|
DROP TABLE t1;
|
|
DROP TABLE t_part;
|
|
include/rpl_end.inc
|