Home  >  Article  >  Database  >  mysql5.6.4支持nosql_MySQL

mysql5.6.4支持nosql_MySQL

WBOY
WBOYOriginal
2016-06-01 13:43:25941browse

bitsCN.com

在最新的 mysql-5.6.4-labs-innodb-memcached 中,实现了简单的给予 key/value的nosql功能,其主要原理
就是mysqld除了监听3306端口之外,同时监听11211端口。使mysqld和memcached服务处在同一进程中。通过
数据库、表与字段的映射,将缓存在memcache的数据插入到映射的表中。安装包中提供了三张表:containers
cache_policies和config_options,表containers就提供了映射关系,表cache_policies提供了三种存储方式(
innodb_only数据只插入表,cache_only只缓存数据,caching即缓存数据又插入表),表config_options中提供
了一个默认分隔符“|”,就是说如果在表containers的values字段中定义了col1,col2...字段,那在设置缓存值时就
可以用val1|val2的形式,这样将会把val1插入到col1,val2插入到col2。
新版中提供了两个重要文件:
1) libmemcached.so: this is the memcached daemon plugin to MySQL
2) innodb_engine.so: this is an InnoDB API plugin to memcached
安装了插件 libmemcached.so之后,那么memcache就可以通过innodb提供的API直接访问mysql,快捷方便。

安装方式

基本安装可以参考安装包中的INSTALL-BINARY文件,其中一段如下:

mysql5.6.4支持nosql_MySQL

然后可以通过 ln 做一下软链接
commands:ln -s path(path为mysql安装包目录) /usr/local/mysql

安装配置表

在安装包的scripts文件夹下有innodb_memcached_config.sql,将文件导入到mysql中
commands:/usr/local/mysql/bin/mysql -uroot -P 3306 -S /tmp/mysql.sock 执行完之后再执行:/usr/local/mysql/bin/mysql,将会出现innodb_memcache数据库,默认containers配置是将缓存的数据插入到test
数据库中的demo_test表中,字段c1为缓存key,字段c2为缓存数据......

安装innodbmemcache插件

可以通过:show variables like '%memcache%'; 查看插件是否安装
连接mysql,安装commands:install plugin daemon_memcached soname "libmemcached.so";
成功之后将memcache服务安装上

测试

通过telnet 127.0.0.1 11211 连接memcache,简单测试
set a11 10 0 9
123456789
STORED
get a11
VALUE a11 0 9
123456789
END
这样就缓存了一条数据,这时候去数据库查看test.demo_test,并不能查到这条数据,这句翻译不好:
1) If you would like to take a look at what’s in the “demo_test” table, please remember we had batched the commits (32 ops by default) by default.

So you will need to do “read uncommitted” select to find the just inserted rows:

mysql> set session TRANSACTION ISOLATION LEVEL
-> read uncommitted;

反正就是执行上面语句,将读设置为不受限制,然后再执行:select * from test.demo_test;就会查到两条数据,这样恭喜你,你成功了!

有兴趣请深入研究,也可以研究一下mysql集群处理,mysql-cluster最新版本7.2.4

 

本文来自于“老王的技术摘要”专栏  作者 sunny5211

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn