首页 > 精选文章 > 数据库开发 > 正文

mysql memcached UDF 安装详解

1:mysql memcached UDF 其实就是通过libmemcached来使用memcache的一系列函数,通过这些函数,你能 对memcache进行get, set, cas, append, prepend, delete, increment, decrement objects操作,如果我们通过mysql trigger来使用这些函数,那么就能通过mysql更好的,更自动的管理memcache!

2:安装方法:

1)安装memcache

2)安装libmemcached

shell> cd libmemcached-0.35
shell> ./configure --with-memcached=/usr/local/bin/memcached
shell> make && make install
shell> echo "/usr/local/lib" >> /etc/ld.so.conf
shell> ldconfig

3)安装memcached_functions_mysql
shell> tar zxvf memcached_functions_mysql-0.9.tar.gz
shell> cd memcached_functions_mysql-0.9
shell> ./configure --with-mysql=/usr/local/mysql51/bin/mysql_config --with-libmemcached =/usr/local/
shell> make && make install

4)拷贝lib文件到mysql的plugin下面
shell> cp -R /usr/local/lib/libmemcached_functions_mysql.* /usr/local/mysql51/lib/mysql/plugin/

5)添加memcache UDF 函数

在mysql里执行 source install_functions.sql

这样我们就可以使用mysql memcached UDF 了,我们可以通过下面语句查看是否已经正常安装

1)查看mysql.func,有很多函数

mysql> select * from mysql.func;
+------------------------------+-----+---------------------------------+----------+
| name                         | ret | dl                              | type     |
+------------------------------+-----+---------------------------------+----------+
| memc_add                     |   2 | libmemcached_functions_mysql.so | function |
| memc_add_by_key              |   2 | libmemcached_functions_mysql.so | function |
| memc_servers_set             |   2 | libmemcached_functions_mysql.so | function |

2)添加trigger,看是否向memcache里insert、update等

具体的语句,我们可以参照:

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


我们还必须注意以下几点:

1)mysql 编译时一定不要带'--with-mysqld-ldflags=-all-static' 这个参数,因为这样就限制了mysql 的动态安装功能了

2)使用时,要观察mysql.err日志,不知道是有意还是无意,udf更新memcache都会记录在err日志里,注意清理该日志,否则一下就爆满了

3)mysql 官网有这样一句话:

The list of servers used by the memcached UDFs is not persistent over restarts of the MySQL server. If the MySQL server fails, then you must re-set the list of memcached servers.

所以,当我们重启mysql,我们必须通过select  memc_servers_set('192.168.0.1:11211,192.168.0.2:11211');语句重新注册memcache服务器!

参考:http://dev.mysql.com/doc/refman/5.0/en/ha-memcached-interfaces.html

  • 上一篇:保卫萝卜挑战27金萝卜攻略
  • 下一篇:亚马逊最赚钱的项目竟然是展示广告?
  • 了解这些字:安的意思 装的意思 详的意思 解的意思