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
新聞熱點
疑難解答