内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

MySQL使用pt-archiver歸檔歷史數(shù)據(jù)

pt-archiver可以將表按照指定條件歸檔到歷史數(shù)據(jù)庫(kù)中,也支持文件導(dǎo)出,對(duì)于歸檔清理線上歷史數(shù)據(jù)非常方便。
如果要?dú)w檔表的數(shù)據(jù)到歷史數(shù)據(jù)庫(kù)的表中,需要預(yù)先在歷史數(shù)據(jù)庫(kù)中創(chuàng)建表結(jié)構(gòu)。

(1) 按照條件歸檔表中的歷史數(shù)據(jù)到歷史數(shù)據(jù)中,同時(shí)在本地生成歸檔文件

  1. # 在歷史數(shù)據(jù)庫(kù)(192.168.56.102)中創(chuàng)建歸檔表
  2. MySQL> CREATE TABLE `emp` (
  3.     -> `id` int(11) NOT NULL,
  4.     -> `name` varchar(15) DEFAULT NULL,
  5.     -> PRIMARY KEY (`id`)
  6.     -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  7. Query OK, 0 rows affected (0.60 sec)

  8. # 查看源表
  9. mysql> select * from emp;
  10. +--------+---------+
  11. | id | name |
  12. +--------+---------+
  13. | 10 | Neo |
  14. | 10036 | test |
  15. | 10037 | test |
  16. | 10038 | test |
  17. | 10039 | test |
  18. | 10040 | MySQL01 |
  19. | 10041 | MySQL01 |
  20. | 10042 | MySQL01 |
  21. | 100100 | test |
  22. | 100101 | test |
  23. | 100103 | test |
  24. | 100104 | test |
  25. | 100105 | test |
  26. | 100106 | test |
  27. | 100107 | test |
  28. | 100108 | test |
  29. +--------+---------+

  30. # 歸檔id小于200000的數(shù)據(jù)到歷史庫(kù)和本地文件
  31. # pt-archiver --source h=192.168.56.101,P=3307,u=neo,p=neo,D=sale,t=emp --dest h=192.168.56.102,P=3306,u=sale,p=sale,D=test,t=emp --where "id<=200000" --charset=utf8 --limit 1000 --commit-each --file '/opt/%Y-%m-%d-%D.%t'

  32. # 查看源表
  33. mysql> select * from emp where id < 200000;
  34. Empty set (0.05 sec)

  35. # 查看歷史表
  36. mysql> select * from emp limit 2;
  37. +--------+------+
  38. | id | name |
  39. +--------+------+
  40. | 100100 | test |
  41. | 100101 | test |
  42. +--------+------+
  43. 2 rows in set (0.00 sec)

  44. # 查看本地歸檔文件(相當(dāng)于select ... into導(dǎo)出)
  45. # cat /opt/2018-03-19-sale.emp
  46. 10    Neo
  47. 10036    test
  48. 10037    test
  49. 10038    test
  50. 10039    test
  51. 10040    MySQL01
  52. 10041    MySQL01
  53. 10042    MySQL01

(2) 清理過期歷史數(shù)據(jù)

  1. # pt-archiver --source h=192.168.56.101,P=3306,u=neo,p=neo,D=test,t=item_order --where "order_date < '2018-03-01'" --charset=utf8 --purge --limit 1000 --commit-each

  2. # 查看清理后的表中數(shù)據(jù)
  3. mysql> select * from item_order where order_date < '2018-03-01';
  4. Empty set (0.00 sec)


本文標(biāo)題:MySQL使用pt-archiver歸檔歷史數(shù)據(jù)
網(wǎng)頁(yè)鏈接:http://www.rwnh.cn/article22/pgccjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì)公司微信公眾號(hào)、移動(dòng)網(wǎng)站建設(shè)、軟件開發(fā)Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化
清远市| 无极县| 江孜县| 池州市| 宿松县| 瑞丽市| 武山县| 井冈山市| 蕲春县| 连云港市| 册亨县| 景泰县| 崇义县| 侯马市| 鄂温| 昭苏县| 保亭| 金塔县| 扬州市| 东乌| 阳朔县| 凤阳县| 德化县| 永德县| 昌邑市| 闻喜县| 合川市| 江西省| 东乌珠穆沁旗| 永修县| 石阡县| 西华县| 麻江县| 长汀县| 芦溪县| 家居| 屏东县| 涞水县| 陵水| 景德镇市| 巴林右旗|