Mysql 5.1 supports triggers and UDF features. If libmemcache and Memcached Functions for MySQL are used together, memcache can be automatically updated. Record the installation and testing steps.
Installation Steps
- Install memcached. This step is simple and can be seen everywhere.
- Install mysql server 5.1RC.
- Compile libmemcached, decompress it, and install it.
./configure; make; make install
- Compile Memcached Functions for MySQL. Find the latest download path at http://download.tangent.org/here,
./configure --with-mysql=/usr/local/mysql/bin/mysql_config --libdir=/usr/local/mysql/lib/mysql/
make
make install
There are two ways to make Memcached Functions for MySQL take effect in mysql.
- Execute SQL/install_functions. SQL IN THE memcached_functions_mysql source code directory in the mysql shell. This will add memcache function as UDF to mysql
- Run utils/install. pl in the memcached_functions_mysql source code directory. This is a perl script that works the same way as the previous one.
Test memcache function
The following test script is taken from the source code directory of memcached_functions_mysql. If you are interested, try it.
Drop table if exists urls;
Create table urls (
Id int (3) not null,
Url varchar (64) not null default '',
Primary key (id)
);
Select memc_servers_set ('localhost: 100 ');
Select memc_set ('urls: sequence ', 0 );
DELIMITER
Drop trigger if exists url_mem_insert;
Create trigger url_mem_insert
Before insert on urls
FOR EACH ROW BEGIN
Set new. id = memc_increment ('urls: sequence ');
SET @ mm = memc_set (concat ('urls: ', NEW. id), NEW. url );
END
DELIMITER;
Insert into urls (url) values ('HTTP: // google.com ');
Insert into urls (url) values ('HTTP: // www.ooso.net/index.php ');
Insert into urls (url) values ('HTTP: // www.ooso.net /');
Insert into urls (url) values ('HTTP: // slashdot.org ');
Insert into urls (url) values ('HTTP: // mysql.com ');
Select * from urls;
Select memc_get ('urls: 1 ');
Select memc_get ('urls: 2 ');
Select memc_get ('urls: 3 ');
Select memc_get ('urls: 4 ');
Select memc_get ('urls: 5 ');