作者:杨涛涛
资深数据库专家,专研 MySQL 十余年。擅长 MySQL、PostgreSQL、MongoDB 等开源数据库相关的备份恢复、SQL 调优、监控运维、高可用架构设计等。目前任职于爱可生,为各大运营商及银行金融企业提供 MySQL 相关技术支持、MySQL 相关课程培训等工作。
本文来源:原创投稿
*爱可生开源社区出品,原创内容未经授权不得随意使用,转载请联系小编并注明来源。
相关推荐文章:
新特性解读 | 8.0 新增 DML 语句(TABLE & VALUES)
一款优秀的缓存系统
特别是对以下场景非常适合用 memcache 来做缓存:
3. 更新比较频繁的小表(用户状态表、物品库存等)
3. 不需要单独安装 memcache,安装 MySQL 即可使用。
MySQL 5.7 —— 深入优化
MySQL 8.0 —— 新增特性
可以直接类似于 select * from t1 where id between 10 and 20 这样的范围检索语句。
1. 导入元数据
(localhost:ytt)<mysql>\. /usr/share/mysql-8.0/innodb_memcached_config.sqlQuery OK, 1 row affected (0.05 sec)
2. 安装插件
(localhost:test)<mysql>INSTALL PLUGIN daemon_memcached soname "libmemcached.so";Query OK, 0 rows affected (0.08 sec)
(localhost:information_schema)<mysql>select * from information_schema.plugins where plugin_name = 'daemon_memcached'\G*************************** 1. row ***************************PLUGIN_NAME: daemon_memcachedPLUGIN_VERSION: 1.0PLUGIN_STATUS: ACTIVEPLUGIN_TYPE: DAEMONPLUGIN_TYPE_VERSION: 80020.0PLUGIN_LIBRARY: libmemcached.soPLUGIN_LIBRARY_VERSION: 1.10PLUGIN_AUTHOR: Oracle CorporationPLUGIN_DESCRIPTION: Memcached DaemonPLUGIN_LICENSE: GPLLOAD_OPTION: ON1 row in set (0.00 sec)
3. 准备数据
注意:表主键对应 memcached api 的 Key,除主键外的其他字段只能整型或者字符类型,剩下的 flags,cas,expiry 是规定死的字段。
(localhost:ytt)<mysql>create table t1 (id serial primary key,r1 int,r2 int,r3 varchar(20),flags int,cas bigint unsigned,expiry int);Query OK, 0 rows affected (0.05 sec)
(localhost:ytt)<mysql>select * from t1;+----+------+------+---------------------+-------+------+--------+| id | r1 | r2 | r3 | flags | cas | expiry |+----+------+------+---------------------+-------+------+--------+| 1 | 2 | 9 | 2040-01-20 07:29:47 | 0 | 0 | 0 || 2 | 7 | 1 | 2037-12-25 22:43:52 | 0 | 0 | 0 || 3 | 2 | 18 | 2049-04-15 07:05:35 | 0 | 0 | 0 || 4 | 8 | 5 | 2048-08-17 23:38:39 | 0 | 0 | 0 || 6 | 9 | 11 | 2043-02-13 11:05:28 | 0 | 0 | 0 || 7 | 2 | 5 | 2049-03-25 20:27:01 | 0 | 0 | 0 || 8 | 7 | 13 | 2032-12-11 05:21:01 | 0 | 0 | 0 || 9 | 1 | 7 | 2028-03-29 03:06:18 | 0 | 0 | 0 || 13 | 6 | 12 | 2021-11-22 11:24:06 | 0 | 0 | 0 || 14 | 4 | 20 | 2035-12-14 13:23:55 | 0 | 0 | 0 || 15 | 10 | 15 | 2030-03-24 17:09:34 | 0 | 0 | 0 || 16 | 8 | 15 | 2022-10-21 09:31:45 | 0 | 0 | 0 || 17 | 3 | 3 | 2034-07-20 09:52:18 | 0 | 0 | 0 || 18 | 9 | 19 | 2020-06-25 05:08:37 | 0 | 0 | 0 || 19 | 1 | 7 | 2041-08-29 11:35:06 | 0 | 0 | 0 || 20 | 6 | 14 | 2031-04-25 01:05:20 | 0 | 0 | 0 |+----+------+------+---------------------+-------+------+--------+16 rows in set (0.00 sec)
4. 使用插件
(localhost:ytt)<mysql>insert into innodb_memcache.containers(name,db_schema,db_table,key_columns,value_columns,flags,cas_column,expire_time_column,unique_idx_name_on_key) -> values ('default','ytt','t1','id','r1|r2|r3','flags','cas','expiry','primary');Query OK, 1 row affected (0.01 sec)
5. 读取数据
(localhost:ytt)<mysql>UNINSTALL PLUGIN daemon_memcached;Query OK, 0 rows affected (2.02 sec)(localhost:ytt)<mysql>INSTALL PLUGIN daemon_memcached soname "libmemcached.so";Query OK, 0 rows affected (0.01 sec)
root@ytt-unbuntu:/data/mysql57/data# telnet localhost 11211Trying 127.0.0.1...Connected to localhost.Escape character is '^]'.get 1VALUE 1 0 232|9|2040-01-20 07:29:47ENDget 2VALUE 2 0 237|1|2037-12-25 22:43:52ENDget 3VALUE 3 0 242|18|2049-04-15 07:05:35ENDget 4VALUE 4 0 238|5|2048-08-17 23:38:39ENDget 5ENDget 6VALUE 6 0 249|11|2043-02-13 11:05:28END
get 1 2 3 4 5 6We temporarily don't support multiple get option.
root@ytt-unbuntu:/home/ytt# telnet localhost 11222Trying 127.0.0.1...Connected to localhost.Escape character is '^]'.get 1 2 3 4 5 6VALUE 1 0 232|9|2040-01-20 07:29:47VALUE 2 0 237|1|2037-12-25 22:43:52VALUE 3 0 242|18|2049-04-15 07:05:35VALUE 4 0 238|5|2048-08-17 23:38:39VALUE 6 0 249|11|2043-02-13 11:05:28END
get @<=6
get @>10
get @>10@<20
get @>2@<3@<10END
关于爱可生
爱可生成立于2003年,依托于融合、开放、创新的数据处理技术和服务能力,为大型行业用户的特定场景提供深度挖掘数据价值的解决方案。
公司持续积累的核心关键技术,覆盖到分布式数据库集群、云数据平台、数据库大体量运管平台、海量数据集成于存储、清洗与治理、人工智能分析挖掘、可视化展现、安全与隐私保护等多个领域。
公司已与多个行业内的专业公司建立了长期伙伴关系,不断促进新技术与行业知识相结合,为用户寻求新的数据驱动的价值增长点。公司已在金融、能源电力、广电、政府等行业取得了众多大型用户典型成功案例,获得了市场的认可和业务的持续增长。



文章转载自爱可生云数据库,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




