Mysqltools -- gently delete part of the data in large tables of MySQL

Easy feather fxst 2021-01-24 15:42:35
mysqltools gently delete data large


1. A reproduction of the scene

Bless The Child At work in the afternoon

Operation and maintenance : are you there ? Just now the tools came out and there was a batch of Mysql The table does not conform to the new specification , You look at the !

I : well , let me have a look .

inner OS: What the hell? ? I can't do a good job with the code ?

After a while of investigation , Basically, it's all parts Mysql Table has no primary key , It's very simple , Add a data id Just a matter of !

What the hell? , How does this watch twenty million Data. , I don't think there should be so much data in my mind , Code review , Sure enough, it's a pot of ancestral heritage , This deletion logic doesn't work at all .

The problem is coming. , 20 million Mysql surface , With the current performance of online machines , I'm worried that I'll hang up as soon as I operate .

Next is the world of search engines , Searching ...

Why , This MysqlTools What is it ? It's an operation and maintenance tool , But it seems that batch deletion of historical data is also very useful .

2. Tool is introduced

MysqlTools-Python It's a monitoring acquisition 、 Backup 、 On-Site Inspection 、 Log analysis 、 Automated troubleshooting Kit .

Tool list
Tool name Functional specifications
mtls-monitor Monitor item collection
mtls-backup Automated database backup
mtls-delete-rows partial ( moderate ) Delete rows from large tables
mtls-file-truncate partial ( moderate ) Truncated physical file
mtls-big-files Find out the large file name in the given directory
mtls-http tcp(http) Port connectivity test
mtls-log Slow query log slice
mtls-perf-bench Database running tool ( In development )
mtls-kill-all-connections Kill all client connections
mtls-sql-distribution Statistics slow query file in SQL Type and hotspot table
mtls-file-stat Statistics of the latest update time of the table
mtls-expired-tables Find a table that hasn't been used for a long time

3.Linux Environmental installation steps

3.1 Environment depends on

MySqlTools-Python Tool support Python-3.x All versions under , Directly through pip install .

3.2 Python install

stay Linux In the system , System native Python The environment is basically 2.x edition , Need to be reinstalled Python 3 Environmental Science .

Be careful : Do not delete the system's own without special reasons Python 2 Environmental Science , Avoid relying on Python 2 There's something wrong with our tools .

Python Download address of each version https://www.python.org/ftp/py...

  1. Download installation package

    wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
  2. Unzip the installation package to the current directory

    tar -xvf Python-3.9.1.tgz
  3. Installation dependency

    Depending on the number of packages installed directly affects Python Functions supported by the interpreter , The following dependency packages can basically cover the function support .

    yum -y install gcc gcc-c++ libffi libyaml-devel libffi-devel zlib zlib-devel openssl shadow-utils net-tools openssl-devel libyaml sqlite-devel libxml2 libxslt-devel libxml2-devel wget vim mysql-devel
    Be careful : If it's due to environmental problems mysql-devel Installation error , No installation .
  4. newly build Python 3 Catalog

    mkdir /data/python3.9
  5. Enter the unzip installation package directory

    cd Python-3.9.1
  6. Appoint Python 3 The installation directory

    ./configure --prefix=/data/python3.9
  7. Compile Android Python 3

    make && make install
  8. add to Python 3 The chain of soft

    ln -s /data/python3.9/bin/python3.9 /usr/bin/python3
  9. add to pip3 The chain of soft

    ln -s /data/python3.9/bin/pip3 /usr/bin/pip3
3.3 MysqlTools-Python install

Installation command :

pip3 install mysqltools-python

verification (mtlsmonitor see MySQL Execute after startup Select Statement quantity ):

/data/python3.9/bin/mtls-monitor --host=127.0.0.1 --port=3306 --user=monitor --password=yiyufxst ComSelect

Normal return :

248433539

Possible misstatements :

Traceback (most recent call last):
File "/data/python3.9/bin/mtls-monitor", line 4, in <module>
from mtls import base,statu,variable,mgr,replication,binlog,innodb_statu
File "/data/python3.9/lib/python3.9/site-packages/mtls/base.py", line 11, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'

install mysql-connector that will do

pip3 install mysql-connector

4. Tool use

Delete big table data
  1. Large amount of data , hypothesis test For large tables that need to be deleted , Delete data as id < 19685538 The data of , The amount of data is 221 All around .

    mysql> select count(*) from test where id < 19685538;
    +----------+
    | count(*) |
    +----------+
    | 2209566 |
    +----------+
    1 row in set (1.33 sec)
  2. Delete statement executed

    cat /tmp/delete-test.sql
    delete from tempdb.test where id < 19685538;
  3. adopt mlts-delete-rows Complete batch operations

    mtlsdeleterows --host=127.0.0.1 --port=3306 --user=root --password=yiyufxst --rows=1000 --sql-file=/tmp/dlt.sql exec
    2021-01-21 20:43:35,413 INFO 1000 row(s) affected by delete from tempdb.test where id < 19685538 limit 1000;
    2021-01-21 20:43:36,422 INFO 1000 row(s) affected by delete from tempdb.test where id < 19685538 limit 1000;
    2021-01-21 20:43:37,430 INFO 1000 row(s) affected by delete from tempdb.test where id < 19685538 limit 1000;
    ...
    2021-01-21 20:51:53,561 INFO 1000 row(s) affected by delete from tempdb.test where id < 19685538 limit 1000;
    2021-01-21 20:51:54,569 INFO 1000 row(s) affected by delete from tempdb.test where id < 19685538 limit 1000;
    2021-01-21 20:51:55,576 INFO 566 row(s) affected by delete from tempdb.test where id < 19685538 limit 1000;
    2021-01-21 20:51:56,578 INFO compelete

thank

Special thanks MysqlTools-Python The author of Jiang lexing bosses , Because the test environment is often filled with miscellaneous things , There are many problems in the actual installation process , Search for me with no solution , With the big guy's wechat , Ask a lot Python The basic problem of installation , Thank you for your explanation , At last it worked .

Reference link

Python 3 install :https://www.sqlpy.com/blogs/c...

mysqltools-python:https://github.com/Neeky/mysq...

版权声明
本文为[Easy feather fxst]所创,转载请带上原文链接,感谢
https://javamana.com/2021/01/20210124154207271u.html

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云