mysql6手冊上有講 14.4.3.7. Using the MySQL memcached UDFs The memcached MySQL User Defined Functions (UDFs) enable you to set and retrieve objects from within MySQL 5.0 or greater. To install the MySQL memcached UDFs, download the UDF package from http://tangent.org/586/Memcached_Functions_for_MySQL.html. You will need to unpack the package and run configure to configure the build process. When running configure, use the --with-mysql option and specify the location of the mysql_config command. Note that you must be running : shell> tar zxf memcached_functions_mysql-0.5.tar.gz shell> cd memcached_functions_mysql-0.5 shell> ./configure --with-mysql-config=/usr/local/mysql/bin/mysql_configNow build and install the functions: shell> make shell> make install You may want to copy the MySQL memcached UDFs into your MySQL plugins directory: shell> cp /usr/local/lib/libmemcached_functions_mysql* /usr/local/mysql/lib/mysql/plugins/ Once installed, you must initialize the function within MySQL using CREATE and specifying the return value and library. For example, to add the memc_get() function: mysql> CREATE FUNCTION memc_get RETURNS STRING SONAME "libmemcached_functions_mysql.so"; You must repeat this process for each function that you want to provide access to within MySQL. Once you have created the association, the information will be retained, even over restarts of the MySQL server. You can simplify the process by using the SQL script provided in the memcached UDFs package: shell> mysql <sql/install_functions.sql Alternatively, if you have Perl installed, then you can use the supplied Perl script, which will check for the existence of each function and create the function/library association if it has not already been defined: shell> utils/install.pl --silent The --silent option installs everything automatically. Without this option, the script will ask whether you want to install each of the available functions. The interface remains consistent with the other APIs and interfaces. To set up a list of servers, use the memc_servers_set() function, which accepts a single string containing and comma-separated list of servers: mysql> SELECT memc_servers_set('192.168.0.1:11211,192.168.0.2:11211'); Note 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. To set a value, use memc_set: mysql> SELECT memc_set('myid', 'myvalue'); To retrieve a stored value: mysql> SELECT memc_get('myid');
14.4.3.7. Using the MySQL memcached UDFs
The memcached MySQL User Defined Functions (UDFs) enable you to set and retrieve objects from within MySQL 5.0 or greater. To install the MySQL memcached UDFs, download the UDF package from http://tangent.org/586/Memcached_Functions_for_MySQL.html. You will need to unpack the package and run configure to configure the build process. When running configure, use the --with-mysql option and specify the location of the mysql_config command. Note that you must be running : shell> tar zxf memcached_functions_mysql-0.5.tar.gz
shell> cd memcached_functions_mysql-0.5
shell> ./configure --with-mysql-config=/usr/local/mysql/bin/mysql_configNow build and install the functions: shell> make
shell> make install
You may want to copy the MySQL memcached UDFs into your MySQL plugins directory: shell> cp /usr/local/lib/libmemcached_functions_mysql* /usr/local/mysql/lib/mysql/plugins/
Once installed, you must initialize the function within MySQL using CREATE and specifying the return value and library. For example, to add the memc_get() function: mysql> CREATE FUNCTION memc_get RETURNS STRING SONAME "libmemcached_functions_mysql.so";
You must repeat this process for each function that you want to provide access to within MySQL. Once you have created the association, the information will be retained, even over restarts of the MySQL server. You can simplify the process by using the SQL script provided in the memcached UDFs package: shell> mysql <sql/install_functions.sql
Alternatively, if you have Perl installed, then you can use the supplied Perl script, which will check for the existence of each function and create the function/library association if it has not already been defined: shell> utils/install.pl --silent
The --silent option installs everything automatically. Without this option, the script will ask whether you want to install each of the available functions. The interface remains consistent with the other APIs and interfaces. To set up a list of servers, use the memc_servers_set() function, which accepts a single string containing and comma-separated list of servers: mysql> SELECT memc_servers_set('192.168.0.1:11211,192.168.0.2:11211');
Note
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. To set a value, use memc_set: mysql> SELECT memc_set('myid', 'myvalue');
To retrieve a stored value: mysql> SELECT memc_get('myid');