https://github.com/dawnbreaks/mysql2redis
yum -y install autoconf libtool
yum -y install expat-devel
yum -y install mysql-devel
yum -y install expat
yum -y install libxml2-devel libxml2
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz
tar zxvf apr-1.7.0.tar.gz
rm -f apr-1.7.0.tar.gz
cd apr-1.7.0
./buildconf
./configure
make
make install
cd ..
rm -rf apr-1.7.0
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
tar zxvf apr-util-1.6.1.tar.gz
rm -f apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
vi configure.in
去掉 APU_FIND_EXPAT
./configure --with-apr=/usr/local/apr
make
make install
cd ..
rm -rf apr-util-1.6.1
echo "/usr/local/apr/lib/" >> /etc/ld.so.conf
/sbin/ldconfig
git clone https://github.com/redis/hiredis.git
cd hiredis
make
make install
cd ..
rm -rf hiredis
echo "/usr/local/lib" >> /etc/ld.so.conf
/sbin/ldconfig
git clone https://github.com/dawnbreaks/mysql2redis.git
cd mysql2redis
vi lib_mysqludf_redis.h
在 #include <mysql/plugin.h> 前增加下列行:
#define MYSQL_ABI_CHECK
vi lib_mysqludf_redis.c
static struct config cfg = {
.tcp = {
.host = "IP地址",
.port = 6379
},
.unix_sock = {
.path = "/tmp/redis.sock"
},
.password = "密码",
.auth = 1,
.log_file = "/tmp/redis_udf.log",
.debug = 0,
.type = CONN_TCP
};
make
找到插件目录:SHOW VARIABLES LIKE 'plugin_dir%' 将 lib_mysqludf_redis_v2.so 文件拷贝过去
cp lib_mysqludf_redis_v2.so /usr/lib64/mysql/plugin/
执行下列 SQL:
DROP FUNCTION IF EXISTS redis_servers_set_v2;
DROP FUNCTION IF EXISTS redis_command_v2;
DROP FUNCTION IF EXISTS free_resources;
CREATE FUNCTION redis_servers_set_v2 RETURNS int SONAME "lib_mysqludf_redis_v2.so";
CREATE FUNCTION redis_command_v2 RETURNS int SONAME "lib_mysqludf_redis_v2.so";
CREATE FUNCTION free_resources RETURNS int SONAME "lib_mysqludf_redis_v2.so";
cd ..
rm -rf mysql2redis