2013年4月30日星期二

NoSQL :: PHP :: MEMCACHE :: INNODB :: MySQL

Original Post: http://anothermysqldba.blogspot.com/2013/04/nosql-php-memcache-innodb-mysql.html

现在的MySQL 5.6已经出了一小会儿, Percona的5.6 ,在写这篇的时候,阿尔法,我们都将开始看起来更涉及到MySQL的NoSQL解决方案。 (我会继续关注和MariaDB的在这方面做的)。但无论如何... 因为开发人员和管理人员继续好奇的NoSQL可以提供什么.... 

这仅仅是给予了很高的水平作为一个NoSQL解决方案使用Memcache的概述,并保持MySQL的InnoDB数据库和数据圆通。 

虽然这个博客是不是第一个关于这个主题,我希望这几件事情连在一起,对一些人来说。 

良好的读取和引用在这里: 
https://blogs.oracle.com/mysqlinnodb/entry/get_started_with_innodb_memcached 
http://schlueters.de/blog/archives/152-Not-only-SQL-memcache-and-MySQL-5.6.html 
http://dev.mysql.com/doc/refman/5.6/en/innodb-memcached-setup.html 
https://blogs.oracle.com/jsmyth/entry/nosql_with_mysql_s_memcached 
http://yoshinorimatsunobu.blogspot.com/2010/10/using-mysql-as-nosql-story-for.html 
https://blogs.oracle.com/mysqlinnodb/entry/nosql_to_innodb_with_memcached 
https://blogs.oracle.com/MySQL/entry/mysql_5_6_is_a 
https://blogs.oracle.com/mysqlinnodb/entry/get_started_with_innodb_memcached 
http://planet.mysql.com/entry/?id=32830 
NoSQL的http://dev.mysql.com/tech-resources/articles/whats-new-in-mysql-5.6.html# 
http://dev.mysql.com/doc/refman/5.6/en/innodb-memcached-internals.html 
http://dev.mysql.com/doc/refman/5.6/en/innodb-memcached-troubleshoot.html 


# php --version

PHP 5.4.14 (cli) (built: Apr 27 2013 14:22:04)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies 

否则我的PHP安装也有这个....

more /etc/php.d/memcache.ini

; ----- Options to use the memcache session handler
; Use memcache as a session handler
session.save_handler=memcache
; Defines a comma separated of server urls to use for session storage
session.save_path="tcp://localhost:11211" 


首先激活插件... 


mysql> install plugin daemon_memcached soname "libmemcached.so"; 

创建一个数据库,所以我们不只是使用标准试验Db和demo_test的所有其他的例子中使用。 只是为了显示它不只是锁定。 



CREATE DATABASE nosql_mysql_innodb_memcache;
use nosql_mysql_innodb_memcache;

CREATE TABLE nosql_mysql (
`demo_key` VARCHAR(32),
`demo_value` VARCHAR(1024),
`demo_flag` INT,
`demo_cas` BIGINT UNSIGNED,
`demo_expire` INT,
primary key(demo_key)
)
ENGINE = INNODB;

use innodb_memcache;

INSERT INTO containers VALUES ('DEMO','nosql_mysql_innodb_memcache','nosql_mysql','demo_key','demo_value','demo_flag','demo_cas','demo_expire','PRIMARY');


select * from containers\G
*************************** 1. row ***************************
name: DEMO
db_schema: nosql_mysql_innodb_memcache
db_table: nosql_mysql
key_columns: demo_key
value_columns: demo_value
flags: demo_flag
cas_column: demo_cas
expire_time_column: demo_expire
unique_idx_name_on_key: PRIMARY 


OK现在让我们只是有一些在此表中的数据,以证明它像正常的MySQL运行。


mysql>use nosql_mysql_innodb_memcache;
mysql> insert into nosql_mysql VALUES ('key1','demo data','1',1,1);
Query OK, 1 row affected (0.04 sec)


select * from nosql_mysql \G
*************************** 1. row ***************************
demo_key: key1
demo_value: demo data
demo_flag: 1
demo_cas: 1
demo_expire: 1
1 row in set (0.00 sec) 

因此,让我们看看我们能做些什么现在用PHP ...


PHP代码: 

$memcache->connect('localhost', 11211) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";

$memcache->set('key3', 'FROM PHP') or die ("Failed to save data at the server");
echo "Data from the cache:<br/>\n";
echo $memcache->get('key3');
?> 

PHP的输出: 
服务器版本:5.6.10 
从高速缓存中的数据: 
从PHP 


我们所能做的只是笑着典型的例子,我们看到和使用telnet。 



telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
set key2 1 0 11
Hello World
STORED
get key2
VALUE key2 1 11
Hello World
END
get key3
VALUE key3 0 8
FROM PHP
END 
好吧,让我们看看我们在MySQL数据库中 


set session TRANSACTION ISOLATION LEVEL read uncommitted;
SELECT @@GLOBAL.tx_isolation, @@tx_isolation \G
*************************** 1. row ***************************
@@GLOBAL.tx_isolation: REPEATABLE-READ
@@tx_isolation: READ-UNCOMMITTED


> select * from nosql_mysql\G
*************************** 1. row ***************************
demo_key: key1
demo_value: demo data
demo_flag: 1
demo_cas: 1
demo_expire: 1
*************************** 2. row ***************************
demo_key: key2
demo_value: Hello World
demo_flag: 1
demo_cas: 2
demo_expire: 0
*************************** 3. row ***************************
demo_key: key3
demo_value: FROM PHP
demo_flag: 0
demo_cas: 2
demo_expire: 0 


因此,PHP和MySQL的InnoDB的memcache中,我们可以看到,我们能够直接地,以解决代码。

当然别人有自己的见解( http://blog.couchbase.com/why-mysql-56-no-real-threat-nosql),但我认为这仅仅是一个开始,我们将如何能够使用NoSQL的MySQL的。