查看文章 |
很早之前,就看到了通过mysql UDF 更新memcached ,原来也研究过一段时间,只是没有来得及写个文档,导致后来工作中,经常要google,搜索其安装,使用的方法,刹时麻烦,今天总结一下: 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 3)安装memcached_functions_mysql 4)拷贝lib文件到mysql的plugin下面 5)添加memcache UDF 函数 在mysql里执行 source install_functions.sql 这样我们就可以使用mysql memcached UDF 了,我们可以通过下面语句查看是否已经正常安装 1)查看mysql.func,有很多函数 mysql> select * from mysql.func; 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服务器! |

