Kafka -- Docker + Schema Registry
Avro
Avro的数据文件里包含了整个Schema
如果每条Kafka记录都嵌入了Schema,会让记录的大小成倍地增加
在读取记录时,仍然需要读到整个Schema,所以需要先找到Schema
可以采用通用的结构模式并使用Schema注册表的方案
开源的Schema注册表实现:Confluent Schema Registry
Confluent Schema Registry
把所有写入数据需要用到的Schema保存在注册表里,然后在_记录里引用Schema ID_
负责读数据的应用程序使用Schema ID从注册表拉取Schema来反序列化记录
序列化器和反序列化器分别负责处理Schema的注册和拉取
Confluent Schema Registry1234567891011121314151617181920# Start Zookeeper and expose port 2181 for use by the host machine$ docker run -d --name zookeeper -p 2181:2181 confluent/zookeeper# Start K ...
MySQL -- 自增ID耗尽
显示定义ID表定义的自增值ID达到上限后,在申请下一个ID时,得到的值保持不变
123456789101112131415161718-- (2^32-1) = 4,294,967,295-- 建议使用 BIGINT UNSIGNEDCREATE TABLE t (id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY) AUTO_INCREMENT=4294967295;INSERT INTO t VALUES (null);-- AUTO_INCREMENT没有改变mysql> SHOW CREATE TABLE t;+-------+------------------------------------------------------+| Table | Create Table |+-------+------------------------------------------------------+| t | CREATE TABLE `t` ( `id` int ...
MySQL -- 分区表
表初始化1234567891011121314CREATE TABLE `t` ( `ftime` DATETIME NOT NULL, `c` int(11) DEFAULT NULL, KEY (`ftime`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 PARTITION BY RANGE (YEAR(ftime)) (PARTITION p_2017 VALUES LESS THAN (2017) ENGINE = InnoDB, PARTITION p_2018 VALUES LESS THAN (2018) ENGINE = InnoDB, PARTITION p_2019 VALUES LESS THAN (2019) ENGINE = InnoDB, PARTITION p_others VALUES LESS THAN MAXVALUE ENGINE = InnoDB);INSERT INTO t VALUES ('2017-4-1',1),('2018-4-1',1);mys ...
MySQL -- 权限
创建用户1CREATE USER 'ua'@'%' IDENTIFIED BY 'pa';
用户名+地址才表示一个用户,ua@ip1和ua@ip2代表的是两个不同的用户
在磁盘上,往mysql.user表里插入一行,由于没有指定权限,所有表示权限的字段都是N
在内存里,往数组acl_users里插入一个acl_user对象,该对象的access字段的值为0
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950mysql> SELECT * FROM mysql.user WHERE user = 'ua'\G;*************************** 1. row *************************** Host: % User: ua Select_priv: N ...
MySQL -- 拷贝表
初始化123456789101112131415161718192021CREATE DATABASE db1;USE db1;CREATE TABLE t(id INT PRIMARY KEY, a INT, b INT, INDEX(a)) ENGINE=InnoDB;DELIMITER ;;CREATE PROCEDURE idata()BEGIN DECLARE i INT; SET i=1; WHILE (i <= 1000) DO INSERT INTO t VALUES (i,i,i); SET i=i+1; END WHILE;END;;DELIMITER ;CALL idata();CREATE DATABASE db2;CREATE TABLE db2.t LIKE db1.t;-- 目标:把db1.t里面a>900的数据导出来,插入到db2.t
mysqldump12345$ mysqldump -uroot --add-locks=0 --no-create-info --single-transaction -- ...
MySQL -- INSERT语句的锁
INSERT…SELECT表初始化1234567891011121314CREATE TABLE `t` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `c` INT(11) DEFAULT NULL, `d` INT(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `c` (`c`)) ENGINE=InnoDB;INSERT INTO t VALUES (null,1,1);INSERT INTO t VALUES (null,2,2);INSERT INTO t VALUES (null,3,3);INSERT INTO t VALUES (null,4,4);CREATE TABLE t2 LIKE t;
操作序列
时刻
session A
session B
T1
BEGIN;
T2
INSERT INTO t2(c,d) SELECT c,d FROM t;
T3
INSERT INTO t VALUES (-1,-1,-1);(Blocked)
1234567-- T3 ...
MySQL -- 自增主键
自增不连续表初始化1234567CREATE TABLE `t` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `c` INT(11) DEFAULT NULL, `d` INT(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `c` (`c`)) ENGINE=InnoDB;
自增值123456789101112131415INSERT INTO t VALUES (null,1,1);-- AUTO_INCREMENT=2,表示下一次插入数据时,如果需要自动生成自增值,会生成id=2mysql> SHOW CREATE TABLE t;+-------+---------------------------------------------+| Table | Create Table |+-------+---------------------------------------------+| t | CREATE TABL ...
MySQL -- Memory引擎
数据组织表初始化1234CREATE TABLE t1 (id INT PRIMARY KEY, c INT) ENGINE=Memory;CREATE TABLE t2 (id INT PRIMARY KEY, c INT) ENGINE=InnoDB;INSERT INTO t1 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(0,0);INSERT INTO t2 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(0,0);
执行语句123456789101112131415161718192021222324252627282930313233-- 0在最后mysql> SELECT * FROM t1;+----+------+| id | c |+----+------+| 1 | 1 || 2 | 2 || 3 | 3 || 4 | 4 || 5 | 5 || 6 | 6 || 7 ...
MySQL -- 内部临时表
UNIONUNION语义:取两个子查询结果的并集,重复的行只保留一行
表初始化1234567891011121314CREATE TABLE t1(id INT PRIMARY KEY, a INT, b INT, INDEX(a));DELIMITER ;;CREATE PROCEDURE idata()BEGIN DECLARE i INT; SET i=1; WHILE (i<= 1000) DO INSERT INTO t1 VALUES (i,i,i); SET i=i+1; END WHILE;END;;DELIMITER ;CALL idata();
执行语句12345678910(SELECT 1000 AS f) UNION (SELECT id FROM t1 ORDER BY id DESC LIMIT 2);mysql> EXPLAIN (SELECT 1000 AS f) UNION (SELECT id FROM t1 ORDER BY id DESC LIMIT 2);+----+--------------+ ...
MySQL -- 用户临时表
临时表 VS 内存表
内存表,指的是使用Memory引擎的表,建表语法:CREATE TABLE ... ENGINE=Memory
所有数据都保存在内存中,系统重启时被清空,但表结构还在
临时表,可以使用各种引擎
如果使用的是InnoDB或者MyISAM引擎,数据需要写到磁盘上
当然也可以使用Memory引擎
特征
session A
session B
CREATE TEMPORARY TABLE t(c int) ENGINE=MyISAM;(创建临时表)
SHOW CREATE TABLE t;(Table ‘test.t’ doesn’t exist)
CREATE TABLE t(id INT PRIMARY KEY) ENGINE=InnoDB;(创建普通表)
SHOW CREATE TABLE t;(显示临时表)
SHOW TABLES;(显示普通表)
INSERT INTO t VALUES (1);
SELECT * FROM t;(返回1)
SELECT * FROM t;(Empty set)
...