MySQL to Redis
来源:互联网 发布:淘宝七天下架什么意思 编辑:程序博客网 时间:2024/05/16 18:45
简介
使用mysql2redis可以非常便捷的将mysql中的数据导出到redis中去, 通常是需要一个select语句即可实现。
软件安装
// 安装apr + apr-util$ wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.1.tar.gz$ tar zxvf apr-1.5.1.tar.gz$ ./configure --prefix=/usr/local/apr$ make$ make install$ wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.4.tar.gz$ cd apr-util-1.5.4$ ./configure --with-apr=/usr/local/apr$ make$ make install// 安装hiredis, redis的C语言client$ git clone https://github.com/redis/hiredis$ cd hiredis$ make$ make install$ git clone https://github.com/dawnbreaks/mysql2redis.git$ cd mysql2redis$ make$ cp lib_mysqludf_redis_v2.so /usr/lib64/mysql/plugin/
注册mysql2redis UDF
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";
如果出现以下异常信息,则关闭SELINUX
ERROR 1126 (HY000): Can't open shared library 'lib_mysqludf_redis_v2.so' (errno: 2 libhiredis.so.0.12: failed to map segment from shared object: Permission denied)关闭selinux
// 临时关闭
$ setenforce 0//永久关闭
cat /etc/selinux/config
SELINUX=disabled
测试
// mysql// 设置redis服务器地址mysql> select redis_servers_set_v2("127.0.0.1",6379);mysql> select * from user_info;+----+------------+------+-------------------+---------+| id | NAME | age | email | addr |+----+------------+------+-------------------+---------+| 1 | Troy Zhang | 30 | java-koma@163.com | ChengDu |+----+------------+------+-------------------+---------+// 将user_info表的数据更新到redis中mysql> select redis_command_v2("hmset", concat("user_info:", id), 'name', name, 'age', age, 'email', email, 'addr', addr) from user_info;// redis127.0.0.1:6379> keys *1) "user_info:1"127.0.0.1:6379> hgetall user_info:11) "name"2) "Troy Zhang"3) "age"4) "\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"5) "email"6) "java-koma@163.com"7) "addr"8) "ChengDu"
0 0
- MySQL to Redis
- Python Redis [How to] : Cache Python MySQL Result using Redis
- redis+mysql
- mysql redis
- redis+mysql
- 杂乱手札 - LINUX, Apache, Mysql, PHP, HTML-JS-CSS, Redis 2014 to 2016
- Redis与Mysql结合
- redis mysql Memcached
- Redis 与Mysql通信
- Mysql与Redis
- Redis mysql应用
- Redis mysql应用
- Redis, Memcache, Mysql区别
- Redis mysql应用
- Redis 2 Mysql
- mysql redis 同步
- Redis, Memcache, Mysql区别
- Redis和MySQL方案
- java编程题:将某个时间以固定格式转化成字符串
- Spark(一): 基本架构及原理
- FFTW中文说明
- HTTP基础认证Basic Authentication
- 斐波那契数列的几种解法
- MySQL to Redis
- Linux内核网络ip_mkroute_input
- 关于关键词提取,摘要提取的,及文本相似总结
- UIImageView上添加Button不能响应点击事件
- 在shell中把ls的输出存进一个数组变量中
- 合并两个排序列表
- 给Nginx配置一个自签名的SSL证书 【转】
- java自定义注解
- 使用pip安装软件时报pip is configured with locations that require TLS/SSL, however the ssl modul错误