一:mysql:数据库的表结构;
CREATE TABLE `lg_chineseaddress` (
`address_id` varchar(20) NOT NULL,
`address_name` varchar(200) NOT NULL COMMENT '地址',
`address_type` varchar(10) DEFAULT NULL COMMENT '地址类型:1,省市自治区 2,市,3区县,4,乡镇街道 5,,村居委会',
PRIMARY KEY (`address_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
二:创建sql文件,sql语句是将数据转为redis可接收的语句
SELECT CONCAT(
"*8\r\n",
'$',LENGTH(redis_cmd),'\r\n',redis_cmd,'\r\n',
'$',LENGTH(redis_key),'\r\n',redis_key,'\r\n',
'$',LENGTH(hkey1),'\r\n',hkey1,'\r\n','$',LENGTH(hval1),'\r\n',hval1,'\r\n',
'$',LENGTH(hkey2),'\r\n',hkey2,'\r\n','$',LENGTH(hval2),'\r\n',hval2,'\r\n',
'$',LENGTH(hkey3),'\r\n',hkey3,'\r\n','$',LENGTH(hval3),'\r\n',hval3,'\r'
)FROM(
SELECT 'HMSET' AS redis_cmd,
concat_ws(':','lg_chineseaddress', address_id) AS redis_key,
'address_id' AS hkey1, address_id AS hval1,
'address_name' AS hkey2, address_name AS hval2,
'address_type' AS hkey3, address_type AS hval3
From lg_chineseaddress
)AS t
三:在安装有mysql数据库的Linux输入命令:
mysql -u用户名 -p密码 -h 127.0.0.1 数据库名 --skip-column-names --raw < 存放刚刚创建的sql文件的地址| /usr/local/redis/bin/redis-cli -p 6379 --pipe
例:
mysql -uroot -p123123-h 127.0.0.1 test --skip-column-names --raw < /myredis/chineseaddress.sql | /usr/local/redis/bin/redis-cli -p 6379 --pipe