MySQL 5.1 supports triggers as well as custom function interface (UDF) features, and can implement memcache Automatic Updates if combined with Libmemcache and memcached functions for MySQL. Simply record the installation test steps.
Installation steps
- Install memcached, this step is very simple, everywhere
- Install MySQL server 5.1RC, installation method also very popular, no nonsense.
- Compile libmemcached, after decompression installation can
./configure; make; make install
- Compile memcached functions for MySQL, in http://download.tangent.org/ find an updated version of the download is,
./configure --with-mysql=/usr/local/mysql/bin/mysql_config --libdir=/usr/local/mysql/lib/mysql/
make
make install
Next, there are two ways to get memcached functions for MySQL to take effect in MySQL
- Execute the Sql/install_functions.sql in the Memcached_functions_mysql source directory in the MySQL shell, which will add the Memcache function as a UDF to MySQL
- Run the utils/install.pl in the Memcached_functions_mysql source directory, which is a Perl script that functions as above
Testing Memcache function
The following test script is excerpted from the Memcached_functions_mysql source directory and is interested to try
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:11211');
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 ' ) ;