- 浏览: 50953 次
- 性别:
- 来自: 上海
最新评论
MemCache 安装手册
wget http://launchpad.net/libmemcached/1.0/0.34/+download/libmemcached-0.34.tar.gz
wget http://memcached.googlecode.com/files/memcached-1.4.1.tar.gz
wget http://www.monkey.org/~provos/libevent-1.2.tar.gz
1、安装libevent
tar zxvf libevent-1.2.tar.gz
cd libevent-1.2
./configure -prefix=/usr/libevent
make
make install
2、安装memcache
tar -zxvf memcached-1.4.1.tar.gz
cd memcached-1.4.1
./configure -with-libevent=/usr/libevent/ -prefix=/usr/local/memcached
make
make install
3、安装libmemcached
wget http://launchpad.net/libmemcached/1.0/0.34/+download/libmemcached-0.34.tar.gz
tar xvzf libmemcached-0.34.tar.gz
cd libmemcached-0.34
./configure --prefix=/usr/local/libmemcached --with-memcached=/usr/local/memcached
./configure的时候,如果你的Memcached不是默认安装路径的话,会报
configure: error: “could not find memcached binary”
错,如下的类似的命令可以解决这个问题。
./configure --prefix=/usr/local/libmemcached --with-memcached=/usr/local/memcached/bin/memcached
make
make install
chmod 777 /etc/ld.so.conf
echo "/usr/local/libmemcached" >> /etc/ld.so.conf
ldconfig
4、安装memcached_functions_mysql
wget http://download.tangent.org/memcached_functions_mysql-0.9.tar.gz
http://patg.net/downloads/memcached_functions_mysql-0.9. tar.gz
tar zxvf memcached_functions_mysql-0.9.tar.gz
cd memcached_functions_mysql-0.9
./configure --prefix=/usr/local/memcache_mysql --with-mysql=/usr/local/mysql/bin/mysql_config --with-libmemcached=/usr/local/libmemcached
make; make install
cp /usr/local/memcache_mysql/lib/libmemcached_functions* /usr/local/mysql/lib/mysql/plugin
5)添加memcache UDF 函数
mysql> source sql/install_functions.sql
这样我们就可以使用mysql memcached UDF 了,我们可以通过下面语句查看是否已经正常安装
mysql> select * from mysql.func;
添加trigger,就是向memcache内insert,update,deletel等,参照:
1)memcached_functions_mysql-0.9/sql 目录下的trigger_fun.sql
2)或者文档:http://dev.mysql.com/doc/refman/5.1/en/ha-memcached-interfaces-mysqludf.html
如果懒得看就看我后边的例子
3 测试
/usr/local/memcached/bin/memcached -m 110m -u root -p 11211 -d -P -t 200 /var/run/memcached1.pid
64位会报以下的错误:
/usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-1.2.so.1: cannot open shared object file: No such file or directory
解决:ln -s /usr/libevent/lib/libevent-1.2.so.1 /usr/lib64/libevent-1.2.so.1
mysql> select memc_servers_set('127.0.0.1:11211')
注意:如果mysql restart,需要重新运行这句以建立与memcached之间的关系
mysql> select memc_servers_behavior_set('MEMCACHED_BEHAVIOR_NO_BLOCK','1');
+--------------------------------------------------------------+
| memc_servers_behavior_set('MEMCACHED_BEHAVIOR_NO_BLOCK','1') |
+--------------------------------------------------------------+
| 0 |
+--------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select memc_servers_behavior_set('MEMCACHED_BEHAVIOR_TCP_NODELAY','1');
+-----------------------------------------------------------------+
| memc_servers_behavior_set('MEMCACHED_BEHAVIOR_TCP_NODELAY','1') |
+-----------------------------------------------------------------+
| 0 |
+-----------------------------------------------------------------+
1 row in set (0.00 sec)
注意:设置MEMCACHED_BEHAVIOR_NO_BLOCK为打开状态,这样在memcached出现问题时(不能连接时)
数据继续插入到mysql中,报错提示,如果不设置此值,如果memcached失败,mysql需要等到timeout
才可以插入到表中。
mysql> use test;
Database changed
mysql> create table xxd (id int, value varchar(100));
mysql> create trigger xxdmmci after insert on xxd for each row set @tmp = memc_set(NEW.id, NEW.value);
mysql> create trigger xxdmmcu after update on xxd for each row set @tmp = memc_set(NEW.id, NEW.value);
mysql> create trigger xxdmmcd before delete on xxd for each row set @tmp = memc_delete(OLD.id);
mysql> insert into xxd values(1, 'xxd'),(2,'xxd79'),(3, 'buro79xxd');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select memc_get('2');
+----------------------------+
| memc_get('2') |
+----------------------------+
| xxd79 |
+----------------------------+
1 row in set (0.00 sec)
mysql> update xxd set value='xxd_new' where id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select memc_get('1');
+----------------------------+
| memc_get('1') |
+----------------------------+
| xxd_new |
+----------------------------+
1 row in set (0.00 sec)
mysql> delete from xxd where id=1;
Query OK, 1 row affected (0.00 sec)
mysql> select memc_get('1');
+----------------------------+
| memc_get('1') |
+----------------------------+
| NULL |
+----------------------------+
1 row in set (0.00 sec)
mysql> exit
$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get 1
END
get 2
VALUE 2 0 5
xxd79
END
get 3
VALUE 3 0 9
buro79xxd
END
quit
Connection closed by foreign host.
--EOF--
(1). 下载安装 lib_mysqludf_json 修改版:
以下安装包适合32位Linux操作系统:
wget http://mysql-udf-http.googlecode.com/files/lib_mysqludf_json-i386.tar.gz
tar zxvf lib_mysqludf_json-i386.tar.gz
cd lib_mysqludf_json-i386/
# 如果你的MySQL安装路径不是/usr/local/webserver/mysql/,请修改以下路径。
cp -f lib_mysqludf_json.so /usr/local/webserver/mysql/lib/mysql/plugin/lib_mysqludf_json.so
cd ../
以下安装包适合64位Linux操作系统:
wget http://mysql-udf-http.googlecode.com/files/lib_mysqludf_json-x86_64.tar.gz
tar zxvf lib_mysqludf_json-x86_64.tar.gz
cd lib_mysqludf_json-x86_64/
# 如果你的MySQL安装路径不是/usr/local/webserver/mysql/,请修改以下路径。
cp -f lib_mysqludf_json.so /usr/local/mysql/lib/mysql/plugin/lib_mysqludf_json.so
cd ../
通过命令行登陆进入MySQL:
/usr/local/webserver/mysql/bin/mysql -S /tmp/mysql.sock
mysql>
create function lib_mysqludf_json_info returns string soname 'lib_mysqludf_json.so';
create function json_array returns string soname 'lib_mysqludf_json.so';
create function json_members returns string soname 'lib_mysqludf_json.so';
create function json_object returns string soname 'lib_mysqludf_json.so';
create function json_values returns string soname 'lib_mysqludf_json.so';
lib_mysqludf_json的详细用法请访问:http://www.mysqludf.org/lib_mysqludf_json/
(2). 创建测试表
mysql>
SET NAMES UTF8;
USE test;
CREATE TABLE IF NOT EXISTS `mytable` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`addtime` int(10) NOT NULL,
`title` varchar(255) CHARACTER SET utf8 NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
SET NAMES UTF8;
USE test;
CREATE TABLE IF NOT EXISTS `mytable` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`addtime` int(10) NOT NULL,
`title` varchar(255) CHARACTER SET utf8 NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
(3). 为测试表创建触发器:
mysql>
/* INSERT插入操作的触发器 */
DELIMITER |
DROP TRIGGER IF EXISTS mytable_insert;
CREATE TRIGGER mytable_insert
AFTER INSERT ON mytable
FOR EACH ROW BEGIN
SET @tt_json = (SELECT json_object(id,addtime,title) FROM mytable WHERE id = NEW.id LIMIT 1);
SET @tt_resu = (SELECT http_put(CONCAT('http://127.0.0.1:11211/', NEW.id), @tt_json));
END |
DELIMITER ;
/* UPDATE更新操作的触发器 */
DELIMITER |
DROP TRIGGER IF EXISTS mytable_update;
CREATE TRIGGER mytable_update
AFTER UPDATE ON mytable
FOR EACH ROW BEGIN
SET @tt_json = (SELECT json_object(id,addtime,title) FROM mytable WHERE id = OLD.id LIMIT 1);
SET @tt_resu = (SELECT http_put(CONCAT('http://127.0.0.1:11211/', OLD.id), @tt_json));
END |
DELIMITER ;
/* DELETE删除操作的触发器 */
DELIMITER |
DROP TRIGGER IF EXISTS mytable_delete;
CREATE TRIGGER mytable_delete
AFTER DELETE ON mytable
FOR EACH ROW BEGIN
SET @tt_resu = (SELECT http_delete(CONCAT('http://127.0.0.1:11211/', OLD.id)));
END |
DELIMITER ;
/* INSERT插入操作的触发器 */
DELIMITER |
DROP TRIGGER IF EXISTS mytable_insert;
CREATE TRIGGER mytable_insert
AFTER INSERT ON mytable
FOR EACH ROW BEGIN
SET @tt_json = (SELECT json_object(id,addtime,title) FROM mytable WHERE id = NEW.id LIMIT 1);
SET @tt_resu = (SELECT http_put(CONCAT('http://127.0.0.1:11211/', NEW.id), @tt_json));
END |
DELIMITER ;
/* UPDATE更新操作的触发器 */
DELIMITER |
DROP TRIGGER IF EXISTS mytable_update;
CREATE TRIGGER mytable_update
AFTER UPDATE ON mytable
FOR EACH ROW BEGIN
SET @tt_json = (SELECT json_object(id,addtime,title) FROM mytable WHERE id = OLD.id LIMIT 1);
SET @tt_resu = (SELECT http_put(CONCAT('http://1127.0.0.1:11211/', OLD.id), @tt_json));
END |
DELIMITER ;
/* DELETE删除操作的触发器 */
DELIMITER |
DROP TRIGGER IF EXISTS mytable_delete;
CREATE TRIGGER mytable_delete
AFTER DELETE ON mytable
FOR EACH ROW BEGIN
SET @tt_resu = (SELECT http_delete(CONCAT('http://127.0.0.1:11211/', OLD.id)));
END |
DELIMITER ;
(4). 将 MySQL 表和 Tokyo Tyrant 关联进行查询:
mysql>
SELECT id,addtime,title,http_get(CONCAT('http://127.0.0.1:11211/',id)) AS tt FROM mytable ORDER BY id DESC LIMIT 0,5;
SELECT id,addtime,title,http_get(CONCAT('http://127.0.0.1:11211/',id)) AS tt FROM mytable ORDER BY id DESC LIMIT 0,5;
--------------------------------------------------------------------------------
5. 如何删除mysql-udf-http UDF函数:
mysql>
drop function http_get;
drop function http_post;
drop function http_put;
drop function http_delete;
drop function http_get;
drop function http_post;
drop function http_put;
drop function http_delete;
以上为详细安装!!!
memcache.php源文件下载
http://livebookmark.net/memcachephp/memcachephp.zip
或
http://pecl.php.net/get/memcache-2.2.6.tgz
如果安装memcache.php则要apache首先要支持php
即apache+php
然后旋转apache里面就可以。
测试例子:
五,测试
例子1:
mysql> select memc_servers_set('127.0.0.1:11211')
注意:如果mysql restart,需要重新运行这句以建立与memcached之间的关系
mysql> select memc_servers_behavior_set('MEMCACHED_BEHAVIOR_NO_BLOCK','1');
+--------------------------------------------------------------+
| memc_servers_behavior_set('MEMCACHED_BEHAVIOR_NO_BLOCK','1') |
+--------------------------------------------------------------+
| 0 |
+--------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select memc_servers_behavior_set('MEMCACHED_BEHAVIOR_TCP_NODELAY','1');
+-----------------------------------------------------------------+
| memc_servers_behavior_set('MEMCACHED_BEHAVIOR_TCP_NODELAY','1') |
+-----------------------------------------------------------------+
| 0 |
+-----------------------------------------------------------------+
1 row in set (0.00 sec)
注意:设置MEMCACHED_BEHAVIOR_NO_BLOCK为打开状态,这样在memcached出现问题时(不能连接时)
数据继续插入到mysql中,报错提示,如果不设置此值,如果memcached失败,mysql需要等到timeout
才可以插入到表中。
mysql> use test;
Database changed
mysql> create table xxd (id int, value varchar(100));
mysql> create trigger xxdmmci after insert on xxd for each row set @tmp = memc_set(NEW.id, NEW.value);
mysql> create trigger xxdmmcu after update on xxd for each row set @tmp = memc_set(NEW.id, NEW.value);
mysql> create trigger xxdmmcd before delete on xxd for each row set @tmp = memc_delete(OLD.id);
mysql> insert into xxd values(1, 'xxd'),(2,'xxd79'),(3, 'buro79xxd');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select memc_get('2');
+----------------------------+
| memc_get('2') |
+----------------------------+
| xxd79 |
+----------------------------+
1 row in set (0.00 sec)
mysql> update xxd set value='xxd_new' where id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select memc_get('1');
+----------------------------+
| memc_get('1') |
+----------------------------+
| xxd_new |
+----------------------------+
1 row in set (0.00 sec)
mysql> delete from xxd where id=1;
Query OK, 1 row affected (0.00 sec)
mysql> select memc_get('1');
+----------------------------+
| memc_get('1') |
+----------------------------+
| NULL |
+----------------------------+
1 row in set (0.00 sec)
mysql> exit
$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get 1
END
get 2
VALUE 2 0 5
xxd79
END
get 3
VALUE 3 0 9
buro79xxd
END
quit
Connection closed by foreign host.
telnet localhost 11211
//保存
set good 32 0 10
helloworld
STORED
//取回
gets good
VALUE good 32 10 10
helloworld
END
//替换
replace good 32 0 10
worldhello
STORED
get good
VALUE good 32 10
worldhello
END
//尾部添加
append good 32 0 5
after
STORED
get good
VALUE good 32 15
worldhelloafter
END
//头部添加
prepend good 32 0 6
before
STORED
get good
VALUE good 32 21
beforeworldhelloafter
END
//删除
delete good
DELETED
get good
END
delete good
NOT_FOUND
cas good 32 0 10 hel
helloworld
EXISTS
gets good
VALUE good 32 10 10
helloworld
END
cas bad 32 0 10 good
worldhello
NOT_FOUND
//统计
stats items
STAT items:1:number 1
STAT items:1:age 24
STAT items:1:evicted 0
STAT items:1:outofmemory 0
END
stats sizes
96 1
END
stats slabs
STAT 1:chunk_size 88
STAT 1:chunks_per_page 11915
STAT 1:total_pages 1
STAT 1:total_chunks 11915
STAT 1:used_chunks 11914
STAT 1:free_chunks 1
STAT 1:free_chunks_end 11913
STAT 2:chunk_size 112
STAT 2:chunks_per_page 9362
STAT 2:total_pages 1
STAT 2:total_chunks 9362
STAT 2:used_chunks 9361
STAT 2:free_chunks 1
STAT 2:free_chunks_end 9361
STAT 5:chunk_size 232
STAT 5:chunks_per_page 4519
STAT 5:total_pages 1
STAT 5:total_chunks 4519
STAT 5:used_chunks 4518
STAT 5:free_chunks 1
STAT 5:free_chunks_end 4518
STAT active_slabs 3
STAT total_malloced 3145472
END
stats items
STAT items:1:number 1
STAT items:1:age 1768
STAT items:1:evicted 0
STAT items:1:outofmemory 0
END
stats
STAT pid 18261
STAT uptime 528593
STAT time 1237277383
STAT version 1.2.6
STAT pointer_size 32
STAT rusage_user 0.004999
STAT rusage_system 0.015997
STAT curr_items 1
STAT total_items 2
STAT bytes 66
STAT curr_connections 2
STAT total_connections 13
STAT connection_structures 3
STAT cmd_get 11
STAT cmd_set 8
STAT get_hits 2
STAT get_misses 9
STAT evictions 0
STAT bytes_read 1342
STAT bytes_written 8752
STAT limit_maxbytes 134217728
STAT threads 1
END
使用usr/bin/perl /root/memcached-1.2.6/scripts/memcached-tool localhost:11211
output
# Item_Size Max_age 1MB_pages Count Full?
1 88 B 1531 s 1 1 no
2 112 B 0 s 1 0 no
5 232 B 0 s 1 0 no
# slab class编号
Item_Size Chunk大小
Max_age LRU内最旧的记录的生存时间
1MB_pages 分配给Slab的页数
Count Slab内的记录数
Full? Slab内是否含有空闲chunk
wget http://launchpad.net/libmemcached/1.0/0.34/+download/libmemcached-0.34.tar.gz
wget http://memcached.googlecode.com/files/memcached-1.4.1.tar.gz
wget http://www.monkey.org/~provos/libevent-1.2.tar.gz
1、安装libevent
tar zxvf libevent-1.2.tar.gz
cd libevent-1.2
./configure -prefix=/usr/libevent
make
make install
2、安装memcache
tar -zxvf memcached-1.4.1.tar.gz
cd memcached-1.4.1
./configure -with-libevent=/usr/libevent/ -prefix=/usr/local/memcached
make
make install
3、安装libmemcached
wget http://launchpad.net/libmemcached/1.0/0.34/+download/libmemcached-0.34.tar.gz
tar xvzf libmemcached-0.34.tar.gz
cd libmemcached-0.34
./configure --prefix=/usr/local/libmemcached --with-memcached=/usr/local/memcached
./configure的时候,如果你的Memcached不是默认安装路径的话,会报
configure: error: “could not find memcached binary”
错,如下的类似的命令可以解决这个问题。
./configure --prefix=/usr/local/libmemcached --with-memcached=/usr/local/memcached/bin/memcached
make
make install
chmod 777 /etc/ld.so.conf
echo "/usr/local/libmemcached" >> /etc/ld.so.conf
ldconfig
4、安装memcached_functions_mysql
wget http://download.tangent.org/memcached_functions_mysql-0.9.tar.gz
http://patg.net/downloads/memcached_functions_mysql-0.9. tar.gz
tar zxvf memcached_functions_mysql-0.9.tar.gz
cd memcached_functions_mysql-0.9
./configure --prefix=/usr/local/memcache_mysql --with-mysql=/usr/local/mysql/bin/mysql_config --with-libmemcached=/usr/local/libmemcached
make; make install
cp /usr/local/memcache_mysql/lib/libmemcached_functions* /usr/local/mysql/lib/mysql/plugin
5)添加memcache UDF 函数
mysql> source sql/install_functions.sql
这样我们就可以使用mysql memcached UDF 了,我们可以通过下面语句查看是否已经正常安装
mysql> select * from mysql.func;
添加trigger,就是向memcache内insert,update,deletel等,参照:
1)memcached_functions_mysql-0.9/sql 目录下的trigger_fun.sql
2)或者文档:http://dev.mysql.com/doc/refman/5.1/en/ha-memcached-interfaces-mysqludf.html
如果懒得看就看我后边的例子
3 测试
/usr/local/memcached/bin/memcached -m 110m -u root -p 11211 -d -P -t 200 /var/run/memcached1.pid
64位会报以下的错误:
/usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-1.2.so.1: cannot open shared object file: No such file or directory
解决:ln -s /usr/libevent/lib/libevent-1.2.so.1 /usr/lib64/libevent-1.2.so.1
mysql> select memc_servers_set('127.0.0.1:11211')
注意:如果mysql restart,需要重新运行这句以建立与memcached之间的关系
mysql> select memc_servers_behavior_set('MEMCACHED_BEHAVIOR_NO_BLOCK','1');
+--------------------------------------------------------------+
| memc_servers_behavior_set('MEMCACHED_BEHAVIOR_NO_BLOCK','1') |
+--------------------------------------------------------------+
| 0 |
+--------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select memc_servers_behavior_set('MEMCACHED_BEHAVIOR_TCP_NODELAY','1');
+-----------------------------------------------------------------+
| memc_servers_behavior_set('MEMCACHED_BEHAVIOR_TCP_NODELAY','1') |
+-----------------------------------------------------------------+
| 0 |
+-----------------------------------------------------------------+
1 row in set (0.00 sec)
注意:设置MEMCACHED_BEHAVIOR_NO_BLOCK为打开状态,这样在memcached出现问题时(不能连接时)
数据继续插入到mysql中,报错提示,如果不设置此值,如果memcached失败,mysql需要等到timeout
才可以插入到表中。
mysql> use test;
Database changed
mysql> create table xxd (id int, value varchar(100));
mysql> create trigger xxdmmci after insert on xxd for each row set @tmp = memc_set(NEW.id, NEW.value);
mysql> create trigger xxdmmcu after update on xxd for each row set @tmp = memc_set(NEW.id, NEW.value);
mysql> create trigger xxdmmcd before delete on xxd for each row set @tmp = memc_delete(OLD.id);
mysql> insert into xxd values(1, 'xxd'),(2,'xxd79'),(3, 'buro79xxd');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select memc_get('2');
+----------------------------+
| memc_get('2') |
+----------------------------+
| xxd79 |
+----------------------------+
1 row in set (0.00 sec)
mysql> update xxd set value='xxd_new' where id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select memc_get('1');
+----------------------------+
| memc_get('1') |
+----------------------------+
| xxd_new |
+----------------------------+
1 row in set (0.00 sec)
mysql> delete from xxd where id=1;
Query OK, 1 row affected (0.00 sec)
mysql> select memc_get('1');
+----------------------------+
| memc_get('1') |
+----------------------------+
| NULL |
+----------------------------+
1 row in set (0.00 sec)
mysql> exit
$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get 1
END
get 2
VALUE 2 0 5
xxd79
END
get 3
VALUE 3 0 9
buro79xxd
END
quit
Connection closed by foreign host.
--EOF--
(1). 下载安装 lib_mysqludf_json 修改版:
以下安装包适合32位Linux操作系统:
wget http://mysql-udf-http.googlecode.com/files/lib_mysqludf_json-i386.tar.gz
tar zxvf lib_mysqludf_json-i386.tar.gz
cd lib_mysqludf_json-i386/
# 如果你的MySQL安装路径不是/usr/local/webserver/mysql/,请修改以下路径。
cp -f lib_mysqludf_json.so /usr/local/webserver/mysql/lib/mysql/plugin/lib_mysqludf_json.so
cd ../
以下安装包适合64位Linux操作系统:
wget http://mysql-udf-http.googlecode.com/files/lib_mysqludf_json-x86_64.tar.gz
tar zxvf lib_mysqludf_json-x86_64.tar.gz
cd lib_mysqludf_json-x86_64/
# 如果你的MySQL安装路径不是/usr/local/webserver/mysql/,请修改以下路径。
cp -f lib_mysqludf_json.so /usr/local/mysql/lib/mysql/plugin/lib_mysqludf_json.so
cd ../
通过命令行登陆进入MySQL:
/usr/local/webserver/mysql/bin/mysql -S /tmp/mysql.sock
mysql>
create function lib_mysqludf_json_info returns string soname 'lib_mysqludf_json.so';
create function json_array returns string soname 'lib_mysqludf_json.so';
create function json_members returns string soname 'lib_mysqludf_json.so';
create function json_object returns string soname 'lib_mysqludf_json.so';
create function json_values returns string soname 'lib_mysqludf_json.so';
lib_mysqludf_json的详细用法请访问:http://www.mysqludf.org/lib_mysqludf_json/
(2). 创建测试表
mysql>
SET NAMES UTF8;
USE test;
CREATE TABLE IF NOT EXISTS `mytable` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`addtime` int(10) NOT NULL,
`title` varchar(255) CHARACTER SET utf8 NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
SET NAMES UTF8;
USE test;
CREATE TABLE IF NOT EXISTS `mytable` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`addtime` int(10) NOT NULL,
`title` varchar(255) CHARACTER SET utf8 NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
(3). 为测试表创建触发器:
mysql>
/* INSERT插入操作的触发器 */
DELIMITER |
DROP TRIGGER IF EXISTS mytable_insert;
CREATE TRIGGER mytable_insert
AFTER INSERT ON mytable
FOR EACH ROW BEGIN
SET @tt_json = (SELECT json_object(id,addtime,title) FROM mytable WHERE id = NEW.id LIMIT 1);
SET @tt_resu = (SELECT http_put(CONCAT('http://127.0.0.1:11211/', NEW.id), @tt_json));
END |
DELIMITER ;
/* UPDATE更新操作的触发器 */
DELIMITER |
DROP TRIGGER IF EXISTS mytable_update;
CREATE TRIGGER mytable_update
AFTER UPDATE ON mytable
FOR EACH ROW BEGIN
SET @tt_json = (SELECT json_object(id,addtime,title) FROM mytable WHERE id = OLD.id LIMIT 1);
SET @tt_resu = (SELECT http_put(CONCAT('http://127.0.0.1:11211/', OLD.id), @tt_json));
END |
DELIMITER ;
/* DELETE删除操作的触发器 */
DELIMITER |
DROP TRIGGER IF EXISTS mytable_delete;
CREATE TRIGGER mytable_delete
AFTER DELETE ON mytable
FOR EACH ROW BEGIN
SET @tt_resu = (SELECT http_delete(CONCAT('http://127.0.0.1:11211/', OLD.id)));
END |
DELIMITER ;
/* INSERT插入操作的触发器 */
DELIMITER |
DROP TRIGGER IF EXISTS mytable_insert;
CREATE TRIGGER mytable_insert
AFTER INSERT ON mytable
FOR EACH ROW BEGIN
SET @tt_json = (SELECT json_object(id,addtime,title) FROM mytable WHERE id = NEW.id LIMIT 1);
SET @tt_resu = (SELECT http_put(CONCAT('http://127.0.0.1:11211/', NEW.id), @tt_json));
END |
DELIMITER ;
/* UPDATE更新操作的触发器 */
DELIMITER |
DROP TRIGGER IF EXISTS mytable_update;
CREATE TRIGGER mytable_update
AFTER UPDATE ON mytable
FOR EACH ROW BEGIN
SET @tt_json = (SELECT json_object(id,addtime,title) FROM mytable WHERE id = OLD.id LIMIT 1);
SET @tt_resu = (SELECT http_put(CONCAT('http://1127.0.0.1:11211/', OLD.id), @tt_json));
END |
DELIMITER ;
/* DELETE删除操作的触发器 */
DELIMITER |
DROP TRIGGER IF EXISTS mytable_delete;
CREATE TRIGGER mytable_delete
AFTER DELETE ON mytable
FOR EACH ROW BEGIN
SET @tt_resu = (SELECT http_delete(CONCAT('http://127.0.0.1:11211/', OLD.id)));
END |
DELIMITER ;
(4). 将 MySQL 表和 Tokyo Tyrant 关联进行查询:
mysql>
SELECT id,addtime,title,http_get(CONCAT('http://127.0.0.1:11211/',id)) AS tt FROM mytable ORDER BY id DESC LIMIT 0,5;
SELECT id,addtime,title,http_get(CONCAT('http://127.0.0.1:11211/',id)) AS tt FROM mytable ORDER BY id DESC LIMIT 0,5;
--------------------------------------------------------------------------------
5. 如何删除mysql-udf-http UDF函数:
mysql>
drop function http_get;
drop function http_post;
drop function http_put;
drop function http_delete;
drop function http_get;
drop function http_post;
drop function http_put;
drop function http_delete;
以上为详细安装!!!
memcache.php源文件下载
http://livebookmark.net/memcachephp/memcachephp.zip
或
http://pecl.php.net/get/memcache-2.2.6.tgz
如果安装memcache.php则要apache首先要支持php
即apache+php
然后旋转apache里面就可以。
测试例子:
五,测试
例子1:
mysql> select memc_servers_set('127.0.0.1:11211')
注意:如果mysql restart,需要重新运行这句以建立与memcached之间的关系
mysql> select memc_servers_behavior_set('MEMCACHED_BEHAVIOR_NO_BLOCK','1');
+--------------------------------------------------------------+
| memc_servers_behavior_set('MEMCACHED_BEHAVIOR_NO_BLOCK','1') |
+--------------------------------------------------------------+
| 0 |
+--------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select memc_servers_behavior_set('MEMCACHED_BEHAVIOR_TCP_NODELAY','1');
+-----------------------------------------------------------------+
| memc_servers_behavior_set('MEMCACHED_BEHAVIOR_TCP_NODELAY','1') |
+-----------------------------------------------------------------+
| 0 |
+-----------------------------------------------------------------+
1 row in set (0.00 sec)
注意:设置MEMCACHED_BEHAVIOR_NO_BLOCK为打开状态,这样在memcached出现问题时(不能连接时)
数据继续插入到mysql中,报错提示,如果不设置此值,如果memcached失败,mysql需要等到timeout
才可以插入到表中。
mysql> use test;
Database changed
mysql> create table xxd (id int, value varchar(100));
mysql> create trigger xxdmmci after insert on xxd for each row set @tmp = memc_set(NEW.id, NEW.value);
mysql> create trigger xxdmmcu after update on xxd for each row set @tmp = memc_set(NEW.id, NEW.value);
mysql> create trigger xxdmmcd before delete on xxd for each row set @tmp = memc_delete(OLD.id);
mysql> insert into xxd values(1, 'xxd'),(2,'xxd79'),(3, 'buro79xxd');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select memc_get('2');
+----------------------------+
| memc_get('2') |
+----------------------------+
| xxd79 |
+----------------------------+
1 row in set (0.00 sec)
mysql> update xxd set value='xxd_new' where id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select memc_get('1');
+----------------------------+
| memc_get('1') |
+----------------------------+
| xxd_new |
+----------------------------+
1 row in set (0.00 sec)
mysql> delete from xxd where id=1;
Query OK, 1 row affected (0.00 sec)
mysql> select memc_get('1');
+----------------------------+
| memc_get('1') |
+----------------------------+
| NULL |
+----------------------------+
1 row in set (0.00 sec)
mysql> exit
$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get 1
END
get 2
VALUE 2 0 5
xxd79
END
get 3
VALUE 3 0 9
buro79xxd
END
quit
Connection closed by foreign host.
telnet localhost 11211
//保存
set good 32 0 10
helloworld
STORED
//取回
gets good
VALUE good 32 10 10
helloworld
END
//替换
replace good 32 0 10
worldhello
STORED
get good
VALUE good 32 10
worldhello
END
//尾部添加
append good 32 0 5
after
STORED
get good
VALUE good 32 15
worldhelloafter
END
//头部添加
prepend good 32 0 6
before
STORED
get good
VALUE good 32 21
beforeworldhelloafter
END
//删除
delete good
DELETED
get good
END
delete good
NOT_FOUND
cas good 32 0 10 hel
helloworld
EXISTS
gets good
VALUE good 32 10 10
helloworld
END
cas bad 32 0 10 good
worldhello
NOT_FOUND
//统计
stats items
STAT items:1:number 1
STAT items:1:age 24
STAT items:1:evicted 0
STAT items:1:outofmemory 0
END
stats sizes
96 1
END
stats slabs
STAT 1:chunk_size 88
STAT 1:chunks_per_page 11915
STAT 1:total_pages 1
STAT 1:total_chunks 11915
STAT 1:used_chunks 11914
STAT 1:free_chunks 1
STAT 1:free_chunks_end 11913
STAT 2:chunk_size 112
STAT 2:chunks_per_page 9362
STAT 2:total_pages 1
STAT 2:total_chunks 9362
STAT 2:used_chunks 9361
STAT 2:free_chunks 1
STAT 2:free_chunks_end 9361
STAT 5:chunk_size 232
STAT 5:chunks_per_page 4519
STAT 5:total_pages 1
STAT 5:total_chunks 4519
STAT 5:used_chunks 4518
STAT 5:free_chunks 1
STAT 5:free_chunks_end 4518
STAT active_slabs 3
STAT total_malloced 3145472
END
stats items
STAT items:1:number 1
STAT items:1:age 1768
STAT items:1:evicted 0
STAT items:1:outofmemory 0
END
stats
STAT pid 18261
STAT uptime 528593
STAT time 1237277383
STAT version 1.2.6
STAT pointer_size 32
STAT rusage_user 0.004999
STAT rusage_system 0.015997
STAT curr_items 1
STAT total_items 2
STAT bytes 66
STAT curr_connections 2
STAT total_connections 13
STAT connection_structures 3
STAT cmd_get 11
STAT cmd_set 8
STAT get_hits 2
STAT get_misses 9
STAT evictions 0
STAT bytes_read 1342
STAT bytes_written 8752
STAT limit_maxbytes 134217728
STAT threads 1
END
使用usr/bin/perl /root/memcached-1.2.6/scripts/memcached-tool localhost:11211
output
# Item_Size Max_age 1MB_pages Count Full?
1 88 B 1531 s 1 1 no
2 112 B 0 s 1 0 no
5 232 B 0 s 1 0 no
# slab class编号
Item_Size Chunk大小
Max_age LRU内最旧的记录的生存时间
1MB_pages 分配给Slab的页数
Count Slab内的记录数
Full? Slab内是否含有空闲chunk
发表评论
-
ES安装部署
2021-01-11 11:01 284一,准备工作 1,Es下载链接 https://mirro ... -
计算机基础
2021-01-11 10:53 4581、计算机完整的体系结 ... -
KVM详细安装
2016-02-22 09:59 700KVM详细安装 安装KVM yum -y install q ... -
linux for
2015-09-23 15:44 0for ((i=0;i<10000;i++)); do ... -
sendmail无法发送邮件
2013-07-25 11:57 979sendmail无法发送邮件 后面经过修改。 vi /etc/ ... -
msmtp
2013-06-06 10:43 842原来一直在Linux下使 ... -
sysctl优化脚本
2012-12-28 12:32 964#!/bin/sh sysctl -w net.ipv4.n ... -
linux date
2012-12-19 12:04 823linux date 我使用过的Linux命令之date - ... -
http错误
2012-07-26 17:09 9521xx - 信息提示 这些状态代码表示临时的响应。客户端在收到 ... -
nagios最新详细安装
2012-08-11 11:46 1649nagios最新详细安装 第一部分: 一、开发库等安装 首 ... -
centos_5中文语言包安装
2012-07-06 14:57 636第一:中文语言包: 在一台机子上装了centos 5,刚开始没 ... -
linux包批量安装
2012-06-30 10:09 758yum groupinstall "KDE (K D ... -
Linux系统信息查看命令大全
2012-06-30 09:59 1430系统 # uname -a # 查看内 ... -
python交互式自动部署
2012-06-26 09:06 1817python交互式自动部署 1、首先要做ssh互相信息 2、 ... -
linux下安装expect
2012-06-16 16:29 1438linux下安装expect expect ... -
python一些组件的安装
2012-06-16 16:17 5689paramiko是python(2.2或更高)的模块,遵循SS ... -
ssh不需要密码登录
2012-06-15 09:31 857ssh不需要密码登录 A为登录B、C、D三台机器 A的相关配置 ... -
MegaCli安装
2012-06-13 17:50 0下载地址:wget http://www.eth0.us/fi ... -
rsync配置及报错处理
2012-06-07 17:49 4096服务器端配置文件: 首先安装rsync+xinetd 并启用 ... -
mysql快速安装
2012-06-01 16:08 902一、快速安装mysql准备工作 首先需要保证自己的开发工具包 ...
相关推荐
Linux MemCache 安装手册 Memcached是一款高性能、分布式内存对象缓存系统,它被广泛应用于Web应用中,用于减轻数据库的负载,提高数据访问速度。这个安装手册将引导你完成在Linux环境下安装和配置Memcached的过程...
( Memcache_安装配置手册.doc
阿里云的云数据库Memcache版API手册主要涵盖了如何与Memcache进行交互的详细规范,尤其适合开发者和系统管理员使用。Memcache是一种广泛应用于缓存数据的高性能、分布式内存对象缓存系统,它能够提高Web应用的性能,...
Memcache 使用手册 Memcache 是一种高性能的内存键值缓存,它可以为应用程序提供高速的数据访问。Memcache 服务可以通过应用程序的多个实例访问该缓存, Memcache 对于那些不需要数据库的永久性功能和事务功能的...
本手册旨在详细介绍如何搭建基于Memcache+Tomcat的集群环境,并对其关键配置进行说明。 #### 二、基础知识介绍 ##### 2.1 Memcache简介 Memcache是一种高性能、分布式内存对象缓存系统,通过减轻数据库负载来加速...
阿里云提供的云数据库Memcache版API手册主要介绍了如何操作和管理基于Memcache的分布式缓存服务。Memcache是一种广泛使用的高性能、内存中的键值存储系统,常用于减轻数据库的负载,提高Web应用的响应速度。以下是...
根据给定的文件信息,以下是对OpenStack控制节点安装手册中的关键知识点的详细解析: ### OpenStack控制节点安装概述 OpenStack控制节点是OpenStack架构的核心组成部分,负责处理API请求、认证用户、调度资源以及...
Java Memcache 是一个高效、广泛使用的分布式内存缓存系统,专为加速动态Web应用程序而设计。在JDK 1.4环境下使用Java Memcache,意味着我们需要一个兼容此版本JVM的客户端库,以便与Memcache服务器进行通信。在这个...
### Linux下memcached安装手册 #### 一、概述 本文档旨在详细介绍如何在Linux环境下安装memcached,并确保其正常运行。memcached是一款高性能、分布式内存对象缓存系统,用于加速动态Web应用程序,减轻数据库负担...
这份手册详细介绍了 `memcachedb` 的安装、配置、使用以及维护等各个方面,旨在帮助用户更好地理解和操作这个工具。 1. **系统需求与安装** - `memcachedb` 需要在支持 `memcached` 的操作系统上运行,如 Linux、...
整体而言,ThinkPHP3.2.3完全开发手册是针对特定版本的ThinkPHP框架的技术文档,提供了框架的使用、安装、功能更新和版权信息等详细资料,目的是帮助开发者更好地理解和利用ThinkPHP进行Web应用开发。
在使用云数据库 Memcache 版时,用户需要遵守阿里云的保密义务,未经阿里云事先书面同意,不得向任何第三方披露本手册内容或提供给任何第三方使用。 此外,云数据库 Memcache 版产品简介还包括了目录、法律声明、...
未经阿里云事先书面同意,用户不得向任何第三方披露本手册内容或提供给任何第三方使用。 3. 未经阿里云事先书面许可,任何单位、公司或个人不得擅自摘抄、翻译、复制本文档内容的部分或全部,不得以任何方式或途径...
Java的安装;Tomcat安装;Tomcat的集群;Tomcat的调优;JVM优化:生产环境参数实例及分析;优化JVM参数提高eclipse运行速度;...memcache集群配置;JMS安装;JMS集群配置;Nginx反向代理;防火墙配置
ThinkPHP 5开发手册是面向ThinkPHP框架初学者和需要...手册覆盖了从安装到部署的整个流程,并针对安全性和性能优化提供了详细的建议。对于任何想要深入学习和使用ThinkPHP 5的开发者来说,这本手册都是不可或缺的资源。
以上步骤详细介绍了如何从零开始构建一个完整的OpenStack IaaS环境。通过这些步骤,不仅可以实现云基础设施的快速搭建,还能够深入了解OpenStack各组件之间的交互机制以及它们在实际场景中的应用。
手册会详细指导如何配置Apache或Nginx服务器以适应ThinkPHP。 2. **目录结构**:了解ThinkPHP的目录结构对后续开发至关重要,包括APP目录、CONF目录、LIBRARY目录等,每个目录都有特定的功能和用途。 3. **MVC模式...
2. **安装与配置**:手册详细介绍了如何下载ThinkPHP3.0并进行安装,包括设置环境变量、配置Apache或Nginx服务器以及数据库连接设置等。同时,还提供了快速启动示例,帮助开发者快速搭建第一个ThinkPHP项目。 3. **...