Mysql 5.6中会话表的内存引擎实现
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mysql 5.6中会话表的内存引擎实现相关的知识,希望对你有一定的参考价值。
caching session variables in mysql using memory engine for fast client response.note: please test before use, then use at your own risk.
/** @author prgrmmr.aben [at] gmail (dot) com * http://fivesnippets.blogspot.com/2014/08/a-very-light-implementation-of-session.html * please give back a small donation if you find * this little educational snippet of code useful **/ CREATE TABLE IF NOT EXISTS `session` ( `id` INT(11) NOT NULL AUTO_INCREMENT, /*`refUser` int(11) DEFAULT NULL COMMENT 'references user number',*/ `IP` INT(39) DEFAULT NULL, `creation` datetime NOT NULL TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT 'creation time', `expiry` datetime DEFAULT NULL COMMENT 'expiry time', `secretToken` VARCHAR(10) NOT NULL, `type` enum('guest','client') NOT NULL DEFAULT 'guest', PRIMARY KEY (`id`), ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='don''t need to be a real session in memory' AUTO_INCREMENT=1 ; CREATE TABLE cachedSession ENGINE=MEMORY SELECT * FROM SESSION; CREATE DEFINER=`root`@`localhost` PROCEDURE `cacheSessions`() NO SQL BEGIN DELETE FROM cachedsession WHERE 1; INSERT INTO cachedsession SELECT * FROM SESSION WHERE `expiry`<NOW(); SELECT ROW_COUNT(); END$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `cleanSession`() NO SQL COMMENT 'clean sessions expired @hours ago' BEGIN DELETE FROM `session` WHERE TIMESTAMPDIFF(MINUTE, expiry, NOW())>0; SELECT ROW_COUNT(); END$$
以上是关于Mysql 5.6中会话表的内存引擎实现的主要内容,如果未能解决你的问题,请参考以下文章