1,保證linux上安裝了mysql資料庫,然後根據建表語句先建議表,並初始化好資料
2,然後將order.sql放到redis的安裝目錄下(與redis-server啟動檔案同目錄),在--raw不用進去redis,但是在jedis目錄下
mysql -uroot -proot1234 test --default-character-set=utf8 --skip-column-names --raw < order.sql | ./redis-cli -h 192.168.99.101 -p 6379 -a 123456 --pipe
注意 : test是庫名
詳細步驟如下: 主要是用到管道的resp協議
第1步:在mysql中建立表和匯入資料.
create table `order` (
`orderid` varchar(40) collate utf8_bin default null,
`ordertime` varchar(60) collate utf8_bin default null,
`ordermoney` varchar(40) collate utf8_bin default null,
`orderstatus` varchar(40) collate utf8_bin default null,
`version` varchar(40) collate utf8_bin default null
) engine=innodb default charset=utf8 collate=utf8_bin
insert into `order` values('123456781','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456782','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456783','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456784','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456786','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456785','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456787','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456788','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456789','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456719','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456729','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456739','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456749','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456759','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456769','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456779','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456799','2019-01-01 14:04:05',24,0,0);
insert into `order` values('123456789','2019-01-01 14:04:05',24,0,0);
第2步:把sql語句封裝成redis認識的命令並儲存成sql檔案。並上傳到redis目錄 下。
select concat(
'*10\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\n',
'$', length(hkey4),'\r\n',hkey4,'\r\n',
'$', length(hval4),'\r\n',hval4,'\r'
)from (
select
'hset' as redis_cmd,
concat('order:info:',orderid) as redis_key,
'ordertime' as hkey1, ordertime as hval1,
'ordermoney' as hkey2, ordermoney as hval2,
'orderstatus' as hkey3, orderstatus as hval3,
'version' as hkey4, `version` as hval4
from `order`
) as t
解釋:
'*10\r\n', 表示全部有10組資料
$10 表示這字段有多少長度
第3步:不用進去redis,但是在jedis目錄下
mysql -uroot -proot1234 test --default-character-set=utf8 --skip-column-names --raw < order.sql | ./redis-cli -h 192.168.99.101 -p 6379 -a 123456 --pipe
結果如下:
禁用防火牆
[root@rhel7 ~]# systemctl stop firewalld.service
[root@rhel7 ~]# systemctl disable firewalld.service
[root@rhel7 ~]# systemctl status firewalld.service
JAVA使用pipeline批量寫Redis資料
最近遇到乙個需求,需要把資料庫中的手機號批量寫入到資料庫,使用了很多的方法都效能不佳或者出現連線池斷開的問題,最後在網上找到了這個方法 public static void main string args throws exception long end system.currenttimemi...
mysql 批量更新 MySQL批量更新
我有2個表 mysql data details accounts invoices 理想情況下,每個data details都應具有accounts invoices id.data details有乙個帶有accounts invoices主鍵的外來鍵 由於某種原因,有data details記...
mysql批量修復 mysql 批量修復
bin bash host name 127.0.0.1 user name user pwd database need optmize table false tables usr local webserver mysql bin mysql h host name u user name p...