|
| 1 | +include/master-slave.inc |
| 2 | +Warnings: |
| 3 | +Note #### Sending passwords in plain text without SSL/TLS is extremely insecure. |
| 4 | +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. |
| 5 | +[connection master] |
| 6 | +create database s_db; |
| 7 | +grant all on s_db.* to normal_1@'%' identified by 'pass'; |
| 8 | +grant all on test.* to normal_2@'%' identified by 'pass'; |
| 9 | +grant all on s_db.* to normal_3@'%' identified by 'pass'; |
| 10 | +grant all on test.* to normal_4@'%' identified by 'pass'; |
| 11 | +create table s_db.t1(id int, col1 int)engine=innodb; |
| 12 | +set global read_only=on; |
| 13 | +########################################### |
| 14 | +master and slave sync sequence. |
| 15 | +########################################### |
| 16 | +use s_db; |
| 17 | +create sequence s1; |
| 18 | +show create table s1; |
| 19 | +Table Create Table |
| 20 | +s1 CREATE SEQUENCE `s1` ( |
| 21 | + `currval` bigint(21) NOT NULL COMMENT 'current value', |
| 22 | + `nextval` bigint(21) NOT NULL COMMENT 'next value', |
| 23 | + `minvalue` bigint(21) NOT NULL COMMENT 'min value', |
| 24 | + `maxvalue` bigint(21) NOT NULL COMMENT 'max value', |
| 25 | + `start` bigint(21) NOT NULL COMMENT 'start value', |
| 26 | + `increment` bigint(21) NOT NULL COMMENT 'increment value', |
| 27 | + `cache` bigint(21) NOT NULL COMMENT 'cache size', |
| 28 | + `cycle` bigint(21) NOT NULL COMMENT 'cycle state', |
| 29 | + `round` bigint(21) NOT NULL COMMENT 'already how many round' |
| 30 | +) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
| 31 | +use s_db; |
| 32 | +show create table s1; |
| 33 | +Table Create Table |
| 34 | +s1 CREATE SEQUENCE `s1` ( |
| 35 | + `currval` bigint(21) NOT NULL COMMENT 'current value', |
| 36 | + `nextval` bigint(21) NOT NULL COMMENT 'next value', |
| 37 | + `minvalue` bigint(21) NOT NULL COMMENT 'min value', |
| 38 | + `maxvalue` bigint(21) NOT NULL COMMENT 'max value', |
| 39 | + `start` bigint(21) NOT NULL COMMENT 'start value', |
| 40 | + `increment` bigint(21) NOT NULL COMMENT 'increment value', |
| 41 | + `cache` bigint(21) NOT NULL COMMENT 'cache size', |
| 42 | + `cycle` bigint(21) NOT NULL COMMENT 'cycle state', |
| 43 | + `round` bigint(21) NOT NULL COMMENT 'already how many round' |
| 44 | +) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
| 45 | +use s_db; |
| 46 | +drop sequence s1; |
| 47 | +########################################### |
| 48 | +test keyword |
| 49 | +########################################### |
| 50 | +use s_db; |
| 51 | +create table t_2(currval int, nextval int); |
| 52 | +drop table t_2; |
| 53 | +########################################### |
| 54 | +dml with func |
| 55 | +########################################### |
| 56 | +use s_db; |
| 57 | +create sequence s1 start with 1 minvalue 1 maxvalue 7 cache 2 cycle increment by 2; |
| 58 | +select currval for s1; |
| 59 | +ERROR HY000: Sequence 's_db.s1' is not yet defined in this session |
| 60 | +select currval(s1); |
| 61 | +ERROR HY000: Sequence 's_db.s1' is not yet defined in this session |
| 62 | +select nextval(s1); |
| 63 | +nextval(s1) |
| 64 | +1 |
| 65 | +insert into t1 values(nextval(s1), currval(s1)); |
| 66 | +select * from t1; |
| 67 | +id col1 |
| 68 | +3 3 |
| 69 | +update t1 set col1=nextval(s1); |
| 70 | +select * from t1; |
| 71 | +id col1 |
| 72 | +3 5 |
| 73 | +commit; |
| 74 | +drop sequence s1; |
| 75 | +########################################### |
| 76 | +func, trigger, procedure with sequence func |
| 77 | +########################################### |
| 78 | +use s_db; |
| 79 | +create sequence s1 start with 1 minvalue 1 cache 2 cycle increment by 2; |
| 80 | +CREATE FUNCTION `test_func_1` () RETURNS int |
| 81 | +BEGIN |
| 82 | +RETURN (select nextval(s1)); |
| 83 | +END$$ |
| 84 | +CREATE FUNCTION `test_func_2` () RETURNS int |
| 85 | +BEGIN |
| 86 | +RETURN (select currval(s1)); |
| 87 | +END$$ |
| 88 | +select test_func_2(); |
| 89 | +ERROR HY000: Sequence 's_db.s1' is not yet defined in this session |
| 90 | +select test_func_1(); |
| 91 | +test_func_1() |
| 92 | +1 |
| 93 | +select test_func_2(); |
| 94 | +test_func_2() |
| 95 | +1 |
| 96 | +select test_func_1(); |
| 97 | +test_func_1() |
| 98 | +3 |
| 99 | +select test_func_2(); |
| 100 | +test_func_2() |
| 101 | +3 |
| 102 | +drop function test_func_1; |
| 103 | +drop function test_func_2; |
| 104 | +set autocommit=0; |
| 105 | +select * from t1; |
| 106 | +id col1 |
| 107 | +3 5 |
| 108 | +CREATE PROCEDURE test_proc_1() |
| 109 | +BEGIN |
| 110 | +insert into t1 values(nextval(s1), currval(s1)); |
| 111 | +insert into t1 values(nextval(s1), currval(s1)); |
| 112 | +END$$ |
| 113 | +call test_proc_1(); |
| 114 | +select * from t1; |
| 115 | +id col1 |
| 116 | +3 5 |
| 117 | +5 5 |
| 118 | +7 7 |
| 119 | +rollback; |
| 120 | +select * from t1; |
| 121 | +id col1 |
| 122 | +3 5 |
| 123 | +select nextval(s1); |
| 124 | +nextval(s1) |
| 125 | +9 |
| 126 | +commit; |
| 127 | +drop procedure test_proc_1; |
| 128 | +create table t2(id int)engine=innodb; |
| 129 | +CREATE TRIGGER test_tri_1 |
| 130 | +AFTER INSERT ON t1 |
| 131 | +FOR EACH ROW |
| 132 | +BEGIN INSERT INTO t2 VALUES(nextval(s1)); |
| 133 | +END$$ |
| 134 | +insert into t1 values(nextval(s1), nextval(s1)); |
| 135 | +insert into t1 values(nextval(s1), nextval(s1)); |
| 136 | +select * from t1; |
| 137 | +id col1 |
| 138 | +3 5 |
| 139 | +11 13 |
| 140 | +17 19 |
| 141 | +select * from t2; |
| 142 | +id |
| 143 | +15 |
| 144 | +21 |
| 145 | +commit; |
| 146 | +drop trigger test_tri_1; |
| 147 | +drop table t2; |
| 148 | +use s_db; |
| 149 | +drop database s_db; |
| 150 | +drop user normal_1@'%'; |
| 151 | +drop user normal_2@'%'; |
| 152 | +drop user normal_3@'%'; |
| 153 | +drop user normal_4@'%'; |
| 154 | +include/rpl_end.inc |
0 commit comments